diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-07-03 11:11:05 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-07-04 11:24:16 -0400 |
commit | 9954891c66a241338cc48d2c2236b12dd2368572 (patch) | |
tree | c0c752abe8c5286173762d0d76bbc1e033dcbf7c | |
parent | e87e5ce9505a996528c632ac082f84601f53a8a1 (diff) | |
download | pango-9954891c66a241338cc48d2c2236b12dd2368572.tar.gz |
Add pango2_lines_get_trimmed_extents
This was missing
-rw-r--r-- | pango2/pango-lines.c | 45 | ||||
-rw-r--r-- | pango2/pango-lines.h | 7 |
2 files changed, 43 insertions, 9 deletions
diff --git a/pango2/pango-lines.c b/pango2/pango-lines.c index 3c46e2e4..a532cd4f 100644 --- a/pango2/pango-lines.c +++ b/pango2/pango-lines.c @@ -491,12 +491,13 @@ pango2_lines_is_hyphenated (Pango2Lines *lines) /* {{{ Extents */ /** - * pango2_lines_get_extents: + * pango2_lines_get_trimmd_extents: * @lines: a `Pango2Lines` object + * @trim: `Pango2LeadingTrim` flags * @ink_rect: (out) (optional): return location for the ink extents * @logical_rect: (out) (optional): return location for the logical extents * - * Computes the extents of the lines. + * Computes the extents of the lines, trimmed according to `trim`. * * Logical extents are usually what you want for positioning things. Note * that the extents may have non-zero x and y. You may want to use those @@ -508,9 +509,10 @@ pango2_lines_is_hyphenated (Pango2Lines *lines) * coordinates begin at the top left corner. */ void -pango2_lines_get_extents (Pango2Lines *lines, - Pango2Rectangle *ink_rect, - Pango2Rectangle *logical_rect) +pango2_lines_get_trimmed_extents (Pango2Lines *lines, + Pango2LeadingTrim trim, + Pango2Rectangle *ink_rect, + Pango2Rectangle *logical_rect) { for (int i = 0; i < lines->lines->len; i++) { @@ -518,15 +520,15 @@ pango2_lines_get_extents (Pango2Lines *lines, Position *pos = &g_array_index (lines->positions, Position, i); Pango2Rectangle line_ink; Pango2Rectangle line_logical; - Pango2LeadingTrim trim = PANGO2_LEADING_TRIM_NONE; + Pango2LeadingTrim line_trim = PANGO2_LEADING_TRIM_NONE; if (line->starts_paragraph) - trim |= PANGO2_LEADING_TRIM_START; + line_trim |= PANGO2_LEADING_TRIM_START; if (line->ends_paragraph) - trim |= PANGO2_LEADING_TRIM_END; + line_trim |= PANGO2_LEADING_TRIM_END; pango2_line_get_extents (line, &line_ink, NULL); - pango2_line_get_trimmed_extents (line, trim, &line_logical); + pango2_line_get_trimmed_extents (line, trim & line_trim, &line_logical); line_ink.x += pos->x; line_ink.y += pos->y; @@ -569,6 +571,31 @@ pango2_lines_get_extents (Pango2Lines *lines, } /** + * pango2_lines_get_extents: + * @lines: a `Pango2Lines` object + * @ink_rect: (out) (optional): return location for the ink extents + * @logical_rect: (out) (optional): return location for the logical extents + * + * Computes the extents of the lines. + * + * Logical extents are usually what you want for positioning things. Note + * that the extents may have non-zero x and y. You may want to use those + * to offset where you render the layout. Not doing that is a very typical + * bug that shows up as right-to-left layouts not being correctly positioned + * in a layout with a set width. + * + * The extents are given in layout coordinates and in Pango units; layout + * coordinates begin at the top left corner. + */ +void +pango2_lines_get_extents (Pango2Lines *lines, + Pango2Rectangle *ink_rect, + Pango2Rectangle *logical_rect) +{ + pango2_lines_get_trimmed_extents (lines, PANGO2_LEADING_TRIM_NONE, ink_rect, logical_rect); +} + +/** * pango2_lines_get_size: * @lines: a `Pango2Lines` * @width: (out) (optional): location to store the logical width diff --git a/pango2/pango-lines.h b/pango2/pango-lines.h index f2a89f43..497a4050 100644 --- a/pango2/pango-lines.h +++ b/pango2/pango-lines.h @@ -65,6 +65,13 @@ void pango2_lines_get_extents (Pango2Lines *lines, Pango2Rectangle *logical_rect); PANGO2_AVAILABLE_IN_ALL +void pango2_lines_get_trimmed_extents + (Pango2Lines *lines, + Pango2LeadingTrim trim, + Pango2Rectangle *ink_rect, + Pango2Rectangle *logical_rect); + +PANGO2_AVAILABLE_IN_ALL void pango2_lines_get_size (Pango2Lines *lines, int *width, int *height); |