imageproc icon indicating copy to clipboard operation
imageproc copied to clipboard

`draw_text_mut` does not seem to account for accents when placing text.

Open Gremious opened this issue 11 months ago • 4 comments

Very simple, if I ask imageproc for text_size and then snugly render e.g. an Ä:

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

	let mplantin = include_bytes!("../resources/fonts/mplantin.ttf");
	let mplantin = ab_glyph::FontArc::try_from_slice(mplantin).unwrap();

	let font_size = 128.0;
	let word = "ÁÄaaa";

	let (mut w, mut h) = imageproc::drawing::text_size(font_size, &mplantin, word);
	let mut image: DynamicImage = DynamicImage::new_rgba8(w, h);

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

	image
}

The accents are cut off:

txt

But there is additional space at the bottom:

image

Which, if I offset by the right amount (16 in this case), seems to fit perfectly snug.

image

Which leads me to believe imageproc accounts for accents when doing text_size but not when placing the text.

Gremious avatar Jan 13 '25 03:01 Gremious

I remember fixing the text_size function. It’s in the master branch.

imageproc = { git = "https://github.com/image-rs/imageproc.git", branch = "master" }

cospectrum avatar Jan 13 '25 21:01 cospectrum

I remember fixing the text_size function. Try master branch.

imageproc = { git = "https://github.com/image-rs/imageproc.git", branch = "master" }

Maybe it doesn’t solve this issue, but it can be related if someone wants to test draw_text and text_size changes. And I think I already tried to raise a question about additional spacing, which depends on specific glyphs, and we decided not to add it.

cospectrum avatar Jan 13 '25 22:01 cospectrum

~~Yep, master works for me immediately and perfectly fine, thank you very much!~~

~~Feel free to close the issue as you see fit.~~

Gremious avatar Jan 13 '25 22:01 Gremious

On second check, master fixed my particular unrelated troubles with rendering text (so thank you very much), but this particular issue actually still remains, so keeping this open

And as for

Which leads me to believe imageproc accounts for accents when doing text_size but not when placing the text.

idk how imageproc actually works, cause that space on the bottom also fits low glyphs like g and in my font, ( so maybe wrong about this

Gremious avatar Jan 13 '25 23:01 Gremious