1use super::font_face::*;
2
3use flo_curves::geo::*;
4
5use std::sync::*;
6
7#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
11pub enum FontStyle {
12 Normal,
13 Italic,
14 Oblique
15}
16
17#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
21pub struct FontProperties {
22 pub style: FontStyle,
23 pub weight: u32
24}
25
26impl Default for FontStyle {
27 fn default() -> FontStyle { FontStyle::Normal }
28}
29
30impl Default for FontProperties {
31 fn default() -> FontProperties { FontProperties { style: FontStyle::default(), weight: 400 } }
32}
33
34impl FontProperties {
35 pub fn with_weight(mut self, new_weight: u32) -> FontProperties {
39 self.weight = new_weight;
40 self
41 }
42
43 pub fn with_style(mut self, new_style: FontStyle) -> FontProperties {
47 self.style = new_style;
48 self
49 }
50}
51
52#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
56pub enum TextAlignment {
57 Left,
58 Right,
59 Center
60}
61
62#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
66pub enum FontOp {
67 UseFontDefinition(Arc<CanvasFontFace>),
69
70 FontSize(f32),
72
73 LayoutText(String),
75
76 DrawGlyphs(Vec<GlyphPosition>)
78}
79
80#[derive(Copy, Clone, PartialEq)]
84pub struct FontLinePosition {
85 pub offset: f32,
86 pub thickness: f32
87}
88
89#[derive(Copy, Clone, PartialEq)]
93pub struct FontMetrics {
94 pub em_size: f32,
96
97 pub ascender: f32,
99
100 pub descender: f32,
102
103 pub height: f32,
105
106 pub line_gap: f32,
108
109 pub capital_height: Option<f32>,
111
112 pub underline_position: Option<FontLinePosition>,
114
115 pub strikeout_position: Option<FontLinePosition>,
117}
118
119impl FontMetrics {
120 pub fn with_size(self, em_size: f32) -> FontMetrics {
124 let scale_factor = em_size / self.em_size;
125
126 FontMetrics {
127 em_size: self.em_size * scale_factor,
128 ascender: self.ascender * scale_factor,
129 descender: self.descender * scale_factor,
130 height: self.height * scale_factor,
131 line_gap: self.line_gap * scale_factor,
132 capital_height: self.capital_height.map(|height| height*scale_factor),
133 underline_position: self.underline_position.map(|mut pos| { pos.offset *= scale_factor; pos.thickness *= scale_factor; pos }),
134 strikeout_position: self.strikeout_position.map(|mut pos| { pos.offset *= scale_factor; pos.thickness *= scale_factor; pos }),
135 }
136 }
137}
138
139#[derive(Copy, Clone, PartialEq)]
143pub struct TextLayoutMetrics {
144 pub inner_bounds: (Coord2, Coord2),
146
147 pub pos: Coord2
149}
150
151#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
155pub struct GlyphId(pub u32);
156
157#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
161pub struct GlyphPosition {
162 pub id: GlyphId,
164
165 pub location: (f32, f32),
167
168 pub em_size: f32
170}