[pango/pango2] Add pango2_lines_get_trimmed_extents



commit 2b65fe9b27c1844373a1e70c65200f3fb2211435
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jul 3 11:11:05 2022 -0400

    Add pango2_lines_get_trimmed_extents
    
    This was missing

 pango2/pango-lines.c | 45 ++++++++++++++++++++++++++++++++++++---------
 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 3c46e2e42..a532cd4f2 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;
@@ -568,6 +570,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`
diff --git a/pango2/pango-lines.h b/pango2/pango-lines.h
index f2a89f437..497a40502 100644
--- a/pango2/pango-lines.h
+++ b/pango2/pango-lines.h
@@ -64,6 +64,13 @@ void                    pango2_lines_get_extents     (Pango2Lines        *lines,
                                                       Pango2Rectangle    *ink_rect,
                                                       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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]