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
use {Number, Offset};
#[derive(Clone, Debug)]
pub struct Glyph {
pub bounding_box: (Number, Number, Number, Number),
pub side_bearings: (Number, Number),
pub contours: Vec<Contour>,
}
#[derive(Clone, Debug, Default)]
pub struct Contour {
pub offset: Offset,
pub segments: Vec<Segment>,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Segment {
Linear(Offset),
Quadratic(Offset, Offset),
Cubic(Offset, Offset, Offset),
}
impl Glyph {
#[inline]
pub fn advance_width(&self) -> Number {
self.side_bearings.0 + self.width() + self.side_bearings.1
}
#[inline]
pub fn height(&self) -> Number {
self.bounding_box.3 - self.bounding_box.1
}
#[inline]
pub fn width(&self) -> Number {
self.bounding_box.2 - self.bounding_box.0
}
}
impl Default for Glyph {
#[inline]
fn default() -> Self {
use std::f32::NAN;
Glyph { bounding_box: (NAN, NAN, NAN, NAN), side_bearings: (NAN, NAN), contours: vec![] }
}
}
deref! { Glyph::contours => [Contour] }
deref! { Contour::segments => [Segment] }