image-rs / image-rs/imageproc

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

Open
#710 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
979
Forks
181
Avg merge
5m
Merged PRs (30d)
4

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the text_size and draw_text_mut entry points using the provided ÁÄaaa example, font, and 128.0 size. Reproduce the clipped accents and extra bottom space, then ensure both APIs use consistent vertical placement so the rendered text fits the reported dimensions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.