Red Hat Bugzilla – Bug 197747
gdImageStringFT sets improper bounding box for rendered text
Last modified: 2007-11-30 17:11:36 EST
Created attachment 131967 [details]
program for generating pngs
Description of problem:
gdImageStringFT() sets the bounding box for text to be rendered. Unfortunately,
the bounding box it calculates extends too far to the right (by an amount which
seems to depend on the font size). This makes it difficult center text
horizontally, since the text itself is not centered within the calculated
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Call gdImageStringFT to get a bounding box for some text.
2. Find the center of the BB.
3. Call gdImageStringFT to paint the text, offset by half of the BB width.
Text is several pixels too far to the left.
Text should be centered horizontally.
I'm attaching a little example program and a png generated by it which exhibits
the problem. At most sizes, the text is too far left by at least two pixels.
Created attachment 131969 [details]
example of the problem
The bounding box extends 3 pixels too far to the right of the period. This is
not so problematic for lengthy text, but extremely annoying for short text and
a disaster for rotated text.
Can you please send me program, which generates pictures with rotated text and
has the wrong bounding? Thank you.
Created attachment 132819 [details]
program for generating pngs with rotated text
Usage: rotate fontsize angle text >foo.png
The problem is easy to see if you make the size 24 and the angle 60, with some
short bit of text that has descenders (e.g., "Test string"). It appears that
the text is being painted into the lower-left corner (relative to the text) of
the bounding box.
Ok, thank you for the test program.
I wanted to make sure I know, what you your problem is.
Fixed in gd-2.0.33-11.fc7.