core: graphics: finish supporting glyphs extending past font descent

Extend the height of the label when a glyph goes past the descent.

Also truncate the bitmap when the height is final.

Also remove statements added for debugging.
This commit is contained in:
Richard Acayan 2024-08-19 23:02:50 -04:00
parent 6027469c08
commit e17e4f31f5

View file

@ -320,10 +320,6 @@ impl<D: Display> Graphics<D> {
let mut y = y_max as usize - metrics.ascender as usize / 64; let mut y = y_max as usize - metrics.ascender as usize / 64;
let height = (y_max - y_min) as usize; let height = (y_max - y_min) as usize;
println!("{} {}, {}", (-bbox.yMin) as usize,
metrics.y_ppem as usize,
metrics.descender);
let vec: Vec<u8> = vec![0; stride * height]; let vec: Vec<u8> = vec![0; stride * height];
let mut img = ImgVec::new(vec, stride, height); let mut img = ImgVec::new(vec, stride, height);
@ -349,6 +345,10 @@ impl<D: Display> Graphics<D> {
y = dest_y as usize; y = dest_y as usize;
} }
if height < dest_y as usize + glyph.bitmap.rows as usize {
height = dest_y as usize + glyph.bitmap.rows as usize;
}
let src = bitmap_to_imgref(&glyph.bitmap); let src = bitmap_to_imgref(&glyph.bitmap);
let dest = img.sub_image_mut(dest_x as usize, let dest = img.sub_image_mut(dest_x as usize,
dest_y as usize, dest_y as usize,
@ -370,10 +370,9 @@ impl<D: Display> Graphics<D> {
freetype::FT_Done_Face(ftface); freetype::FT_Done_Face(ftface);
}; };
let vec = img.into_buf(); let mut vec = img.into_buf();
println!("{}, {}x{}", vec.len(), stride, height); vec.truncate(stride * height);
let img = ImgVec::new_stride(vec, width, height, stride); let img = ImgVec::new_stride(vec, width, height, stride);
img.sub_image(0, 0, width, height - y);
TextRaster { TextRaster {
img, img,