After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 329545 - pango_layout_get_size is buggy
pango_layout_get_size is buggy
Status: RESOLVED NOTABUG
Product: pango
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: pango-maint
pango-maint
Depends on:
Blocks:
 
 
Reported: 2006-02-02 00:54 UTC by Behdad Esfahbod
Modified: 2006-02-17 08:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Behdad Esfahbod 2006-02-02 00:54:17 UTC
In Bug 328456, I rambled how the size returned by pango_layout_get_size is not useful, and we need a function like this:

int
pango_layout_get_effective_width (const PangoLayout *layout)
{
  int width;

  width = pango_layout_get_width (layout);
  if (width == -1)
    pango_layout_get_size (layout, &width, NULL);

  return width;
}

But now that I think about it, it seems to me that it's a bug in pango_layout_get_size.  The current implementation is:

void
pango_layout_get_size (PangoLayout *layout,
                       int         *width,
                       int         *height)
{
  PangoRectangle logical_rect;

  pango_layout_get_extents (layout, NULL, &logical_rect);

  if (width)
    *width = logical_rect.width;
  if (height)
    *height = logical_rect.height;
}

while a useful implementation should look like:

void
pango_layout_get_size (PangoLayout *layout,
                       int         *width,
                       int         *height)
{
  PangoRectangle logical_rect;

  pango_layout_get_extents (layout, NULL, &logical_rect);

  if (width)
    *width = logical_rect.x + logical_rect.width;
  if (height)
    *height = logical_rect.y + logical_rect.height;
}

It only makes a difference with right-aligned-only text, where logical_rect.x becomes non-zero.

This bug has been worked-around without anybody noticing this is a bug, in many places, including gtklabel.c, and probably a couple more places in gtk+.  It has caused bugs initially before being fixed in there.  Anyway, the current situation is that we cannot fix this or we will break stuff...

So probably another function should be added, and get_size (and get_pixel_size) being documented as they are.
Comment 1 Behdad Esfahbod 2006-02-17 08:47:39 UTC
Sorry, I was wrong.  logical_rect.x + logical_rect.width is not equal to get_width() for left-aligned text.  Closing this.