[pango/baseline-handling: 2/2] layout: Handle baselines




commit b480ee7af505f4bba792d1308528b1bd226af15b
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Feb 14 18:41:29 2022 -0600

    layout: Handle baselines
    
    During post-processing for lines, take into
    account the baselines for each run, and shift
    them vertically to align them on the dominant
    baseline.

 pango/pango-layout.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 9167883c..9870807e 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -85,6 +85,7 @@
 #include <locale.h>
 
 #include <hb-ot.h>
+#include <hb-glib.h>
 
 #include "pango-layout-private.h"
 #include "pango-attributes-private.h"
@@ -6694,6 +6695,11 @@ apply_baseline_shift (PangoLayoutLine *line,
 {
   int y_offset = 0;
   PangoItem *prev = NULL;
+  hb_ot_layout_baseline_tag_t dominant_baseline = 0;
+  hb_script_t script;
+  hb_position_t baseline;
+  hb_position_t run_baseline;
+  hb_position_t baseline_adjustment;
 
   for (GSList *l = line->runs; l; l = l->next)
     {
@@ -6701,16 +6707,41 @@ apply_baseline_shift (PangoLayoutLine *line,
       PangoItem *item = run->item;
       int start_x_offset, end_x_offset;
       int start_y_offset, end_y_offset;
+      hb_font_t *hb_font;
+
+      hb_font = pango_font_get_hb_font (item->analysis.font);
+
+      if (dominant_baseline == 0)
+        {
+          script = hb_glib_script_to_script (item->analysis.script);
+          dominant_baseline = hb_ot_layout_get_baseline_tag_for_script (script);
+          hb_ot_layout_get_baseline_with_fallback (hb_font,
+                                                   dominant_baseline,
+                                                   HB_DIRECTION_LTR, /* FIXME */
+                                                   script,
+                                                   HB_TAG_NONE, /* FIXME */
+                                                   &baseline);
+        }
+
+      script = hb_glib_script_to_script (item->analysis.script);
+      hb_ot_layout_get_baseline_with_fallback (hb_font,
+                                               dominant_baseline,
+                                               HB_DIRECTION_LTR, /* FIXME */
+                                               script,
+                                               HB_TAG_NONE, /* FIXME */
+                                               &run_baseline);
 
       collect_baseline_shift (state, item, prev, &start_x_offset, &start_y_offset, &end_x_offset, 
&end_y_offset);
 
-      y_offset += start_y_offset;
+      baseline_adjustment = baseline - run_baseline;
+
+      y_offset += start_y_offset + baseline_adjustment;
 
       run->y_offset = y_offset;
       run->start_x_offset = start_x_offset;
       run->end_x_offset = end_x_offset;
 
-      y_offset += end_y_offset;
+      y_offset += end_y_offset - baseline_adjustment;
 
       prev = item;
     }


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