Skip to content

text_size does not seem to account for vertical padding. #717

@NonayMete

Description

@NonayMete

Simple example script behaves unexpectedly.
I ask imageproc for text_size and then render a few characters.

pub fn txt_img() -> image::DynamicImage {
	use imageproc::drawing::draw_text_mut;

	let deja_vu_sans = include_bytes!(r"..\..\system\registration\assets\DejaVuSans.ttf");
	let deja_vu_sans = ab_glyph::FontArc::try_from_slice(deja_vu_sans).unwrap();

	let font_size = 128.0;
	let word = "FMCPE";
	let (w, h) = imageproc::drawing::text_size(font_size, &deja_vu_sans, word);
	let mut image = image::DynamicImage::new_rgba8(w, h);

	draw_text_mut(&mut image, image::Rgba([ 255u8, 255u8, 255u8, 255u8 ]), 0, 0, font_size, &deja_vu_sans, word);

	image
}

fn main() {
    let img = txt_img();
    img.save("test.png").unwrap();
}

The bottom of the letters in "test.png" are cut off.

"test.png"
Image

I have tried a number of random windows fonts and had the same issue with all of them.

Unsure what the root cause of the issue is, whether it is the vertical padding built into the font or some other kind of logic bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions