/src/serenity/Userland/Libraries/LibGfx/Font/FontStyleMapping.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> |
3 | | * Copyright (c) 2021, the SerenityOS developers. |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <AK/StringView.h> |
11 | | |
12 | | namespace Gfx { |
13 | | |
14 | | struct FontStyleMapping { |
15 | | int style { 0 }; |
16 | | StringView name; |
17 | | }; |
18 | | |
19 | | static constexpr Array<FontStyleMapping, 10> font_weight_names = { { |
20 | | { 100, "Thin"sv }, |
21 | | { 200, "Extra Light"sv }, |
22 | | { 300, "Light"sv }, |
23 | | { 400, "Regular"sv }, |
24 | | { 500, "Medium"sv }, |
25 | | { 600, "Semi Bold"sv }, |
26 | | { 700, "Bold"sv }, |
27 | | { 800, "Extra Bold"sv }, |
28 | | { 900, "Black"sv }, |
29 | | { 950, "Extra Black"sv }, |
30 | | } }; |
31 | | |
32 | | static constexpr Array<FontStyleMapping, 4> font_slope_names = { { |
33 | | { 0, "Regular"sv }, |
34 | | { 1, "Italic"sv }, |
35 | | { 2, "Oblique"sv }, |
36 | | { 3, "Reclined"sv }, |
37 | | } }; |
38 | | |
39 | | static constexpr Array<FontStyleMapping, 9> font_width_names = { { |
40 | | { 1, "Ultra Condensed"sv }, |
41 | | { 2, "Extra Condensed"sv }, |
42 | | { 3, "Condensed"sv }, |
43 | | { 4, "Semi Condensed"sv }, |
44 | | { 5, "Normal"sv }, |
45 | | { 6, "Semi Expanded"sv }, |
46 | | { 7, "Expanded"sv }, |
47 | | { 8, "Extra Expanded"sv }, |
48 | | { 9, "Ultra Expanded"sv }, |
49 | | } }; |
50 | | |
51 | | static constexpr StringView weight_to_name(int weight) |
52 | 0 | { |
53 | 0 | for (auto& it : font_weight_names) { |
54 | 0 | if (it.style == weight) |
55 | 0 | return it.name; |
56 | 0 | } |
57 | 0 | return {}; |
58 | 0 | } Unexecuted instantiation: BitmapFont.cpp:Gfx::weight_to_name(int) Unexecuted instantiation: CSSStyleValue.cpp:Gfx::weight_to_name(int) Unexecuted instantiation: CSSFontFaceRule.cpp:Gfx::weight_to_name(int) Unexecuted instantiation: StyleComputer.cpp:Gfx::weight_to_name(int) |
59 | | |
60 | | static constexpr int name_to_weight(StringView name) |
61 | 0 | { |
62 | 0 | for (auto& it : font_weight_names) { |
63 | 0 | if (it.name == name) |
64 | 0 | return it.style; |
65 | 0 | } |
66 | 0 | return {}; |
67 | 0 | } Unexecuted instantiation: BitmapFont.cpp:Gfx::name_to_weight(AK::StringView) Unexecuted instantiation: CSSStyleValue.cpp:Gfx::name_to_weight(AK::StringView) Unexecuted instantiation: CSSFontFaceRule.cpp:Gfx::name_to_weight(AK::StringView) Unexecuted instantiation: StyleComputer.cpp:Gfx::name_to_weight(AK::StringView) |
68 | | |
69 | | static constexpr StringView slope_to_name(int slope) |
70 | 0 | { |
71 | 0 | for (auto& it : font_slope_names) { |
72 | 0 | if (it.style == slope) |
73 | 0 | return it.name; |
74 | 0 | } |
75 | 0 | return {}; |
76 | 0 | } Unexecuted instantiation: BitmapFont.cpp:Gfx::slope_to_name(int) Unexecuted instantiation: CSSStyleValue.cpp:Gfx::slope_to_name(int) Unexecuted instantiation: CSSFontFaceRule.cpp:Gfx::slope_to_name(int) Unexecuted instantiation: StyleComputer.cpp:Gfx::slope_to_name(int) |
77 | | |
78 | | static constexpr int name_to_slope(StringView name) |
79 | 0 | { |
80 | 0 | for (auto& it : font_slope_names) { |
81 | 0 | if (it.name == name) |
82 | 0 | return it.style; |
83 | 0 | } |
84 | 0 | return {}; |
85 | 0 | } Unexecuted instantiation: BitmapFont.cpp:Gfx::name_to_slope(AK::StringView) Unexecuted instantiation: CSSStyleValue.cpp:Gfx::name_to_slope(AK::StringView) Unexecuted instantiation: CSSFontFaceRule.cpp:Gfx::name_to_slope(AK::StringView) Unexecuted instantiation: StyleComputer.cpp:Gfx::name_to_slope(AK::StringView) |
86 | | |
87 | | static constexpr StringView width_to_name(int width) |
88 | 0 | { |
89 | 0 | for (auto& it : font_width_names) { |
90 | 0 | if (it.style == width) |
91 | 0 | return it.name; |
92 | 0 | } |
93 | 0 | return {}; |
94 | 0 | } Unexecuted instantiation: BitmapFont.cpp:Gfx::width_to_name(int) Unexecuted instantiation: CSSStyleValue.cpp:Gfx::width_to_name(int) Unexecuted instantiation: CSSFontFaceRule.cpp:Gfx::width_to_name(int) Unexecuted instantiation: StyleComputer.cpp:Gfx::width_to_name(int) |
95 | | |
96 | | static constexpr int name_to_width(StringView name) |
97 | 0 | { |
98 | 0 | for (auto& it : font_width_names) { |
99 | 0 | if (it.name == name) |
100 | 0 | return it.style; |
101 | 0 | } |
102 | 0 | return {}; |
103 | 0 | } Unexecuted instantiation: BitmapFont.cpp:Gfx::name_to_width(AK::StringView) Unexecuted instantiation: CSSStyleValue.cpp:Gfx::name_to_width(AK::StringView) Unexecuted instantiation: CSSFontFaceRule.cpp:Gfx::name_to_width(AK::StringView) Unexecuted instantiation: StyleComputer.cpp:Gfx::name_to_width(AK::StringView) |
104 | | |
105 | | } |