[pango/pango1-dwrite: 3/3] DWrite WIP...




commit 9f7d1d8fd1b86d053f52a3d18a48710d35092336
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Thu Jul 7 12:36:26 2022 +0800

    DWrite WIP...

 pango/pangowin32-dwrite-fontmap.cpp | 14 ++++++++++++++
 pango/pangowin32-fontmap.c          | 11 +++++++----
 pango/pangowin32-private.h          |  7 +++++++
 3 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/pango/pangowin32-dwrite-fontmap.cpp b/pango/pangowin32-dwrite-fontmap.cpp
index b2e690c25..ddddc8338 100644
--- a/pango/pangowin32-dwrite-fontmap.cpp
+++ b/pango/pangowin32-dwrite-fontmap.cpp
@@ -93,6 +93,15 @@ pango_win32_dwrite_font_map_destroy (PangoWin32FontMap *map)
   g_free (dwrite_items);
 }
 
+void
+pango_win32_dwrite_font_release (gpointer dwrite_font)
+{
+  IDWriteFont *font = static_cast<IDWriteFont *>(dwrite_font);
+
+  if (font != NULL)
+    font->Release ();
+}
+
 #else
 /* no-op's, no DirectWrite support */
 void
@@ -104,4 +113,9 @@ void
 pango_win32_dwrite_font_map_destroy (PangoWin32FontMap *map)
 {
 }
+
+void
+pango_win32_dwrite_font_release (gpointer dwrite_font)
+{
+}
 #endif
\ No newline at end of file
diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c
index e6b64eb0d..4e95c61e9 100644
--- a/pango/pangowin32-fontmap.c
+++ b/pango/pangowin32-fontmap.c
@@ -705,7 +705,7 @@ _pango_win32_font_map_init (PangoWin32FontMap *win32fontmap)
 {
   LOGFONTW logfont;
   HDC hdc = _pango_win32_get_display_dc ();
-  struct EnumProcData enum_proc_data;
+  struct EnumProcData enum_proc_data = {hdc, win32fontmap};
   pango_win32_dwrite_font_map_init (win32fontmap);
 
   win32fontmap->families =
@@ -714,6 +714,11 @@ _pango_win32_font_map_init (PangoWin32FontMap *win32fontmap)
   win32fontmap->fonts =
     g_hash_table_new_full ((GHashFunc) logfontw_nosize_hash,
                            (GEqualFunc) logfontw_nosize_equal, NULL, g_free);
+  win32fontmap->dwrite_fonts =
+    g_hash_table_new_full ((GHashFunc) logfontw_nosize_hash,
+                           (GEqualFunc) logfontw_nosize_equal,
+                           NULL,
+                           pango_win32_dwrite_font_release);
 
   win32fontmap->font_cache = pango_win32_font_cache_new ();
   win32fontmap->freed_fonts = g_queue_new ();
@@ -725,9 +730,6 @@ _pango_win32_font_map_init (PangoWin32FontMap *win32fontmap)
   memset (&logfont, 0, sizeof (logfont));
   logfont.lfCharSet = DEFAULT_CHARSET;
 
-  enum_proc_data.hdc = hdc;
-  enum_proc_data.font_map = win32fontmap;
-
   EnumFontFamiliesExW (hdc, &logfont,
                        (FONTENUMPROCW) pango_win32_enum_proc,
                        (LPARAM) &enum_proc_data, 0);
@@ -866,6 +868,7 @@ pango_win32_font_map_finalize (GObject *object)
 
   pango_win32_font_cache_free (win32fontmap->font_cache);
 
+  g_hash_table_destroy (win32fontmap->dwrite_fonts);
   g_hash_table_destroy (win32fontmap->warned_fonts);
   g_hash_table_destroy (win32fontmap->fonts);
   g_hash_table_destroy (win32fontmap->families);
diff --git a/pango/pangowin32-private.h b/pango/pangowin32-private.h
index db7d73a3c..43ae65da8 100644
--- a/pango/pangowin32-private.h
+++ b/pango/pangowin32-private.h
@@ -109,6 +109,11 @@ struct _PangoWin32FontMap
 
   /* keep track of DirectWrite boiler plate items */
   PangoWin32DWriteItems *dwrite_items;
+
+  /* Map LOGFONTWs to IDWriteFonts corresponding to actual fonts
+   * installed, if applicable.
+   */
+  GHashTable *dwrite_fonts;
 };
 
 struct _PangoWin32FontMapClass
@@ -291,6 +296,8 @@ void            pango_win32_dwrite_font_map_init    (PangoWin32FontMap *map);
 
 void            pango_win32_dwrite_font_map_destroy (PangoWin32FontMap *map);
 
+void            pango_win32_dwrite_font_release (gpointer dwrite_font);
+
 G_END_DECLS
 
 #endif /* __PANGOWIN32_PRIVATE_H__ */


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