diff options
author | Chun-wei Fan <fanchunwei@src.gnome.org> | 2022-07-15 18:36:56 +0800 |
---|---|---|
committer | Chun-wei Fan <fanchunwei@src.gnome.org> | 2022-09-26 11:04:25 +0800 |
commit | 43f3d8b3c22a02b83a3221bd7a0de52a88524c07 (patch) | |
tree | c15a98a617bf033e2e008268e23a72d948d99406 | |
parent | 5bc16f7896ba3eb5b37ffdb03f28c646aad5889e (diff) | |
download | pango-43f3d8b3c22a02b83a3221bd7a0de52a88524c07.tar.gz |
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.
-rw-r--r-- | pango/pangowin32-dwrite-fontmap.cpp | 25 | ||||
-rw-r--r-- | pango/pangowin32-fontmap.c | 8 | ||||
-rw-r--r-- | 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 0a0278a9..dd2f506a 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 9a140702..3756c929 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 97bb6ba1..1d843ec2 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); |