diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2006-04-29 19:41:23 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2006-04-29 19:41:23 +0000 |
commit | dd69229f4e5bea613aec846d9964edc7d2683825 (patch) | |
tree | 96e68e3f2770bb47cc68669d8eb352845a7403ac /pango | |
parent | 58493b0080dc8d91e09b8b9ec05f910388730047 (diff) | |
download | pango-dd69229f4e5bea613aec846d9964edc7d2683825.tar.gz |
Bug 329547 – pango_layout_get_pixel_extents and
2006-04-29 Behdad Esfahbod <behdad@gnome.org>
Bug 329547 – pango_layout_get_pixel_extents and
pango_layout_get_pixel_size cause off-by-one metrics
* docs/pango-sections.txt:
* docs/tmpl/glyphs.sgml:
* pango/pango-types.h: Define PANGO_PIXELS_FLOOR and
* PANGO_PIXELS_CEIL.
* pango/pango-layout.c (pango_layout_get_pixel_extents),
(pango_layout_get_pixel_size): Make sure logical rects are
consistent and ink rects are inclusive.
Diffstat (limited to 'pango')
-rw-r--r-- | pango/fonts.c | 10 | ||||
-rw-r--r-- | pango/pango-attributes.c | 4 | ||||
-rw-r--r-- | pango/pango-layout.c | 33 | ||||
-rw-r--r-- | pango/pango-types.h | 10 |
4 files changed, 33 insertions, 24 deletions
diff --git a/pango/fonts.c b/pango/fonts.c index 69c3fef1..59da712a 100644 --- a/pango/fonts.c +++ b/pango/fonts.c @@ -378,7 +378,7 @@ pango_font_description_get_size (const PangoFontDescription *desc) /** * pango_font_description_set_absolute_size: * @desc: a #PangoFontDescription - * @size: the new size, in Pango units. There are #PANGO_SCALE Pango units in one + * @size: the new size, in Pango units. There are %PANGO_SCALE Pango units in one * device unit. For an output backend where a device unit is a pixel, a @size * value of 10 * PANGO_SCALE gives a 10 pixel font. * @@ -1341,7 +1341,7 @@ pango_font_metrics_unref (PangoFontMetrics *metrics) * actual drawn ink. It is necessary to lay out the text to figure * where the ink will be.) * - * Return value: the ascent, in Pango units. (1 point == #PANGO_SCALE Pango units.) + * Return value: the ascent, in Pango units. (1 point == %PANGO_SCALE Pango units.) **/ int pango_font_metrics_get_ascent (PangoFontMetrics *metrics) @@ -1361,7 +1361,7 @@ pango_font_metrics_get_ascent (PangoFontMetrics *metrics) * actual drawn ink. It is necessary to lay out the text to figure * where the ink will be.) * - * Return value: the descent, in Pango units. (1 point == #PANGO_SCALE Pango units.) + * Return value: the descent, in Pango units. (1 point == %PANGO_SCALE Pango units.) **/ int pango_font_metrics_get_descent (PangoFontMetrics *metrics) @@ -1380,7 +1380,7 @@ pango_font_metrics_get_descent (PangoFontMetrics *metrics) * determining the initial size for a window. Actual characters in * text will be wider and narrower than this. * - * Return value: the character width, in Pango units. (1 point == #PANGO_SCALE Pango units.) + * Return value: the character width, in Pango units. (1 point == %PANGO_SCALE Pango units.) **/ int pango_font_metrics_get_approximate_char_width (PangoFontMetrics *metrics) @@ -1401,7 +1401,7 @@ pango_font_metrics_get_approximate_char_width (PangoFontMetrics *metrics) * is generally somewhat more accurate than the result of * pango_font_metrics_get_approximate_char_width() for digits. * - * Return value: the digit width, in Pango units. (1 point == #PANGO_SCALE Pango units.) + * Return value: the digit width, in Pango units. (1 point == %PANGO_SCALE Pango units.) **/ int pango_font_metrics_get_approximate_digit_width (PangoFontMetrics *metrics) diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index 08353219..ea7c268b 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -472,7 +472,7 @@ pango_attr_size_new_internal (int size, /** * pango_attr_size_new: - * @size: the font size, in #PANGO_SCALE<!-- -->ths of a point. + * @size: the font size, in %PANGO_SCALE<!-- -->ths of a point. * * Create a new font-size attribute in fractional points. * @@ -487,7 +487,7 @@ pango_attr_size_new (int size) /** * pango_attr_size_new_absolute: - * @size: the font size, in #PANGO_SCALE<!-- -->ths of a device unit. + * @size: the font size, in %PANGO_SCALE<!-- -->ths of a device unit. * * Create a new font-size attribute in device units. * diff --git a/pango/pango-layout.c b/pango/pango-layout.c index d321177a..7b4b5c4e 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -1275,7 +1275,7 @@ pango_layout_index_to_line_and_extents (PangoLayout *layout, * @line: location to store resulting line index. (which will * between 0 and pango_layout_get_line_count(layout) - 1) * @x_pos: location to store resulting position within line - * (in thousandths of a device unit) + * (%PANGO_SCALE units per device unit) * * Converts from byte @index_ within the @layout to line and X position. * (X position is measured from the left edge of the line) @@ -2261,20 +2261,26 @@ pango_layout_get_pixel_extents (PangoLayout *layout, if (ink_rect) { - ink_rect->width = (ink_rect->width + PANGO_SCALE / 2) / PANGO_SCALE; - ink_rect->height = (ink_rect->height + PANGO_SCALE / 2) / PANGO_SCALE; + int orig_x = ink_rect->x; + int orig_y = ink_rect->y; - ink_rect->x = PANGO_PIXELS (ink_rect->x); - ink_rect->y = PANGO_PIXELS (ink_rect->y); + ink_rect->x = PANGO_PIXELS_FLOOR (ink_rect->x); + ink_rect->y = PANGO_PIXELS_FLOOR (ink_rect->y); + + ink_rect->width = PANGO_PIXELS_CEIL (orig_x + ink_rect->width ) - ink_rect->x; + ink_rect->height = PANGO_PIXELS_CEIL (orig_y + ink_rect->height) - ink_rect->y; } if (logical_rect) { - logical_rect->width = (logical_rect->width + PANGO_SCALE / 2) / PANGO_SCALE; - logical_rect->height = (logical_rect->height + PANGO_SCALE / 2) / PANGO_SCALE; + int orig_x = logical_rect->x; + int orig_y = logical_rect->y; logical_rect->x = PANGO_PIXELS (logical_rect->x); logical_rect->y = PANGO_PIXELS (logical_rect->y); + + logical_rect->width = PANGO_PIXELS (orig_x + logical_rect->width ) - logical_rect->x; + logical_rect->height = PANGO_PIXELS (orig_y + logical_rect->height) - logical_rect->y; } } @@ -2285,7 +2291,7 @@ pango_layout_get_pixel_extents (PangoLayout *layout, * @height: location to store the logical height, or %NULL * * Determines the logical width and height of a #PangoLayout - * in Pango units. (device units divided by %PANGO_SCALE). This + * in Pango units. (device units scaled by %PANGO_SCALE). This * is simply a convenience function around pango_layout_get_extents(). **/ void @@ -2311,8 +2317,9 @@ pango_layout_get_size (PangoLayout *layout, * * Determines the logical width and height of a #PangoLayout * in device units. (pango_layout_get_size() returns the width - * and height in thousandths of a device unit.) This - * is simply a convenience function around pango_layout_get_extents(). + * and height scaled by %PANGO_SCALE.) This + * is simply a convenience function around + * pango_layout_get_pixel_extents(). **/ void pango_layout_get_pixel_size (PangoLayout *layout, @@ -2321,12 +2328,12 @@ pango_layout_get_pixel_size (PangoLayout *layout, { PangoRectangle logical_rect; - pango_layout_get_extents (layout, NULL, &logical_rect); + pango_layout_get_pixel_extents (layout, NULL, &logical_rect); if (width) - *width = (logical_rect.width + PANGO_SCALE / 2) / PANGO_SCALE; + *width = logical_rect.width; if (height) - *height = (logical_rect.height + PANGO_SCALE / 2) / PANGO_SCALE; + *height = logical_rect.height; } static void diff --git a/pango/pango-types.h b/pango/pango-types.h index 6a198a60..980658a3 100644 --- a/pango/pango-types.h +++ b/pango/pango-types.h @@ -127,10 +127,12 @@ double pango_matrix_get_font_scale_factor (const PangoMatrix *matrix); #define PANGO_SCALE 1024 #define PANGO_PIXELS(d) (((int)(d) + 512) >> 10) -/* The above expression is just slightly wrong for floating point d; - * We'd expect -512.5 => -1 but instead we get 0. That's unlikely - * to matter for practical use and the expression is much more - * compact and faster than alternatives that work exactly for both +#define PANGO_PIXELS_FLOOR(d) (((int)(d)) >> 10) +#define PANGO_PIXELS_CEIL(d) (((int)(d) + 1023) >> 10) +/* The above expressions are just slightly wrong for floating point d; + * For example we'd expect PANGO_PIXELS(-512.5) => -1 but instead we get 0. + * That's unlikely to matter for practical use and the expression is much + * more compact and faster than alternatives that work exactly for both * integers and floating point. */ |