[pango/pango1-dwrite: 3/10] pangowin32: Check for MonoSpace fonts using DirectWrite




commit 78a8bf14d19944922a616aae70f14e20b0f06972
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Jul 15 18:36:56 2022 +0800

    pangowin32: Check for MonoSpace fonts using DirectWrite
    
    ...if we have Windows 7 with the platform update (which is normally the
    case), otherwise we fallback to former GDI approach, since we need to
    use the IDWriteFont1 interface that is only available with updated
    Windows 7.

 pango/pangowin32-dwrite-fontmap.cpp | 25 ++++++++++++++++++++++++-
 pango/pangowin32-fontmap.c          |  8 ++++++--
 pango/pangowin32-private.h          |  3 +++
 3 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/pango/pangowin32-dwrite-fontmap.cpp b/pango/pangowin32-dwrite-fontmap.cpp
index 0a0278a98..dd2f506a0 100644
--- a/pango/pangowin32-dwrite-fontmap.cpp
+++ b/pango/pangowin32-dwrite-fontmap.cpp
@@ -23,7 +23,7 @@
 #include "config.h"
 
 #include <initguid.h>
-#include <dwrite.h>
+#include <dwrite_1.h>
 
 #ifdef STRICT
 #undef STRICT
@@ -32,8 +32,10 @@
 
 #ifdef _MSC_VER
 # define UUID_OF_IDWriteFactory __uuidof (IDWriteFactory)
+# define UUID_OF_IDWriteFont1 __uuidof (IDWriteFont1)
 #else
 # define UUID_OF_IDWriteFactory IID_IDWriteFactory
+# define UUID_OF_IDWriteFont1 IID_IDWriteFont1
 #endif
 
 struct _PangoWin32DWriteItems
@@ -181,6 +183,27 @@ pango_win32_logfontw_get_dwrite_font (LOGFONTW *logfontw)
   return font;
 }
 
+gboolean
+pango_win32_dwrite_font_is_monospace (gpointer  dwrite_font,
+                                      gboolean *is_monospace)
+{
+  IDWriteFont *font = static_cast<IDWriteFont *>(dwrite_font);
+  IDWriteFont1 *font1 = NULL;
+  gboolean result = FALSE;
+
+  if (SUCCEEDED (font->QueryInterface(UUID_OF_IDWriteFont1,
+                                      reinterpret_cast<void**>(&font1))))
+    {
+      *is_monospace = font1->IsMonospacedFont ();
+      font1->Release ();
+      result = TRUE;
+    }
+  else
+    *is_monospace = FALSE;
+
+  return result;
+}
+
 void
 pango_win32_dwrite_font_release (gpointer dwrite_font)
 {
diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c
index 9a1407026..3756c9293 100644
--- a/pango/pangowin32-fontmap.c
+++ b/pango/pangowin32-fontmap.c
@@ -1736,8 +1736,12 @@ pango_win32_insert_font (PangoWin32FontMap *win32fontmap,
   win32face->family = win32family =
     pango_win32_get_font_family (win32fontmap,
                                  pango_font_description_get_family (win32face->description));
-  if ((lfp->lfPitchAndFamily & 0xF0) == FF_MODERN)
-    win32family->is_monospace = TRUE;
+
+  if (!pango_win32_dwrite_font_is_monospace (dwrite_font, &win32family->is_monospace))
+    {
+      if ((lfp->lfPitchAndFamily & 0xF0) == FF_MODERN)
+        win32family->is_monospace = TRUE;
+    }
 
   win32family->faces = g_slist_append (win32family->faces, win32face);
 
diff --git a/pango/pangowin32-private.h b/pango/pangowin32-private.h
index 97bb6ba1d..1d843ec2d 100644
--- a/pango/pangowin32-private.h
+++ b/pango/pangowin32-private.h
@@ -302,6 +302,9 @@ void                   pango_win32_dwrite_font_map_populate   (PangoWin32FontMap
 
 void                   pango_win32_dwrite_items_destroy       (PangoWin32DWriteItems *items);
 
+gboolean               pango_win32_dwrite_font_is_monospace   (gpointer               dwrite_font,
+                                                               gboolean              *is_monospace);
+
 void                   pango_win32_dwrite_font_release        (gpointer               dwrite_font);
 
 gpointer               pango_win32_logfontw_get_dwrite_font   (LOGFONTW *logfontw);


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