[cairo] reverse of finding text extents

Maarten Bosmans mkbosmans at gmail.com
Mon Sep 12 01:27:31 PDT 2011


2011/9/11 Roman Beslik <beroal at ukr.net>:
> Hello.
> For some text T and some number S, how can I determine the longest prefix T'
> of T such that the width of the image of T' is less than S? The practical
> aim is to break T into lines which fit in a rectangle.

How about letting Pango take care of this all? Line breaking
algorithms are not really trivial to get right, so you better not
implement this yourself. The cairo text functions aren't called *toy*
text interface for nothing, once you want more advanced text handling
(e.g. line breaking, proper international text support with font
fallback), you really should use pango.

Maarten


More information about the cairo mailing list