Re: Measuring text lengths with Pango

On Wed, 22 Feb 2006, it was written:

> Hi everyone,
> I need to write some code to arrange text paragraphs along with image
> boxes in off-screen, "real", coordinates (cm, mm, in, etc).
> But Pango seems to be aways bounded to device units (pixels), which is
> not what I want.

No, device units do not necessarily mean pixels.  It's just
device units, whatever it may mean.  You may define a device unit
as one millimeter for example.  All you need to tell Pango about
is your desired dpi (device-units per inch ;)).  In the case of
millimeters, that would be 25.4dpi.  Setting dpi is
backend-dependent.  For FT2 backend, it's
pango_ft2_font_map_set_resolution.  For Cairo, it's
pango_cairo_font_map_set_resolution, and for Xft it's a bit
harder than a single call.

Of course there is a point here and it's that device units (dots)
are supposed to be dots, so, if hinting is enabled, glyphs and
extents may be rounded to integer units.  For that, you may want
to choose something like 1/10millimeter units, using 254dpi

Anyway, guess you got it, it's all a matter of converting to the
right unit:

72pt = 1in
1in = 2.54cm
1in = (your PangoFontMap's dpi setting) device units
1 device unit = PANGO_SCALE Pango units


> An exaple: I want to know the length, in centimeters, of the sentence
> "Hello, World!" on a 12pt Times New Roman font.
> I've spent quite a few hours trying to find out how could I use Pango to
> give me that info but I had no success yet (yes, I'm a newbie).
> Can you guys give me some directions?
> Thanks in advance,
> Daniel d'Andrada T. de Carvalho - INdT


"Commandment Three says Do Not Kill, Amendment Two says Blood Will Spill"
	-- Dan Bern, "New American Language"

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