1 | // LAF OS Library |
2 | // Copyright (C) 2019 Igara Studio S.A. |
3 | // |
4 | // This file is released under the terms of the MIT license. |
5 | // Read LICENSE.txt for more information. |
6 | |
7 | #ifndef OS_FONT_STYLE_H_INCLUDED |
8 | #define OS_FONT_STYLE_H_INCLUDED |
9 | #pragma once |
10 | |
11 | #include "base/ints.h" |
12 | |
13 | namespace os { |
14 | |
15 | class FontStyle { |
16 | public: |
17 | enum class Weight { |
18 | Invisible = 0, |
19 | Thin = 100, |
20 | = 200, |
21 | Light = 300, |
22 | Normal = 400, |
23 | Medium = 500, |
24 | SemiBold = 600, |
25 | Bold = 700, |
26 | = 800, |
27 | Black = 900, |
28 | = 1000, |
29 | }; |
30 | |
31 | enum class Width { |
32 | UltraCondensed = 1, |
33 | = 2, |
34 | Condensed = 3, |
35 | SemiCondensed = 4, |
36 | Normal = 5, |
37 | SemiExpanded = 6, |
38 | Expanded = 7, |
39 | ExtraExpanded = 8, |
40 | UltraExpanded = 9, |
41 | }; |
42 | |
43 | enum class Slant { |
44 | Upright, |
45 | Italic, |
46 | Oblique, |
47 | }; |
48 | |
49 | constexpr FontStyle(const Weight weight, |
50 | const Width width, |
51 | const Slant slant) |
52 | : m_value(int(weight) | |
53 | (int(width) << 16) | |
54 | (int(slant) << 24)) { } |
55 | |
56 | constexpr FontStyle() : FontStyle(Weight::Normal, |
57 | Width::Normal, |
58 | Slant::Upright) { } |
59 | |
60 | bool operator==(const FontStyle& other) const { |
61 | return m_value == other.m_value; |
62 | } |
63 | |
64 | Weight weight() const { return Weight(m_value & 0xFFFF); } |
65 | Width width() const { return Width((m_value >> 16) & 0xFF); } |
66 | Slant slant() const { return Slant((m_value >> 24) & 0xFF); } |
67 | |
68 | static constexpr FontStyle Normal() { |
69 | return FontStyle(Weight::Normal, Width::Normal, Slant::Upright); |
70 | } |
71 | |
72 | static constexpr FontStyle Bold() { |
73 | return FontStyle(Weight::Bold, Width::Normal, Slant::Upright); |
74 | } |
75 | |
76 | static constexpr FontStyle Italic() { |
77 | return FontStyle(Weight::Normal, Width::Normal, Slant::Italic); |
78 | } |
79 | |
80 | static constexpr FontStyle BoldItalic() { |
81 | return FontStyle(Weight::Bold, Width::Normal, Slant::Italic); |
82 | } |
83 | |
84 | private: |
85 | uint32_t m_value; |
86 | }; |
87 | |
88 | } // namespace os |
89 | |
90 | #endif |
91 | |