Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Gremious opened this issue Jan 13, 2025 · 4 comments
Open

Comments

@Gremious
Copy link

Gremious commented Jan 13, 2025

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 Gremious changed the title draw_text_mut does not seem to account for accents when placing text. draw_text_mut does not seem to account for accents when placing text. Jan 13, 2025
@cospectrum
Copy link
Contributor

cospectrum commented Jan 13, 2025

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
Copy link
Contributor

cospectrum commented Jan 13, 2025

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.

@Gremious
Copy link
Author

Gremious commented Jan 13, 2025

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

Feel free to close the issue as you see fit.

@Gremious
Copy link
Author

Gremious commented Jan 13, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants