diff options
author | Owen Taylor <otaylor@redhat.com> | 2000-07-02 21:31:19 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2000-07-02 21:31:19 +0000 |
commit | 6870ed61201c6c8545c59861a148647e39a3b7ed (patch) | |
tree | e4ffb25a9ca54888d625bc423ceb3507ec8c1993 /pango | |
parent | 5d69786601736595d1b6ac4fe141a8694fab011d (diff) | |
download | pango-6870ed61201c6c8545c59861a148647e39a3b7ed.tar.gz |
Add a PANGO_PIXELS macro to convert from pango units to device units and
Sun Jul 2 17:19:11 2000 Owen Taylor <otaylor@redhat.com>
* pango/pango-types.h: Add a PANGO_PIXELS macro to convert
from pango units to device units and round.
* pango/pango-layout.[ch]: Add convenience functions
pango_layout_get_pixel_extents, pango_layout_get_size,
pango_layout_get_pixel_size pango_layout_line_get_pixel_extents.
Diffstat (limited to 'pango')
-rw-r--r-- | pango/pango-layout.c | 136 | ||||
-rw-r--r-- | pango/pango-layout.h | 12 | ||||
-rw-r--r-- | pango/pango-types.h | 3 |
3 files changed, 150 insertions, 1 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c index a876c069..abcc7f5b 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -1274,7 +1274,7 @@ pango_layout_get_cursor_pos (PangoLayout *layout, * @logical_rect: rectangle used to store the logical extents of the glyph string * or %NULL to indicate that the result is not needed. * - * Compute the logical and ink extents of a layout line. See the documentation + * Compute the logical and ink extents of a layout. See the documentation * for pango_font_get_glyph_extents() for details about the interpretation * of the rectangles. */ @@ -1370,6 +1370,99 @@ pango_layout_get_extents (PangoLayout *layout, } } +/** + * pango_layout_get_pixel_extents: + * @layout: a #PangoLayout + * @ink_rect: rectangle used to store the extents of the glyph string as drawn + * or %NULL to indicate that the result is not needed. + * @logical_rect: rectangle used to store the logical extents of the glyph string + * or %NULL to indicate that the result is not needed. + * + * Compute the logical and ink extents of a layout. See the documentation + * for pango_font_get_glyph_extents() for details about the interpretation + * of the rectangles. The returned rectangles are in device units, as + * opposed to pango_layout_get_extents(), which returns the extents in + * units of device unit / PANGO_SCALE. + **/ +void +pango_layout_get_pixel_extents (PangoLayout *layout, + PangoRectangle *ink_rect, + PangoRectangle *logical_rect) +{ + g_return_if_fail (PANGO_IS_LAYOUT (layout)); + + pango_layout_get_extents (layout, ink_rect, logical_rect); + + 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; + + ink_rect->x = PANGO_PIXELS (ink_rect->x); + ink_rect->y = PANGO_PIXELS (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; + + logical_rect->x = PANGO_PIXELS (logical_rect->x); + logical_rect->y = PANGO_PIXELS (logical_rect->y); + } +} + +/** + * pango_layout_get_size: + * @layout: a #PangoLayout + * @width: location to store the logical width, or %NULL + * @height: location to store the logical height, or %NULL + * + * Determine the logical width and height of a #PangoLayout + * in Pango units. (device units divided by PANGO_SCALE). This + * is simply a convenience function around pango_layout_get_extents. + **/ +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; +} + +/** + * pango_layout_get_pixel_size: + * @layout: a #PangoLayout + * @width: location to store the logical width, or %NULL + * @height: location to store the logical height, or %NULL + * + * Determine 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. + **/ +void +pango_layout_get_pixel_size (PangoLayout *layout, + int *width, + int *height) +{ + PangoRectangle logical_rect; + + pango_layout_get_extents (layout, NULL, &logical_rect); + + if (width) + *width = (logical_rect.width + PANGO_SCALE / 2) / PANGO_SCALE; + if (height) + *height = (logical_rect.height + PANGO_SCALE / 2) / PANGO_SCALE; +} + static void pango_layout_clear_lines (PangoLayout *layout) { @@ -2337,6 +2430,47 @@ pango_layout_line_new (PangoLayout *layout) return (PangoLayoutLine *) private; } +/** + * pango_layout_line_get_pixel_extents: + * @layout: a #PangoLayout + * @ink_rect: rectangle used to store the extents of the glyph string as drawn + * or %NULL to indicate that the result is not needed. + * @logical_rect: rectangle used to store the logical extents of the glyph string + * or %NULL to indicate that the result is not needed. + * + * Compute the logical and ink extents of a layout line. See the documentation + * for pango_font_get_glyph_extents() for details about the interpretation + * of the rectangles. The returned rectangles are in device units, as + * opposed to pango_layout_line_get_extents(), which returns the extents in + * units of device unit / PANGO_SCALE. + **/ +void +pango_layout_line_get_pixel_extents (PangoLayoutLine *layout_line, + PangoRectangle *ink_rect, + PangoRectangle *logical_rect) +{ + g_return_if_fail (LINE_IS_VALID (layout_line)); + + pango_layout_line_get_extents (layout_line, ink_rect, logical_rect); + + 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; + + ink_rect->x = PANGO_PIXELS (ink_rect->x); + ink_rect->y = PANGO_PIXELS (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; + + logical_rect->x = PANGO_PIXELS (logical_rect->x); + logical_rect->y = PANGO_PIXELS (logical_rect->y); + } +} /* * NB: This implement the exact same algorithm as diff --git a/pango/pango-layout.h b/pango/pango-layout.h index 034794d9..516b867a 100644 --- a/pango/pango-layout.h +++ b/pango/pango-layout.h @@ -120,6 +120,15 @@ gboolean pango_layout_xy_to_index (PangoLayout *layout, void pango_layout_get_extents (PangoLayout *layout, PangoRectangle *ink_rect, PangoRectangle *logical_rect); +void pango_layout_get_pixel_extents (PangoLayout *layout, + PangoRectangle *ink_rect, + PangoRectangle *logical_rect); +void pango_layout_get_size (PangoLayout *layout, + int *width, + int *height); +void pango_layout_get_pixel_size (PangoLayout *layout, + int *width, + int *height); int pango_layout_get_line_count (PangoLayout *layout); PangoLayoutLine *pango_layout_get_line (PangoLayout *layout, @@ -144,6 +153,9 @@ void pango_layout_line_get_x_ranges (PangoLayoutLine *line, void pango_layout_line_get_extents (PangoLayoutLine *line, PangoRectangle *ink_rect, PangoRectangle *logical_rect); +void pango_layout_line_get_pixel_extents (PangoLayoutLine *layout_line, + PangoRectangle *ink_rect, + PangoRectangle *logical_rect); #ifdef __cplusplus } diff --git a/pango/pango-types.h b/pango/pango-types.h index cabdf232..91e21ba8 100644 --- a/pango/pango-types.h +++ b/pango/pango-types.h @@ -49,6 +49,9 @@ struct _PangoRectangle }; #define PANGO_SCALE 1024 +#define PANGO_PIXELS(d) (((d) >= 0) ? \ + ((d) + PANGO_SCALE / 2) / PANGO_SCALE : \ + ((d) - PANGO_SCALE / 2) / PANGO_SCALE) /* Macros to translate from extents rectangles to ascent/descent/lbearing/rbearing */ |