[pango/matthiasc/for-main: 5/5] layout: Make sloped carets work better




commit 16b973b3f4f7201990da1857d92f63fe8a3cfbf7
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 2 18:50:45 2022 -0500

    layout: Make sloped carets work better
    
    When the font matrix has uneven scales, we need
    to factor that into the slope that we get from
    the font metrics.
    
    Tested with a condensed italic Cantarell.

 pango/pango-layout.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 24a1a88b..6349c9c7 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -88,6 +88,9 @@
 
 #include "pango-layout-private.h"
 #include "pango-attributes-private.h"
+#include "pango-font-private.h"
+#include "pango-hbface-private.h"
+#include "pango-hbfont-private.h"
 
 
 typedef struct _ItemProperties ItemProperties;
@@ -2716,6 +2719,7 @@ pango_layout_get_caret_pos (PangoLayout    *layout,
       hb_ot_metrics_get_position (hb_font, HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER, &descender))
     {
       double slope_inv;
+      int x_scale, y_scale;
 
       if (strong_pos)
         strong_pos->x += caret_offset;
@@ -2726,7 +2730,8 @@ pango_layout_get_caret_pos (PangoLayout    *layout,
       if (caret_rise == 0)
         return;
 
-      slope_inv = caret_run / (double) caret_rise;
+      hb_font_get_scale (hb_font, &x_scale, &y_scale);
+      slope_inv = (caret_run * y_scale) / (double) (caret_rise * x_scale);
 
       if (strong_pos)
         {


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