freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft] Total width of text


From: Wojtek Mamrak
Subject: Re: [ft] Total width of text
Date: Wed, 13 Apr 2011 23:20:35 +0200

Also you may find this article very interesting:

http://en.wikipedia.org/wiki/Word_wrap

regards


2011/4/13 Patrick Baggett <address@hidden>
I believe the tutorial has a page for it: http://www.freetype.org/freetype2/docs/tutorial/step2.html

See section 4b, namely the function void compute_string_bbox( FT_BBox *abbox )

It basically adds up the bounding boxes of each character.

Effectively, the algorithm looks like:
0) M <- invalid bounding box
1) For each glyph G
1.1)     Get kerning, advance pen
1.2)     Get the bounding box as B
1.3)     Add the pen position to B
1.4)     Check if B is larger than the current bounding box M, if so, update it
1.5)     Advance pen by G.advance
2) Check if box is valid, correct if necessary

The compute_string_bbox() function assumes that each character already has its position set (which includes kerning + advance), so if you haven't already computed that, use the psuedocode above will get you through.



On Wed, Apr 13, 2011 at 10:23 AM, Leonardo M. Ramé <address@hidden> wrote:
Hi, I'm trying to place text over a bitmap using the function below.

If you take a look at the function, there's a "baseline" variable, in
charge of adjusting the top position of the character bitmap. If I don't
do this, all character ar aligned to the top "pen_y" point. I don't know
if this is the recommended way to align text. Please tell me if you know
a better way.

Also, I want to create a box filled in a color between the image and the
text. For example, the image in grayscale, then a red box with black text.

My question is, how can I get the measures (in pixels) of the box
containing all the text, not just each character.


_______________________________________________
Freetype mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/freetype



reply via email to

[Prev in Thread] Current Thread [Next in Thread]