@@ -38,18 +38,24 @@ impl PixelFont {
38
38
}
39
39
40
40
impl GlyphRenderer for PixelFont {
41
- fn render_glyph ( & self , glyph_id : core:: num:: NonZeroU16 ) -> RenderableGlyph {
41
+ fn render_glyph ( & self , glyph_id : core:: num:: NonZeroU16 ) -> Option < RenderableGlyph > {
42
42
let glyph_index = Self :: glyph_id_to_glyph_index ( glyph_id) ;
43
43
let bitmap_glyph = & self . glyphs . glyph_data [ glyph_index] ;
44
- RenderableGlyph {
44
+ if bitmap_glyph. data . len ( ) == 0 {
45
+ // For example, ' ' has no glyph data
46
+ return None ;
47
+ }
48
+ let width = self . scale_glyph_length ( bitmap_glyph. width - 1 ) + PhysicalLength :: new ( 1 ) ;
49
+ let height = self . scale_glyph_length ( bitmap_glyph. height - 1 ) + PhysicalLength :: new ( 1 ) ;
50
+ Some ( RenderableGlyph {
45
51
x : self . scale_glyph_length ( bitmap_glyph. x ) ,
46
- y : self . scale_glyph_length ( bitmap_glyph. y ) ,
47
- width : self . scale_glyph_length ( bitmap_glyph . width - 1 ) + PhysicalLength :: new ( 1 ) ,
48
- height : self . scale_glyph_length ( bitmap_glyph . height - 1 ) + PhysicalLength :: new ( 1 ) ,
52
+ y : self . scale_glyph_length ( bitmap_glyph. y + bitmap_glyph . height ) - height ,
53
+ width,
54
+ height,
49
55
alpha_map : bitmap_glyph. data . as_slice ( ) . into ( ) ,
50
56
pixel_stride : bitmap_glyph. width as u16 ,
51
57
sdf : self . bitmap_font . sdf ,
52
- }
58
+ } )
53
59
}
54
60
fn scale_delta ( & self ) -> super :: Fixed < u16 , 8 > {
55
61
super :: Fixed :: from_integer ( self . glyphs . pixel_size as u16 ) / self . pixel_size . get ( ) as u16
0 commit comments