Skip to content

Commit

Permalink
Reset char size even if bitmap buffer is null (#243)
Browse files Browse the repository at this point in the history
I was getting incorrect bounds for glyphs after rasterizing the
space(' ') glyph.
In rasterize_glyph(), there is an early return if the bitmap buffer is
null (as it is a space) and because of that the char size is not reset
correctly. Then if you call raster_bounds for another glyph it loads it
with the rasterize char size.
  • Loading branch information
indefini authored May 18, 2024
1 parent 97e4ba5 commit 7ebe4ea
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/loaders/freetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,26 +865,32 @@ impl Font {
bitmap_length, 0,
"bitmap length should be 0 when bitmap_buffer is nullptr"
);
return Ok(());
}
let buffer = slice::from_raw_parts(bitmap_buffer, bitmap_length);
let dst_point = Vector2I::new(
(*(*self.freetype_face).glyph).bitmap_left,
-(*(*self.freetype_face).glyph).bitmap_top,
);
} else {
let buffer = slice::from_raw_parts(bitmap_buffer, bitmap_length);
let dst_point = Vector2I::new(
(*(*self.freetype_face).glyph).bitmap_left,
-(*(*self.freetype_face).glyph).bitmap_top,
);

// FIXME(pcwalton): This function should return a Result instead.
match bitmap.pixel_mode {
FT_PIXEL_MODE_GRAY => {
canvas.blit_from(dst_point, buffer, bitmap_size, bitmap_stride, Format::A8);
}
FT_PIXEL_MODE_LCD | FT_PIXEL_MODE_LCD_V => {
canvas.blit_from(dst_point, buffer, bitmap_size, bitmap_stride, Format::Rgb24);
}
FT_PIXEL_MODE_MONO => {
canvas.blit_from_bitmap_1bpp(dst_point, buffer, bitmap_size, bitmap_stride);
// FIXME(pcwalton): This function should return a Result instead.
match bitmap.pixel_mode {
FT_PIXEL_MODE_GRAY => {
canvas.blit_from(dst_point, buffer, bitmap_size, bitmap_stride, Format::A8);
}
FT_PIXEL_MODE_LCD | FT_PIXEL_MODE_LCD_V => {
canvas.blit_from(
dst_point,
buffer,
bitmap_size,
bitmap_stride,
Format::Rgb24,
);
}
FT_PIXEL_MODE_MONO => {
canvas.blit_from_bitmap_1bpp(dst_point, buffer, bitmap_size, bitmap_stride);
}
_ => panic!("Unexpected FreeType pixel mode!"),
}
_ => panic!("Unexpected FreeType pixel mode!"),
}

FT_Set_Transform(self.freetype_face, ptr::null_mut(), ptr::null_mut());
Expand Down

0 comments on commit 7ebe4ea

Please sign in to comment.