AWS Thinkbox Discussion Forums

Text alignment

Hi guys!

I’m not sure if it’s really a bug or I just overlooked or missed something but anyway here’s my problem.
I’ve created a Draft script we want to use to generate slate for output movies.
It’s working fine however there are some issues with annotation text alignment.
I’ve attached a minimalistic Draft script to reproduce the phenomenon and the (cropped) output.

Draft version: Draft_1_0_0_49258_RC3.zip (this is the latest I believe)
OS: Ubuntu 10.04 x64 LTS

PS: The path to the used typeface and the output path of the test image should be adjusted before testing the script. They are marked with “COMMENT”

Thanks is advance,
Imre
Draft-report-001-2012.12.05.zip (22 KB)

There’s a couple things at play here. The first thing you need to know about is the FontTypeMetric class (I’m in the process of adding this to the documentation):

FontTypeMetric
Type: Class
Description: A class to retrieve font and text properties for annotations.
Properties:
Ascent – The distance in pixels from the text baseline to the highest/upper grid coordinate used to place an outline point.
Descent – The distance in pixels from the baseline to the lowest grid coordinate used to place an outline point. Always a negative value.
TextHeight – The height in pixels of the text written, this does not include any padding
TextWidth – The width in pixels of the text written, this does not include any padding
BaselineOffset – Offset in pixels from the bottom of the image to the baseline used to write the text. Use this to align text from different point sizes and fonts.
MaxHorizontalAdvance – Maximum horizontal advance in pixels.

Your annInfo variable will have a property called FontMetric, which is an object of type FontTypeMetric, that gets set when you call CreateAnnotation. You will want to use annInfo.FontMetric.BaselineOffset to adjust the bottom coordinate for the composite operation.

The second thing you need to know about is some padding we added to prevent certain characters in certain fonts from being cropped. This is added to the left and right sides, and is proportional to the font size. The value being used is math.ceil( 0.16 * annInfo.PointSize). You will want to use this amount to adjust the left/right coordinate for the composite operation.

Using the baseline offset and the left/right padding, you should be able to get very close to correct alignment. If you can’t, you’ve run into our third issue: something isn’t quite right. I’ve tried to track this down in the past, but haven’t been successful yet. There’s something going on with the numbers that doesn’t make sense. If you do still have problems after accounting for both of the above, send me your code again, and I’ll see if it can help me track down this problem.

Cheers,
Andrea

One more thing that I forgot in my previous reply: There’s also some padding added to the image for the shadow, regardless whether it is drawn. It shifts the text to the left by math.floor( 0.05 * annInfo.PointSize ).

Is your alignment working better yet?

Cheers,
Andrea

Hi Andrea,

thanks for the info!
Now the texts are (almost) perfectly aligned.

Thanks,
Imre

Would you like me to have a look at your new calculations to see if I can improve the alignment any?

Cheers,
Andrea

Privacy | Site terms | Cookie preferences