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
use easy_cast::Cast;
#[inline]
pub fn to_u32(x: usize) -> u32 {
x.cast()
}
#[inline]
pub fn to_usize(x: u32) -> usize {
x.cast()
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct DPU(pub f32);
impl DPU {
#[cfg(all(not(feature = "harfbuzz_rs"), feature = "rustybuzz"))]
pub(crate) fn i32_to_px(self, x: i32) -> f32 {
x as f32 * self.0
}
pub(crate) fn i16_to_px(self, x: i16) -> f32 {
f32::from(x) * self.0
}
pub(crate) fn u16_to_px(self, x: u16) -> f32 {
f32::from(x) * self.0
}
pub(crate) fn to_line_metrics(self, metrics: ttf_parser::LineMetrics) -> LineMetrics {
LineMetrics {
position: self.i16_to_px(metrics.position),
thickness: self.i16_to_px(metrics.thickness),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct LineMetrics {
pub position: f32,
pub thickness: f32,
}