[gnome-font-viewer] font-widget: fix support for scale factor



commit 9af2f35a63f34f87407e784b514cafe1cc772384
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Nov 21 14:33:27 2015 -0800

    font-widget: fix support for scale factor
    
    We need to take this into account when advanncing the position of the
    glyphs to render the sample strings.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742428

 src/sushi-font-widget.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/src/sushi-font-widget.c b/src/sushi-font-widget.c
index 3709db5..59313a8 100644
--- a/src/sushi-font-widget.c
+++ b/src/sushi-font-widget.c
@@ -86,6 +86,7 @@ text_to_glyphs (cairo_t *cr,
   hb_font_t *hb_font;
   gdouble x = 0, y = 0;
   gint i;
+  gdouble x_scale, y_scale;
 
   *num_glyphs = 0;
   *glyphs = NULL;
@@ -96,6 +97,9 @@ text_to_glyphs (cairo_t *cr,
   ft_face = cairo_ft_scaled_font_lock_face (cr_font);
   hb_font = hb_ft_font_create (ft_face, NULL);
 
+  cairo_surface_t *target = cairo_get_target (cr);
+  cairo_surface_get_device_scale (target, &x_scale, &y_scale);
+
   /* We abuse pango itemazation to split text into script and direction
    * runs, since we use our fonts directly no through pango, we don't
    * bother changing the default font, but we disable font fallback as
@@ -140,10 +144,10 @@ text_to_glyphs (cairo_t *cr,
 
     for (i = 0; i < n; i++) {
       (*glyphs)[*num_glyphs + i].index = hb_glyphs[i].codepoint;
-      (*glyphs)[*num_glyphs + i].x = x + (hb_positions[i].x_offset / 64.);
-      (*glyphs)[*num_glyphs + i].y = y - (hb_positions[i].y_offset / 64.);
-      x += (hb_positions[i].x_advance / 64.);
-      y -= (hb_positions[i].y_advance / 64.);
+      (*glyphs)[*num_glyphs + i].x = x + (hb_positions[i].x_offset / (64. * x_scale));
+      (*glyphs)[*num_glyphs + i].y = y - (hb_positions[i].y_offset / (64. * y_scale));
+      x += (hb_positions[i].x_advance / (64. * x_scale));
+      y -= (hb_positions[i].y_advance / (64. * y_scale));
     }
 
     *num_glyphs += n;


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