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
use core::ptr::null_mut;
use {ffi, Bitmap, FtResult, Glyph, GlyphMetrics, Outline, RenderMode, Vector};
#[derive(Copy, Clone)]
pub struct SubGlyphInfo {
pub index: i32,
pub flags: u32,
pub arg1: i32,
pub arg2: i32,
pub transform: ffi::FT_Matrix,
}
impl Default for SubGlyphInfo {
fn default() -> Self {
SubGlyphInfo {
index: 0,
flags: 0,
arg1: 0,
arg2: 0,
transform: ffi::FT_Matrix { xx: 0, xy: 0, yx: 0, yy: 0 }
}
}
}
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub struct GlyphSlot {
library_raw: ffi::FT_Library,
raw: ffi::FT_GlyphSlot
}
impl GlyphSlot {
pub unsafe fn from_raw(library_raw: ffi::FT_Library, raw: ffi::FT_GlyphSlot) -> Self {
GlyphSlot { library_raw, raw }
}
pub fn render_glyph(&self, render_mode: RenderMode) -> FtResult<()> {
::error::from_ftret(unsafe { ffi::FT_Render_Glyph(self.raw, render_mode as u32) })
}
pub fn get_subglyph_info(&self, sub_index: u32) -> FtResult<SubGlyphInfo> {
let mut info = SubGlyphInfo::default();
::error::from_ftret(unsafe {
ffi::FT_Get_SubGlyph_Info(self.raw, sub_index, &mut info.index, &mut info.flags,
&mut info.arg1, &mut info.arg2, &mut info.transform)
})?;
Ok(info)
}
pub fn get_glyph(&self) -> FtResult<Glyph> {
let mut aglyph = null_mut();
::error::from_ftret(unsafe { ffi::FT_Get_Glyph(self.raw, &mut aglyph) })?;
Ok(unsafe { Glyph::from_raw(self.library_raw, aglyph) })
}
pub fn outline(&self) -> Option<Outline> {
let outline = unsafe { &(*self.raw).outline };
let format = unsafe { (*self.raw).format };
if format == ffi::FT_GLYPH_FORMAT_OUTLINE {
let outline = unsafe { Outline::from_raw(outline) };
Some(outline)
} else {
None
}
}
#[inline(always)]
pub fn bitmap(&self) -> Bitmap {
unsafe { Bitmap::from_raw(&(*self.raw).bitmap) }
}
#[inline(always)]
pub fn bitmap_left(&self) -> i32 {
unsafe { (*self.raw).bitmap_left }
}
#[inline(always)]
pub fn bitmap_top(&self) -> i32 {
unsafe { (*self.raw).bitmap_top }
}
#[inline(always)]
pub fn advance(&self) -> Vector {
unsafe { (*self.raw).advance }
}
#[inline(always)]
pub fn linear_hori_advance(&self) -> ffi::FT_Fixed {
unsafe { (*self.raw).linearHoriAdvance }
}
#[inline(always)]
pub fn linear_vert_advance(&self) -> ffi::FT_Fixed {
unsafe { (*self.raw).linearVertAdvance }
}
#[inline(always)]
pub fn metrics(&self) -> GlyphMetrics {
unsafe { (*self.raw).metrics }
}
#[inline(always)]
pub fn raw(&self) -> &ffi::FT_GlyphSlotRec {
unsafe { &*self.raw }
}
}