problem with portability of text extents

[Moving discussion from cairo list to this one, as I understand this is more appropriate for pango issues.]

I'm having difficulty drawing tight boxes around text - in particular with the
logical_rect.y value returned by pango_layout_get_extents().

The Pango Reference States that: "Logical extents are usually what you want for positioning things."  But the logical_rect.y value seems to be always "0" and referring probably to some arbitrary y=0 reference used during font design.

I think logical_rect.y should more usefully represent the maximum ascent of any character in the font.  (Strictly, any font used in the top line of a pango layout.)

To illustrate the problem, I've attached two images showing the logical_rect of the string "Ay" in an Fc "Times" font on Linux, and on a Mac, with an Atsui "Times" font.   The Atsui logical_rect actually seems more reasonable - but the bigger problem for me is that the space at the top is not consistent for "Times" across all platforms.

As a workaround, I'm ignoring logical_rect.y and logical_rect.height and instead using:
on all platforms.  But this doesn't feel like the right fix.

Note that using ink_rect would not solve the problem (for graphviz) as that would result in the box height varying with the string content.

Using: pango-1.28.1-4.fc14.x86_64

Comments?    Should I submit this as a pango bug?

I might try to work on a fix myself, if I can be sure I'm going in an acceptable direction.

John Ellson

-------- Original Message --------
Subject: Re: [cairo] problem with portability of text extents
Date: Thu, 10 Feb 2011 23:36:10 -0500
From: Behdad Esfahbod <behdad behdad org>
To: John Ellson <ellson research att com>
CC: cairo cairographics org

On 02/09/11 23:53, John Ellson wrote:
> This maybe a pango problem that I should take elsewhere (?) but I think the
> root cause is in the cairo font backends so I'll ask here first.
> The problem I'm having is that the logical_rect returned by
> pango_layout_get_extents() includes whitespace above and below the text when
> using  PangoCairoFcFont on Fedora, but not when using PangoCairoATSUIFont on a
> Mac.

Hi John,

This is most probably a bug in pangocairo-atsuifont.c's

The ATSUI backend is not well tested and suffers from many problems.

> Would the cairo developers be willing to accept this as a bug, or should I
> attempt to make my own backend-specific compensation to meet my needs in graphviz?

If the ink extents work better, you may want to use those.

Other than that, improvements to the pango code are appreciated, but it's not
something I can work on myself.


> I'll post or send my test code if anyone asks.
> John
> --
> cairo mailing list
> cairo cairographics org

Attachment: Darwin.png
Description: PNG image

Attachment: Linux.png
Description: PNG image

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