1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
use helpers::InternalConstructor;
use winapi::um::dwrite::*;
/// Specifies the metrics that are applicable to all glyphs within the font face.
#[derive(Copy, Clone)]
pub struct FontMetrics {
metrics: DWRITE_FONT_METRICS,
}
impl InternalConstructor for FontMetrics {
type Arguments = DWRITE_FONT_METRICS;
#[inline]
fn build(args: DWRITE_FONT_METRICS) -> Self {
FontMetrics { metrics: args }
}
}
impl FontMetrics {
/// The number of font design units per em unit.
/// Font files use their own coordinate system of font design units.
/// A font design unit is the smallest measurable unit in the em square, an imaginary square that
/// is used to size and align glyphs. The concept of em square is used as a reference scale factor
/// when defining font size and device transformation semantics. The size of one em square is also
/// commonly used to compute the paragraph identation value.
#[inline]
pub fn design_units_per_em(&self) -> u16 {
self.metrics.designUnitsPerEm
}
/// The ascent value of the font face in font design units.
/// Ascent is the distance from the top of font character alignment box to the English baseline.
#[inline]
pub fn ascent(&self) -> u16 {
self.metrics.ascent
}
/// The descent value of the font face in font design units.
/// Descent is the distance from the bottom of font character alignment box to the English baseline.
#[inline]
pub fn descent(&self) -> u16 {
self.metrics.descent
}
/// The line gap in font design units. Recommended additional white space to add between lines to
/// improve legibility. The recommended line spacing (baseline-to-baseline distance) is the sum of ascent,
/// descent, and lineGap. The line gap is usually positive or zero but can be negative, in which case the
/// recommended line spacing is less than the height of the character alignment box.
#[inline]
pub fn line_gap(&self) -> i16 {
self.metrics.lineGap
}
/// The cap height value of the font face in font design units. Cap height is the distance from the English
/// baseline to the top of a typical English capital. Capital "H" is often used as a reference character for
/// the purpose of calculating the cap height value.
#[inline]
pub fn cap_height(&self) -> u16 {
self.metrics.capHeight
}
/// The x-height value of the font face in font design units. x-height is the distance from the English baseline
/// to the top of lowercase letter "x", or a similar lowercase character.
#[inline]
pub fn x_height(&self) -> u16 {
self.metrics.xHeight
}
/// The underline position value of the font face in font design units. Underline position is the position of
/// underline relative to the English baseline. The value is usually made negative in order to place the underline
/// below the baseline.
#[inline]
pub fn underline_position(&self) -> i16 {
self.metrics.underlinePosition
}
/// The suggested underline thickness value of the font face in font design units.
#[inline]
pub fn underline_thickness(&self) -> u16 {
self.metrics.underlineThickness
}
/// The strikethrough position value of the font face in font design units. Strikethrough position is the
/// position of strikethrough relative to the English baseline. The value is usually made positive in order
/// to place the strikethrough above the baseline.
#[inline]
pub fn strikethrough_position(&self) -> i16 {
self.metrics.strikethroughPosition
}
/// The suggested strikethrough thickness value of the font face in font design units.
#[inline]
pub fn strikethrough_thickness(&self) -> u16 {
self.metrics.strikethroughThickness
}
}
/// Specifies the metrics of an individual glyph. The units depend on how the metrics are obtained.
#[derive(Copy, Clone)]
pub struct GlyphMetrics {
metrics: DWRITE_GLYPH_METRICS,
}
impl InternalConstructor for GlyphMetrics {
type Arguments = DWRITE_GLYPH_METRICS;
#[inline]
fn build(args: DWRITE_GLYPH_METRICS) -> Self {
GlyphMetrics { metrics: args }
}
}
impl GlyphMetrics {
/// Specifies the X offset from the glyph origin to the left edge of the black box.
/// The glyph origin is the current horizontal writing position. A negative value means the black
/// box extends to the left of the origin (often true for lowercase italic 'f').
#[inline]
pub fn left_side_bearing(&self) -> i32 {
self.metrics.leftSideBearing
}
/// Specifies the X offset from the origin of the current glyph to the origin of the next glyph
/// when writing horizontally.
#[inline]
pub fn advance_width(&self) -> u32 {
self.metrics.advanceWidth
}
/// Specifies the X offset from the right edge of the black box to the origin of the next glyph
/// when writing horizontally. The value is negative when the right edge of the black box
/// overhangs the layout box.
#[inline]
pub fn right_side_bearing(&self) -> i32 {
self.metrics.rightSideBearing
}
/// Specifies the vertical offset from the vertical origin to the top of the black box.
/// Thus, a positive value adds whitespace whereas a negative value means the glyph overhangs
/// the top of the layout box.
#[inline]
pub fn top_side_bearing(&self) -> i32 {
self.metrics.topSideBearing
}
/// Specifies the Y offset from the vertical origin of the current glyph to the vertical origin
/// of the next glyph when writing vertically. Note that the term "origin" by itself denotes the horizontal origin.
/// The vertical origin is different. Its Y coordinate is specified by verticalOriginY value, and its X coordinate is
/// half the advanceWidth to the right of the horizontal origin.
#[inline]
pub fn advance_height(&self) -> u32 {
self.metrics.advanceHeight
}
/// Specifies the vertical distance from the bottom edge of the black box to the advance height.
/// This is positive when the bottom edge of the black box is within the layout box,
/// or negative when the bottom edge of black box overhangs the layout box.
#[inline]
pub fn bottom_side_bearing(&self) -> i32 {
self.metrics.bottomSideBearing
}
/// Specifies the Y coordinate of a glyph's vertical origin, in the font's design coordinate system.
/// The y coordinate of a glyph's vertical origin is the sum of the glyph's top side bearing and the
/// top (that is, yMax) of the glyph's bounding box.
#[inline]
pub fn vertical_origin_y(&self) -> i32 {
self.metrics.verticalOriginY
}
}