SimpleWindow
载入中...
搜索中...
未找到
Font.h
1#pragma once
2
3#include <Windows.h>
4#include <cstdint>
5#include <string>
6
7namespace sw
8{
12 enum class FontWeight : int {
13 DontCare = 0,
14 Thin = 100,
15 ExtraLight = 200,
16 UltraLight = 200,
17 Light = 300,
18 Normal = 400,
19 Regular = 400,
20 Medium = 500,
21 SemiBold = 600,
22 DemiBold = 600,
23 Bold = 700,
24 ExtraBold = 800,
25 UltraBold = 800,
26 Heavy = 900,
27 Black = 900,
28 };
29
33 enum class FontCharSet : uint8_t {
34 ANSI = ANSI_CHARSET,
35 Baltic = BALTIC_CHARSET,
36 CheneseBig5 = CHINESEBIG5_CHARSET,
37 Default = DEFAULT_CHARSET,
38 EastEurope = EASTEUROPE_CHARSET,
39 GB2312 = GB2312_CHARSET,
40 Greek = GREEK_CHARSET,
41 Hangul = HANGUL_CHARSET,
42 Mac = MAC_CHARSET,
43 Oem = OEM_CHARSET,
44 Russian = RUSSIAN_CHARSET,
45 ShiftJIS = SHIFTJIS_CHARSET,
46 Symbol = SYMBOL_CHARSET,
47 Turkish = TURKISH_CHARSET,
48 Vietnamese = VIETNAMESE_CHARSET,
49
50 // Windows 的朝鲜语版本:
51 Johab = JOHAB_CHARSET,
52
53 // Windows 中东语言版本:
54 Arabic = ARABIC_CHARSET,
55 Hebrew = HEBREW_CHARSET,
56
57 // Windows 的泰语版本:
58 Thai = THAI_CHARSET,
59 };
60
64 enum class FontOutPrecision : uint8_t {
65 Character = OUT_CHARACTER_PRECIS, // 未使用。
66 Default = OUT_DEFAULT_PRECIS, // 指定默认字体映射器行为。
67 Device = OUT_DEVICE_PRECIS, // 当系统包含多个同名字体时,指示字体映射器选择设备字体。
68 Outline = OUT_OUTLINE_PRECIS, // 此值指示字体映射器从 TrueType 和其他基于大纲的字体中进行选择。
69 PostScriptOnly = OUT_PS_ONLY_PRECIS, // 指示字体映射器仅从 PostScript 字体中进行选择。 如果系统中没有安装 PostScript 字体,字体映射器将返回到默认行为。
70 Raster = OUT_RASTER_PRECIS, // 当系统包含多个同名字体时,指示字体映射器选择光栅字体。
71 String = OUT_STRING_PRECIS, // 字体映射器不使用此值,但在枚举光栅字体时会返回此值。
72 Stroke = OUT_STROKE_PRECIS, // 字体映射器不使用此值,但在枚举 TrueType、其他基于轮廓的字体和矢量字体时返回此值。
73 TrueTypeOnly = OUT_TT_ONLY_PRECIS, // 指示字体映射器仅从 TrueType 字体中进行选择。 如果系统中没有安装 TrueType 字体,字体映射器将返回到默认行为。
74 TrueType = OUT_TT_PRECIS, // 当系统包含多个同名字体时,指示字体映射器选择 TrueType 字体。
75 };
76
80 enum class FontClipPrecision : uint8_t {
81 CharacterPrecis = CLIP_CHARACTER_PRECIS, // 未使用。
82 DefaultPrecis = CLIP_DEFAULT_PRECIS, // 指定默认剪辑行为。
83
84#if defined(CLIP_DFA_DISABLE)
85 DFA_Disable = CLIP_DFA_DISABLE, // Windows XP SP1: 关闭字体的字体关联。 请注意,此标志不保证在 Windows Server 2003 之后对任何平台产生任何影响。
86#endif
87
88 Embedded = CLIP_EMBEDDED, // 必须指定此标志才能使用嵌入的只读字体。
89 LH_Angles = CLIP_LH_ANGLES, // 使用此值时,所有字体的旋转取决于坐标系的方向是左手还是右手。如果未使用,设备字体始终逆时针旋转,但其他字体的旋转取决于坐标系的方向。
90 Mask = CLIP_MASK, // 未使用。
91
92#if defined(CLIP_DFA_OVERRIDE)
93 DFA_Override = CLIP_DFA_OVERRIDE, // 关闭字体的字体关联。 这与CLIP_DFA_DISABLE相同,但在某些情况下可能会有问题:建议使用的标志是CLIP_DFA_DISABLE。
94#endif
95
96 StrokePrecis = CLIP_STROKE_PRECIS, // 字体映射器不使用,但在枚举光栅、矢量或 TrueType 字体时返回。 为了兼容,枚举字体时始终返回此值。
97 TT_Always = CLIP_TT_ALWAYS, // 未使用。
98 };
99
103 enum class FontQuality : uint8_t {
104 AntiAliased = ANTIALIASED_QUALITY, // 如果字体支持该字体,并且字体大小不是太小或太大,则字体始终为抗锯齿。
105 ClearType = CLEARTYPE_QUALITY, // 如果设置,则尽可能使用 ClearType 抗锯齿方法呈现文本。
106 Default = DEFAULT_QUALITY, // 字体的外观并不重要。
107 Draft = DRAFT_QUALITY, // 字体的外观不如使用PROOF_QUALITY时重要。 对于 GDI 光栅字体,会启用缩放,这意味着可以使用更多字号,但质量可能较低。 如有必要,将合成粗体、斜体、下划线和删除线字体。
108 NoAntiAliased = NONANTIALIASED_QUALITY, // 字体永远不会抗锯齿。
109 Proof = PROOF_QUALITY, // 字体的字符质量比逻辑字体属性的精确匹配更重要。 对于 GDI 光栅字体,将禁用缩放,并选择大小最接近的字体。 虽然在使用PROOF_QUALITY时可能无法精确映射所选字号,但字体质量较高,外观不会失真。 如有必要,将合成粗体、斜体、下划线和删除线字体。
110 };
111
115 enum class FontPitch : uint8_t {
116 Default = DEFAULT_PITCH,
117 Fixed = FIXED_PITCH,
118 Variable = VARIABLE_PITCH,
119 };
120
124 enum class FontFamily : uint8_t {
125 Decorative = FF_DECORATIVE, // 新奇字体。 例如 Old English。
126 DontCare = FF_DONTCARE, // 使用默认字体。
127 Modern = FF_MODERN, // 具有固定笔划宽度的字体 (带衬线或无衬线) 的空白字体。 Monospace 字体通常是新式字体。 例如,Pica、Elite 和 CourierNew。
128 Roman = FF_ROMAN, // 笔划宽度可变的字体 (比例) 和衬线。 例如 MS Serif。
129 Script = FF_SCRIPT, // 设计为类似于手写的字体。 例如 Script 和 Cursive。
130 Swiss = FF_SWISS, // 笔划宽度可变的字体 (成比例) 且不带衬线。 例如 MS Sans Serif。
131 };
132
136 class Font
137 {
138 public:
142 std::wstring name = L"";
143
147 double size = 12;
148
152 int escapement = 0;
153
157 int orientation = 0;
158
162 FontWeight weight = FontWeight::DontCare;
163
167 bool italic = false;
168
172 bool underline = false;
173
177 bool strikeOut = false;
178
182 FontCharSet charSet = FontCharSet::Default;
183
187 FontOutPrecision outPrecision = FontOutPrecision::Default;
188
192 FontClipPrecision clipPrecision = FontClipPrecision::DefaultPrecis;
193
197 FontQuality quality = FontQuality::Default;
198
202 /*uint8_t pitchAndFamily;*/
203
207 FontPitch pitch = FontPitch::Default;
208
212 FontFamily family = FontFamily::DontCare;
213
214 public:
219
223 Font(const std::wstring &name, FontCharSet charSet);
224
228 Font(const std::wstring &name, double size = 12, FontWeight weight = FontWeight::DontCare);
229
233 Font(const LOGFONTW &logFont);
234
238 operator LOGFONTW() const;
239
243 HFONT CreateHandle() const;
244
248 static Font GetFont(HFONT hFont);
249
256 static Font &GetDefaultFont(bool update = false);
257 };
258}
字体类
Definition Font.h:137
FontFamily family
字体系列
Definition Font.h:212
HFONT CreateHandle() const
创建HFONT句柄
bool strikeOut
是否有删除线
Definition Font.h:177
std::wstring name
字体的字体名称,此字符串的长度不能超过 32
Definition Font.h:142
FontClipPrecision clipPrecision
裁剪精度
Definition Font.h:192
static Font GetFont(HFONT hFont)
通过HFONT获取字体信息
Font()
构造字体对象
bool underline
是否有下划线
Definition Font.h:172
int escapement
转义向量与设备的 x 轴之间的角度(以十分之一度为单位)
Definition Font.h:152
FontQuality quality
输出质量
Definition Font.h:197
Font(const LOGFONTW &logFont)
从LOGFONTW构造字体对象
Font(const std::wstring &name, double size=12, FontWeight weight=FontWeight::DontCare)
构造指定字体名称、大小与粗细的字体对象
FontOutPrecision outPrecision
输出精度
Definition Font.h:187
FontWeight weight
字体的粗细,范围为 0 到 1000
Definition Font.h:162
bool italic
是否为斜体
Definition Font.h:167
double size
字体大小,以dip为单位
Definition Font.h:147
FontCharSet charSet
字符集
Definition Font.h:182
static Font & GetDefaultFont(bool update=false)
获取默认字体,线程中首次调用或参数update为true时会获取系统默认字体
Font(const std::wstring &name, FontCharSet charSet)
构造指定字体名称和字符集的字体对象
FontPitch pitch
字体的间距和系列
Definition Font.h:207
int orientation
每个字符的基线和设备 x 轴之间的角度(以十分之一度为单位)
Definition Font.h:157