[pango/pango1-dwrite] pangocairo-win32font.c: Mark IDWriteFontFace for cleanup



commit 33052e28fd2653cdcc8d31ab67a7f84e1a10f6fe
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Tue Aug 16 13:04:58 2022 +0800

    pangocairo-win32font.c: Mark IDWriteFontFace for cleanup
    
    We should release the resources used by the IDWriteFontFace that we create to
    create the cairo_font_face_t when it is destroyed.  Also fallback to creating
    the cairo_font_face_t using the former GDI approach if the DirectWrite method
    failed, and clean up things as needed.

 pango/pangocairo-win32font.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/pango/pangocairo-win32font.c b/pango/pangocairo-win32font.c
index 523ac62e7..0141c4149 100644
--- a/pango/pangocairo-win32font.c
+++ b/pango/pangocairo-win32font.c
@@ -81,7 +81,25 @@ pango_cairo_win32_font_create_font_face (PangoCairoFont *font)
 #ifdef HAVE_CAIRO_WIN32_DIRECTWRITE
   dwrite_font_face = pango_win32_font_get_dwrite_font_face (win32font);
   if (dwrite_font_face != NULL)
-    return cairo_dwrite_font_face_create_for_dwrite_fontface (dwrite_font_face);
+    {
+      cairo_font_face_t *cairo_face = cairo_dwrite_font_face_create_for_dwrite_fontface (dwrite_font_face);
+
+      if (cairo_face != NULL)
+        {
+          static const cairo_user_data_key_t key;
+
+          cairo_font_face_set_user_data (cairo_face, &key,
+                                         dwrite_font_face,
+                                         (cairo_destroy_func_t) pango_win32_dwrite_font_face_release);
+
+          return cairo_face;
+        }
+      else
+        {
+          g_warning ("cairo_font_face creation failed with DirectWrite, fallback to GDI");
+          pango_win32_dwrite_font_face_release (dwrite_font_face);
+        }
+    }
 #endif
 
   return cairo_win32_font_face_create_for_logfontw (&win32font->logfontw);


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