@@ -21,23 +21,17 @@ thread_local! {
21
21
struct PathBuilder {
22
22
current_subpath : Subpath < PointId > ,
23
23
glyph_subpaths : Vec < Subpath < PointId > > ,
24
- other_subpaths : Vec < VectorData > ,
25
- origin : DVec2 ,
24
+ other_subpaths : Vec < crate :: instances:: Instance < VectorData > > ,
26
25
scale : f64 ,
27
26
id : PointId ,
28
27
}
29
28
30
29
impl PathBuilder {
31
30
fn point ( & self , x : f32 , y : f32 ) -> DVec2 {
32
- // Y-axis inversion converts from font coordinate system (Y-up) to graphics coordinate system (Y-down)
33
- DVec2 :: new ( self . origin . x + x as f64 , self . origin . y - y as f64 ) * self . scale
31
+ DVec2 :: new ( x as f64 , -y as f64 ) * self . scale
34
32
}
35
33
36
- fn set_origin ( & mut self , x : f64 , y : f64 ) {
37
- self . origin = DVec2 :: new ( x, y) ;
38
- }
39
-
40
- fn draw_glyph ( & mut self , glyph : & OutlineGlyph < ' _ > , size : f32 , normalized_coords : & [ NormalizedCoord ] , style_skew : Option < DAffine2 > , skew : DAffine2 ) {
34
+ fn draw_glyph ( & mut self , glyph : & OutlineGlyph < ' _ > , size : f32 , normalized_coords : & [ NormalizedCoord ] , glyph_offset : DVec2 , style_skew : Option < DAffine2 > , skew : DAffine2 ) {
41
35
let location_ref = LocationRef :: new ( normalized_coords) ;
42
36
let settings = DrawSettings :: unhinted ( Size :: new ( size) , location_ref) ;
43
37
glyph. draw ( settings, self ) . unwrap ( ) ;
@@ -53,7 +47,11 @@ impl PathBuilder {
53
47
}
54
48
55
49
if !self . glyph_subpaths . is_empty ( ) {
56
- self . other_subpaths . push ( VectorData :: from_subpaths ( core:: mem:: take ( & mut self . glyph_subpaths ) , false ) ) ;
50
+ self . other_subpaths . push ( crate :: instances:: Instance {
51
+ instance : VectorData :: from_subpaths ( core:: mem:: take ( & mut self . glyph_subpaths ) , false ) ,
52
+ transform : DAffine2 :: from_translation ( glyph_offset) ,
53
+ ..Default :: default ( )
54
+ } )
57
55
}
58
56
}
59
57
}
@@ -145,14 +143,12 @@ fn render_glyph_run(glyph_run: &GlyphRun<'_, ()>, path_builder: &mut PathBuilder
145
143
let outlines = font_ref. outline_glyphs ( ) ;
146
144
147
145
for glyph in glyph_run. glyphs ( ) {
148
- let glyph_x = run_x + glyph. x ;
149
- let glyph_y = run_y - glyph. y ;
146
+ let glyph_offset = DVec2 :: new ( ( run_x + glyph. x ) as f64 , ( run_y - glyph. y ) as f64 ) ;
150
147
run_x += glyph. advance ;
151
148
152
149
let glyph_id = GlyphId :: from ( glyph. id ) ;
153
150
if let Some ( glyph_outline) = outlines. get ( glyph_id) {
154
- path_builder. set_origin ( glyph_x as f64 , glyph_y as f64 ) ;
155
- path_builder. draw_glyph ( & glyph_outline, font_size, & normalized_coords, style_skew, skew) ;
151
+ path_builder. draw_glyph ( & glyph_outline, font_size, & normalized_coords, glyph_offset, style_skew, skew) ;
156
152
}
157
153
}
158
154
}
@@ -187,14 +183,13 @@ fn layout_text(str: &str, font_data: Option<Blob<u8>>, typesetting: TypesettingC
187
183
Some ( layout)
188
184
}
189
185
190
- pub fn to_path ( str : & str , font_data : Option < Blob < u8 > > , typesetting : TypesettingConfig ) -> Vec < VectorData > {
186
+ pub fn to_path ( str : & str , font_data : Option < Blob < u8 > > , typesetting : TypesettingConfig ) -> Vec < crate :: instances :: Instance < VectorData > > {
191
187
let Some ( layout) = layout_text ( str, font_data, typesetting) else { return Vec :: new ( ) } ;
192
188
193
189
let mut path_builder = PathBuilder {
194
190
current_subpath : Subpath :: new ( Vec :: new ( ) , false ) ,
195
191
glyph_subpaths : Vec :: new ( ) ,
196
192
other_subpaths : Vec :: new ( ) ,
197
- origin : DVec2 :: ZERO ,
198
193
scale : layout. scale ( ) as f64 ,
199
194
id : PointId :: ZERO ,
200
195
} ;
0 commit comments