[pango/pango2-windows: 4/6] pangocairo-dwrite-font.cpp: Fix up cairo_font_face_t creation




commit b7e9016a9cf7df524e171e191a9354274d33c128
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Tue Jun 28 12:37:22 2022 +0800

    pangocairo-dwrite-font.cpp: Fix up cairo_font_face_t creation
    
    With the newly-added function to properly acquire the hb_blob_t from the
    underlying hb_font_t in our Pango2Font, we can now create a new proper
    hb_face_t from the hb_blob_t, where we can properly acquire the
    IDirectWriteFontFace and so use Cairo's DirectWrite APIs to create the
    cairo_font_face_t that we need.

 pango2/pangocairo-dwrite-font.cpp | 40 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)
---
diff --git a/pango2/pangocairo-dwrite-font.cpp b/pango2/pangocairo-dwrite-font.cpp
index f3cc477ec..50f0492d5 100644
--- a/pango2/pangocairo-dwrite-font.cpp
+++ b/pango2/pangocairo-dwrite-font.cpp
@@ -24,6 +24,7 @@
 #ifdef HAVE_DIRECT_WRITE
 
 #include "pangocairo-private.h"
+#include "pango-font-private.h"
 #include "pango-font.h"
 
 #include <windows.h>
@@ -35,13 +36,46 @@ cairo_font_face_t *
 create_cairo_dwrite_font_face (Pango2Font *font)
 {
   hb_font_t *hb_font;
+  hb_face_t *hb_face, *hb_face_new;
+  hb_blob_t *blob;
+  unsigned int idx;
   IDWriteFontFace *dwrite_font_face = NULL;
   cairo_font_face_t *result = NULL;
 
   hb_font = pango2_font_get_hb_font (font);
-  dwrite_font_face = hb_directwrite_face_get_font_face (hb_font_get_face (hb_font));
-  if (dwrite_font_face)
-    result = cairo_dwrite_font_face_create_for_dwrite_fontface (dwrite_font_face);
+  hb_face = hb_font_get_face (hb_font);
+  idx = hb_face_get_index (hb_face);
+  blob = pango2_font_get_hb_blob (font);
+
+  hb_face_new = hb_face_create (blob, idx);
+
+  if (hb_face_new != hb_face_get_empty ())
+    {
+      dwrite_font_face = hb_directwrite_face_get_font_face (hb_face_new);
+
+      if (dwrite_font_face)
+        result = cairo_dwrite_font_face_create_for_dwrite_fontface (dwrite_font_face);
+    }
+
+  if (result != NULL)
+    {
+      static cairo_user_data_key_t key;
+      static cairo_user_data_key_t key2;
+
+      cairo_font_face_set_user_data (result, &key,
+                                     hb_face_new,
+                                     (cairo_destroy_func_t) hb_face_destroy);
+      cairo_font_face_set_user_data (result, &key2,
+                                     blob,
+                                     (cairo_destroy_func_t) hb_blob_destroy);
+    }
+  else
+    {
+      if (hb_face_new != hb_face_get_empty ())
+        hb_face_destroy (hb_face_new);
+
+      hb_blob_destroy (blob);
+    }
 
   return result;
 }


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