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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//! Compatibility layer for different font engines.
//!
//! CoreText is used on Mac OS.
//! FreeType is used on everything that's not Mac OS.
//! Eventually, ClearType support will be available for windows.
use fmt;
use ;
use ;
// // If target isn't macos or windows, reexport everything from ft.
// #[cfg(not(any(target_os = "macos", windows)))]
// pub mod ft;
// #[cfg(not(any(target_os = "macos", windows)))]
// pub use ft::FreeTypeFontMap as FontLoader;
//
// #[cfg(windows)]
// pub mod directwrite;
// #[cfg(windows)]
// pub use directwrite::DirectWriteLoader as FontLoader;
//
// // If target is macos, reexport everything from darwin.
// #[cfg(target_os = "macos")]
// mod darwin;
// #[cfg(target_os = "macos")]
// pub use darwin::*;
//
// #[derive(Debug, Clone, PartialEq, Eq, Hash)]
// pub struct FontDesc {
// name: String,
// style: Style,
// }
//
// #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
// pub enum Slant {
// Normal,
// Italic,
// Oblique,
// }
//
// #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
// pub enum Weight {
// Normal,
// Bold,
// }
//
// /// Style of font.
// #[derive(Debug, Clone, PartialEq, Eq, Hash)]
// pub enum Style {
// Specific(String),
// Description { slant: Slant, weight: Weight },
// }
//
// impl fmt::Display for Style {
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// match *self {
// Style::Specific(ref s) => f.write_str(s),
// Style::Description { slant, weight } => {
// write!(f, "slant={:?}, weight={:?}", slant, weight)
// },
// }
// }
// }
//
// impl FontDesc {
// pub fn new<S>(name: S, style: Style) -> FontDesc
// where
// S: Into<String>,
// {
// FontDesc { name: name.into(), style }
// }
// }
//
// impl fmt::Display for FontDesc {
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// write!(f, "{} - {}", self.name, self.style)
// }
// }
//
// /// Identifier for a Font for use in maps/etc.
// #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
// pub struct FontKey {
// token: u32,
// }
//
// impl FontKey {
// /// Get next font key for given size.
// ///
// /// The generated key will be globally unique.
// pub fn next() -> FontKey {
// static TOKEN: AtomicUsize = AtomicUsize::new(0);
//
// FontKey { token: TOKEN.fetch_add(1, Ordering::SeqCst) as _ }
// }
// }
//
// #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
// pub struct GlyphKey {
// pub character: char,
// pub font_key: FontKey,
// pub size: Size,
// }
//
// /// Font size stored as integer.
// #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
// pub struct Size(i16);
//
// impl Size {
// /// Create a new `Size` from a f32 size in points.
// pub fn new(size: f32) -> Size {
// Size((size * Size::factor()) as i16)
// }
//
// /// Scale factor between font "Size" type and point size.
// #[inline]
// pub fn factor() -> f32 {
// 2.0
// }
//
// /// Get the f32 size in points.
// pub fn as_f32_pts(self) -> f32 {
// f32::from(self.0) / Size::factor()
// }
// }
//
// impl<T: Into<Size>> Add<T> for Size {
// type Output = Size;
//
// fn add(self, other: T) -> Size {
// Size(self.0.saturating_add(other.into().0))
// }
// }
//
// impl<T: Into<Size>> Mul<T> for Size {
// type Output = Size;
//
// fn mul(self, other: T) -> Size {
// Size(self.0 * other.into().0)
// }
// }
//
// impl From<f32> for Size {
// fn from(float: f32) -> Size {
// Size::new(float)
// }
// }
//
// #[derive(Debug, Clone)]
// pub struct RasterizedGlyph {
// pub character: char,
// pub width: i32,
// pub height: i32,
// pub top: i32,
// pub left: i32,
// pub advance: (i32, i32),
// pub buffer: BitmapBuffer,
// }
//
// #[derive(Clone, Debug)]
// pub enum BitmapBuffer {
// /// RGB alphamask.
// Rgb(Vec<u8>),
//
// /// RGBA pixels with premultiplied alpha.
// Rgba(Vec<u8>),
// }
//
// impl Default for RasterizedGlyph {
// fn default() -> RasterizedGlyph {
// RasterizedGlyph {
// character: ' ',
// width: 0,
// height: 0,
// top: 0,
// left: 0,
// advance: (0, 0),
// buffer: BitmapBuffer::Rgb(Vec::new()),
// }
// }
// }
//
// #[derive(Debug, Copy, Clone)]
// pub struct Metrics {
// pub average_advance: f64,
// pub line_height: f64,
// pub descent: f32,
// pub underline_position: f32,
// pub underline_thickness: f32,
// pub strikeout_position: f32,
// pub strikeout_thickness: f32,
// }
//
// /// Errors occuring when using the rasterizer.
// #[derive(Debug, error::Error)]
// pub enum Error {
// /// Unable to find a font matching the description.
// #[error("font {0:?} not found")]
// FontNotFound(FontDesc),
//
// /// Unable to find metrics for a font face.
// #[error("metrics not found")]
// MetricsNotFound,
//
// /// The glyph could not be found in any font.
// #[error("glyph for character {:?} not found", .0.character)]
// MissingGlyph(RasterizedGlyph),
//
// /// Requested an operation with a FontKey that isn't known to the rasterizer.
// #[error("invalid font key")]
// UnknownFontKey,
//
// /// Error from platfrom's font system.
// #[error("{0:?}")]
// PlatformError(freetype::Error),
// }
//
// pub trait FontMap {
// /// Create a new Rasterizer.
// fn new(device_pixel_ratio: f32, use_thin_strokes: bool) -> Result<Self, Error>
// where
// Self: Sized;
//
// /// Get `Metrics` for the given `FontKey`.
// fn metrics(&self, _: FontKey, _: Size) -> Result<Metrics, Error>;
//
// /// Load the font described by `FontDesc` and `Size`.
// fn load_font(&mut self, _: &FontDesc, _: Size) -> Result<FontKey, Error>;
//
// /// Rasterize the glyph described by `GlyphKey`..
// fn glyph(&mut self, _: GlyphKey) -> Result<RasterizedGlyph, Error>;
//
// /// Update the Rasterizer's DPI factor.
// fn set_device_pixel_ratio(&mut self, device_pixel_ratio: f32);
//
// /// Kerning between two characters.
// fn kerning(&mut self, left: GlyphKey, right: GlyphKey) -> (f32, f32);
// }