GNOME Bugzilla – Bug 329545
pango_layout_get_size is buggy
Last modified: 2006-02-17 08:47:39 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.
Sorry, I was wrong. logical_rect.x + logical_rect.width is not equal to get_width() for left-aligned text. Closing this.