@@ -52,57 +52,58 @@ impl FontAtlasSet {
52
52
font_size : f32 ,
53
53
text : & str ,
54
54
) -> f32 {
55
- let font = fonts. get ( & self . font ) . unwrap ( ) ;
56
- let scaled_font = ab_glyph:: Font :: as_scaled ( & font. font , font_size) ;
57
- let font_atlases = self
58
- . font_atlases
59
- . entry ( FloatOrd ( font_size) )
60
- . or_insert_with ( || {
61
- vec ! [ FontAtlas :: new(
62
- textures,
63
- texture_atlases,
64
- Vec2 :: new( 512.0 , 512.0 ) ,
65
- ) ]
66
- } ) ;
67
-
68
- let mut last_glyph: Option < Glyph > = None ;
69
55
let mut width = 0.0 ;
70
- for character in text. chars ( ) {
71
- if character. is_control ( ) {
72
- continue ;
73
- }
74
- let glyph = scaled_font. scaled_glyph ( character) ;
75
- if let Some ( last_glyph) = last_glyph. take ( ) {
76
- width += scaled_font. kern ( last_glyph. id , glyph. id ) ;
77
- }
78
- if !font_atlases
79
- . iter ( )
80
- . any ( |atlas| atlas. get_char_index ( character) . is_some ( ) )
81
- {
82
- if let Some ( outlined_glyph) = scaled_font. outline_glyph ( glyph. clone ( ) ) {
83
- let glyph_texture = Font :: get_outlined_glyph_texture ( outlined_glyph) ;
84
- let add_char_to_font_atlas = |atlas : & mut FontAtlas | -> bool {
85
- atlas. add_char ( textures, texture_atlases, character, & glyph_texture)
86
- } ;
87
- if !font_atlases. iter_mut ( ) . any ( add_char_to_font_atlas) {
88
- font_atlases. push ( FontAtlas :: new (
89
- textures,
90
- texture_atlases,
91
- Vec2 :: new ( 512.0 , 512.0 ) ,
92
- ) ) ;
93
- if !font_atlases. last_mut ( ) . unwrap ( ) . add_char (
94
- textures,
95
- texture_atlases,
96
- character,
97
- & glyph_texture,
98
- ) {
99
- panic ! ( "could not add character to newly created FontAtlas" ) ;
56
+ if let Some ( font) = fonts. get ( & self . font ) {
57
+ let scaled_font = ab_glyph:: Font :: as_scaled ( & font. font , font_size) ;
58
+ let font_atlases = self
59
+ . font_atlases
60
+ . entry ( FloatOrd ( font_size) )
61
+ . or_insert_with ( || {
62
+ vec ! [ FontAtlas :: new(
63
+ textures,
64
+ texture_atlases,
65
+ Vec2 :: new( 512.0 , 512.0 ) ,
66
+ ) ]
67
+ } ) ;
68
+
69
+ let mut last_glyph: Option < Glyph > = None ;
70
+ for character in text. chars ( ) {
71
+ if character. is_control ( ) {
72
+ continue ;
73
+ }
74
+ let glyph = scaled_font. scaled_glyph ( character) ;
75
+ if let Some ( last_glyph) = last_glyph. take ( ) {
76
+ width += scaled_font. kern ( last_glyph. id , glyph. id ) ;
77
+ }
78
+ if !font_atlases
79
+ . iter ( )
80
+ . any ( |atlas| atlas. get_char_index ( character) . is_some ( ) )
81
+ {
82
+ if let Some ( outlined_glyph) = scaled_font. outline_glyph ( glyph. clone ( ) ) {
83
+ let glyph_texture = Font :: get_outlined_glyph_texture ( outlined_glyph) ;
84
+ let add_char_to_font_atlas = |atlas : & mut FontAtlas | -> bool {
85
+ atlas. add_char ( textures, texture_atlases, character, & glyph_texture)
86
+ } ;
87
+ if !font_atlases. iter_mut ( ) . any ( add_char_to_font_atlas) {
88
+ font_atlases. push ( FontAtlas :: new (
89
+ textures,
90
+ texture_atlases,
91
+ Vec2 :: new ( 512.0 , 512.0 ) ,
92
+ ) ) ;
93
+ if !font_atlases. last_mut ( ) . unwrap ( ) . add_char (
94
+ textures,
95
+ texture_atlases,
96
+ character,
97
+ & glyph_texture,
98
+ ) {
99
+ panic ! ( "could not add character to newly created FontAtlas" ) ;
100
+ }
100
101
}
101
102
}
103
+ width += scaled_font. h_advance ( glyph. id ) ;
104
+ last_glyph = Some ( glyph) ;
102
105
}
103
106
}
104
- width += scaled_font. h_advance ( glyph. id ) ;
105
- last_glyph = Some ( glyph) ;
106
107
}
107
108
108
109
width
0 commit comments