1
- use core:: cell:: RefCell ;
2
- use std:: sync:: Arc ;
3
-
4
1
use crate :: vector:: PointId ;
5
2
use bezier_rs:: { ManipulatorGroup , Subpath } ;
3
+ use core:: cell:: RefCell ;
6
4
use glam:: DVec2 ;
7
- use parley:: { Alignment , AlignmentOptions , FontContext , GlyphRun , Layout , LayoutContext , LineHeight , PositionedLayoutItem , StyleProperty , fontique:: Blob } ;
8
- use skrifa:: {
9
- GlyphId , MetadataProvider , OutlineGlyph ,
10
- instance:: { LocationRef , NormalizedCoord , Size } ,
11
- outline:: { DrawSettings , OutlinePen } ,
12
- raw:: FontRef as ReadFontsRef ,
13
- } ;
5
+ use parley:: fontique:: Blob ;
6
+ use parley:: { Alignment , AlignmentOptions , FontContext , GlyphRun , Layout , LayoutContext , LineHeight , PositionedLayoutItem , StyleProperty } ;
7
+ use skrifa:: GlyphId ;
8
+ use skrifa:: instance:: { LocationRef , NormalizedCoord , Size } ;
9
+ use skrifa:: outline:: { DrawSettings , OutlinePen } ;
10
+ use skrifa:: raw:: FontRef as ReadFontsRef ;
11
+ use skrifa:: { MetadataProvider , OutlineGlyph } ;
12
+ use std:: sync:: Arc ;
14
13
15
14
thread_local ! {
16
15
static FONT_CONTEXT : RefCell <FontContext > = RefCell :: new( FontContext :: new( ) ) ;
@@ -20,20 +19,18 @@ thread_local! {
20
19
struct PathBuilder {
21
20
current_subpath : Subpath < PointId > ,
22
21
other_subpaths : Vec < Subpath < PointId > > ,
23
- x : f32 ,
24
- y : f32 ,
22
+ origin : DVec2 ,
25
23
scale : f64 ,
26
24
id : PointId ,
27
25
}
28
26
29
27
impl PathBuilder {
30
28
fn point ( & self , x : f32 , y : f32 ) -> DVec2 {
31
- DVec2 :: new ( ( self . x + x) as f64 , ( self . y - y) as f64 ) * self . scale
29
+ DVec2 :: new ( self . origin . x + x as f64 , self . origin . y - y as f64 ) * self . scale
32
30
}
33
31
34
- fn set_origin ( & mut self , x : f32 , y : f32 ) {
35
- self . x = x;
36
- self . y = y;
32
+ fn set_origin ( & mut self , x : f64 , y : f64 ) {
33
+ self . origin = DVec2 :: new ( x, y) ;
37
34
}
38
35
39
36
fn draw_glyph ( & mut self , glyph : & OutlineGlyph < ' _ > , size : f32 , normalized_coords : & [ NormalizedCoord ] ) {
@@ -122,7 +119,7 @@ fn render_glyph_run(glyph_run: &GlyphRun<'_, ()>, path_builder: &mut PathBuilder
122
119
123
120
let glyph_id = GlyphId :: from ( glyph. id ) ;
124
121
if let Some ( glyph_outline) = outlines. get ( glyph_id) {
125
- path_builder. set_origin ( glyph_x, glyph_y) ;
122
+ path_builder. set_origin ( glyph_x as f64 , glyph_y as f64 ) ;
126
123
path_builder. draw_glyph ( & glyph_outline, font_size, & normalized_coords) ;
127
124
}
128
125
}
@@ -138,11 +135,11 @@ fn layout_text(str: &str, font_data: Option<Blob<u8>>, typesetting: TypesettingC
138
135
font_cx
139
136
. collection
140
137
. register_fonts ( font_data, None )
141
- . get ( 0 )
138
+ . first ( )
142
139
. and_then ( |( family_id, _) | font_cx. collection . family_name ( * family_id) . map ( String :: from) )
143
140
} ) ?;
144
141
145
- const DISPLAY_SCALE : f32 = 1.0 ;
142
+ const DISPLAY_SCALE : f32 = 1. ;
146
143
let mut builder = layout_cx. ranged_builder ( & mut font_cx, str, DISPLAY_SCALE , true ) ;
147
144
148
145
builder. push_default ( StyleProperty :: FontSize ( typesetting. font_size as f32 ) ) ;
@@ -159,15 +156,12 @@ fn layout_text(str: &str, font_data: Option<Blob<u8>>, typesetting: TypesettingC
159
156
}
160
157
161
158
pub fn to_path ( str : & str , font_data : Option < Blob < u8 > > , typesetting : TypesettingConfig ) -> Vec < Subpath < PointId > > {
162
- let Some ( layout) = layout_text ( str, font_data, typesetting) else {
163
- return vec ! [ ] ;
164
- } ;
159
+ let Some ( layout) = layout_text ( str, font_data, typesetting) else { return Vec :: new ( ) } ;
165
160
166
161
let mut path_builder = PathBuilder {
167
162
current_subpath : Subpath :: new ( Vec :: new ( ) , false ) ,
168
163
other_subpaths : Vec :: new ( ) ,
169
- x : 0. ,
170
- y : 0. ,
164
+ origin : DVec2 :: ZERO ,
171
165
scale : layout. scale ( ) as f64 ,
172
166
id : PointId :: ZERO ,
173
167
} ;
@@ -195,9 +189,7 @@ pub fn bounding_box(str: &str, font_data: Option<Blob<u8>>, typesetting: Typeset
195
189
}
196
190
}
197
191
198
- let Some ( layout) = layout_text ( str, font_data, typesetting) else {
199
- return DVec2 :: ZERO ;
200
- } ;
192
+ let Some ( layout) = layout_text ( str, font_data, typesetting) else { return DVec2 :: ZERO } ;
201
193
202
194
DVec2 :: new ( layout. full_width ( ) as f64 , layout. height ( ) as f64 )
203
195
}
0 commit comments