[pango/line-height-attribute: 3/3] layout: Handle the line-height attribute




commit d445aad2587bea562b35a68a0ce5d610fce92ac4
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 7 10:39:32 2021 -0400

    layout: Handle the line-height attribute
    
    Scale logical extents according to the line-height
    attribute.

 pango/pango-layout.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index cd455210..8661e741 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -68,6 +68,7 @@
 #include "pango-impl-utils.h"
 #include "pango-glyph-item.h"
 #include <string.h>
+#include <math.h>
 
 #include "pango-layout-private.h"
 #include "pango-attributes-private.h"
@@ -97,6 +98,7 @@ struct _ItemProperties
   gboolean        shape_set;
   PangoRectangle *shape_ink_rect;
   PangoRectangle *shape_logical_rect;
+  double line_height;
 };
 
 typedef struct _PangoLayoutLinePrivate PangoLayoutLinePrivate;
@@ -4188,6 +4190,7 @@ affects_itemization (PangoAttribute *attr,
     case PANGO_ATTR_LETTER_SPACING:
     case PANGO_ATTR_SHAPE:
     case PANGO_ATTR_RISE:
+    case PANGO_ATTR_LINE_HEIGHT:
       return TRUE;
     default:
       return FALSE;
@@ -5143,7 +5146,16 @@ pango_layout_run_get_extents_and_height (PangoLayoutRun *run,
       if (!metrics)
         metrics = pango_font_get_metrics (run->item->analysis.font,
                                           run->item->analysis.language);
-      *height = pango_font_metrics_get_height (metrics);
+    }
+
+  if (properties.line_height != 0.0)
+    {
+      int leading = ceilf (properties.line_height * run_logical->height - run_logical->height);
+      run_logical->y -= leading / 2;
+      run_logical->height += leading;
+
+      if (height)
+        *height = properties.line_height * pango_font_metrics_get_height (metrics);
     }
 
   if (run->item->analysis.flags & PANGO_ANALYSIS_FLAG_CENTERED_BASELINE)
@@ -6019,6 +6031,7 @@ pango_layout_get_item_properties (PangoItem      *item,
   properties->shape_set = FALSE;
   properties->shape_ink_rect = NULL;
   properties->shape_logical_rect = NULL;
+  properties->line_height = 0.0;
 
   while (tmp_list)
     {
@@ -6082,6 +6095,10 @@ pango_layout_get_item_properties (PangoItem      *item,
           properties->shape_ink_rect = &((PangoAttrShape *)attr)->ink_rect;
           break;
 
+        case PANGO_ATTR_LINE_HEIGHT:
+          properties->line_height = ((PangoAttrFloat *)attr)->value;
+          break;
+
         default:
           break;
         }


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