[pango/pango1-dwrite] pangowin32: Implement get_scaled_factors



commit 8b2e0c862e576f34a6b5c83c3d0136139528725d
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Tue Jul 12 14:52:39 2022 +0800

    pangowin32: Implement get_scaled_factors
    
    Use the GDI features to grab the world transform so that we can use it to get
    the scaled factors that we need.

 pango/pangowin32.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
---
diff --git a/pango/pangowin32.c b/pango/pangowin32.c
index 003bd1015..007a246e2 100644
--- a/pango/pangowin32.c
+++ b/pango/pangowin32.c
@@ -57,6 +57,9 @@ static gboolean pango_win32_font_real_select_font      (PangoFont *font,
 static void     pango_win32_font_real_done_font        (PangoFont *font);
 static double   pango_win32_font_real_get_metrics_factor (PangoFont *font);
 static gboolean pango_win32_font_is_hinted             (PangoFont *font);
+static void     pango_win32_font_get_scale_factors     (PangoFont *font,
+                                                        double    *x_scale,
+                                                        double    *y_scale);
 
 static void                  pango_win32_get_item_properties    (PangoItem        *item,
                                                                 PangoUnderline   *uline,
@@ -207,6 +210,7 @@ _pango_win32_font_class_init (PangoWin32FontClass *class)
 
   pclass = g_type_class_get_private ((GTypeClass *) class, PANGO_TYPE_FONT);
   pclass->is_hinted = pango_win32_font_is_hinted;
+  pclass->get_scale_factors = pango_win32_font_get_scale_factors;
 
   _pango_win32_get_display_dc ();
 }
@@ -717,6 +721,53 @@ pango_win32_font_is_hinted (PangoFont *font)
   return PANGO_WIN32_FONT (font)->is_hinted;
 }
 
+static void
+pango_win32_font_get_scale_factors (PangoFont *font,
+                                    double    *x_scale,
+                                    double    *y_scale)
+{
+  PangoWin32Font *win32font;
+  XFORM xForm;
+  HDC hdc = _pango_win32_get_display_dc ();
+  int mode = 0;
+  HFONT hfont, old_hfont;
+
+  hfont = _pango_win32_font_get_hfont (font);
+  if (hfont == NULL)
+    return;
+
+  if ((old_hfont = SelectObject (hdc, hfont)) != NULL)
+    {
+      mode = SetGraphicsMode (hdc, GM_ADVANCED);
+
+      if (mode == 0)
+        g_warning ("SetGraphicsMode() failed");
+      else if (!GetWorldTransform (hdc, &xForm))
+        g_warning ("GetWorldTransform() failed");
+      else
+        {
+          PangoMatrix matrix;
+
+          matrix.xx = xForm.eM11;
+          matrix.yx = xForm.eM12;
+          matrix.xy = xForm.eM21;
+          matrix.yy = xForm.eM22;
+          matrix.x0 = xForm.eDx;
+          matrix.y0 = xForm.eDy;
+
+          pango_matrix_get_font_scale_factors (&matrix, x_scale, y_scale);
+        }
+    }
+  else
+    g_warning ("SelectObject() failed");
+
+  if (mode != 0)
+    SetGraphicsMode (hdc, mode);
+
+  if (old_hfont != NULL)
+    SelectObject (hdc, old_hfont);
+}
+
 /**
  * pango_win32_font_logfont:
  * @font: a `PangoFont` which must be from the Win32 backend


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