[pango/pango1-dwrite] PangoWin32: Support acquiring PangoFontDescription from DWrite fonts



commit b9fe3993dcf0b451b18104d031c2a064ce4839c1
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Aug 12 17:45:50 2022 +0800

    PangoWin32: Support acquiring PangoFontDescription from DWrite fonts
    
    This way, we save ourselves from an unnecessary roundtrip of
    IDWriteFont->logfontw->IDWriteFont, and makes things a bit clearer.

 pango/pangowin32-dwrite-fontmap.cpp | 34 +++++++++++++++++++++-------------
 pango/pangowin32-fontmap.c          |  2 +-
 pango/pangowin32-private.h          |  2 ++
 3 files changed, 24 insertions(+), 14 deletions(-)
---
diff --git a/pango/pangowin32-dwrite-fontmap.cpp b/pango/pangowin32-dwrite-fontmap.cpp
index 15253f94f..e87c8fe23 100644
--- a/pango/pangowin32-dwrite-fontmap.cpp
+++ b/pango/pangowin32-dwrite-fontmap.cpp
@@ -381,6 +381,26 @@ util_dwrite_get_font_variant_name (IDWriteFont *font)
   return util_free_to_string (strings);
 }
 
+PangoFontDescription *
+pango_win32_font_description_from_dwrite_font (const void *dwrite_font)
+{
+  PangoFontDescription *desc = NULL;
+  IDWriteFont *font = (IDWriteFont *)dwrite_font;
+  IDWriteFontFamily *family = NULL;
+
+  if (SUCCEEDED (font->GetFontFamily (&family)) && family != NULL)
+    {
+      char *family_name = util_dwrite_get_font_family_name (family);
+
+      if (family_name != NULL)
+        desc = util_get_pango_font_description (font, family_name);
+
+        family->Release ();
+    }
+
+  return desc;
+}
+
 PangoFontDescription *
 pango_win32_font_description_from_logfontw_dwrite (const LOGFONTW *logfontw)
 {
@@ -402,19 +422,7 @@ pango_win32_font_description_from_logfontw_dwrite (const LOGFONTW *logfontw)
 
   if (SUCCEEDED (hr) && font != NULL)
     {
-      IDWriteFontFamily *family = NULL;
-
-      hr = font->GetFontFamily (&family);
-
-      if (SUCCEEDED (hr) && family != NULL)
-        {
-          char *family_name = util_dwrite_get_font_family_name (family);
-
-          if (family_name != NULL)
-            desc = util_get_pango_font_description (font, family_name);
-
-          family->Release ();
-        }
+      desc = pango_win32_font_description_from_dwrite_font (font);
 
       font->Release ();
     }
diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c
index 836a3e465..ad17613dc 100644
--- a/pango/pangowin32-fontmap.c
+++ b/pango/pangowin32-fontmap.c
@@ -1708,7 +1708,7 @@ pango_win32_insert_font (PangoWin32FontMap *win32fontmap,
   g_hash_table_insert (win32fontmap->fonts, lfp2, lfp2);
   g_hash_table_insert (win32fontmap->dwrite_fonts, lfp2, dwrite_font);
 
-  description = pango_win32_font_description_from_logfontw (lfp2);
+  description = pango_win32_font_description_from_dwrite_font ((const void*) dwrite_font);
 
   /* In some cases, extracting a name for a font can fail; such fonts
    * aren't usable for us
diff --git a/pango/pangowin32-private.h b/pango/pangowin32-private.h
index db2eb5042..bbcc68b0b 100644
--- a/pango/pangowin32-private.h
+++ b/pango/pangowin32-private.h
@@ -304,6 +304,8 @@ PangoWin32DWriteItems *pango_win32_init_direct_write          (void);
 
 PangoWin32DWriteItems *pango_win32_get_direct_write_items     (void);
 
+PangoFontDescription  *pango_win32_font_description_from_dwrite_font (const void     *dwrite_font);
+
 void                   pango_win32_dwrite_font_map_populate   (PangoWin32FontMap     *map);
 
 void                   pango_win32_dwrite_items_destroy       (PangoWin32DWriteItems *items);


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