[pango/pango1-dwrite: 4/5] PangoWin32: Add private API for getting IDWriteFontFace from font




commit c3e3c9cc4727ca70863123407f025b739a21f4b7
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Aug 15 17:32:57 2022 +0800

    PangoWin32: Add private API for getting IDWriteFontFace from font
    
    This moves some items under PangoWin32 in the DirectWrite support to
    simplify acquiring the DirectWrite font face that is needed for various
    operations, as we will need to do this in PangoCairo in the Windows
    support.

 pango/pangowin32-dwrite-fontmap.cpp | 54 +++++++++++++++++++++++++++++++------
 pango/pangowin32-private.h          |  3 +++
 2 files changed, 49 insertions(+), 8 deletions(-)
---
diff --git a/pango/pangowin32-dwrite-fontmap.cpp b/pango/pangowin32-dwrite-fontmap.cpp
index 15253f94f..62f2d6362 100644
--- a/pango/pangowin32-dwrite-fontmap.cpp
+++ b/pango/pangowin32-dwrite-fontmap.cpp
@@ -89,6 +89,38 @@ pango_win32_dwrite_items_destroy (PangoWin32DWriteItems *dwrite_items)
   g_free (dwrite_items);
 }
 
+static IDWriteFontFace *
+_pango_win32_get_dwrite_font_face_from_dwrite_font (IDWriteFont *font)
+{
+  IDWriteFontFace *face = NULL;
+  HRESULT hr;
+
+  g_return_val_if_fail (font != NULL, NULL);
+
+  hr = font->CreateFontFace (&face);
+  if (SUCCEEDED (hr) && face != NULL)
+    return face;
+
+  g_warning ("IDWriteFont::CreateFontFace failed with error code %x\n", (unsigned)hr);
+  return NULL;
+}
+
+void *
+pango_win32_font_get_dwrite_font_face (PangoWin32Font *font)
+{
+  PangoWin32Font *win32font = PANGO_WIN32_FONT (font);
+  PangoWin32FontMap *win32fontmap = PANGO_WIN32_FONT_MAP (win32font->fontmap);
+  IDWriteFont *dwrite_font = NULL;
+  IDWriteFontFace *face = NULL;
+
+  dwrite_font = (IDWriteFont *) g_hash_table_lookup (win32fontmap->dwrite_fonts, &win32font->logfontw);
+
+  if (dwrite_font != NULL)
+    return (void *)_pango_win32_get_dwrite_font_face_from_dwrite_font (dwrite_font);
+
+  return NULL;
+}
+
 void
 pango_win32_dwrite_font_map_populate (PangoWin32FontMap *map)
 {
@@ -134,10 +166,9 @@ pango_win32_dwrite_font_map_populate (PangoWin32FontMap *map)
               break;
             }
 
-          hr = font->CreateFontFace (&face);
-          if (FAILED (hr) || face == NULL)
+          face = _pango_win32_get_dwrite_font_face_from_dwrite_font (font);
+          if (face == NULL)
             {
-              g_warning ("IDWriteFont::CreateFontFace failed with error code %x\n", (unsigned)hr);
               font->Release ();
               continue;
             }
@@ -466,16 +497,23 @@ pango_win32_dwrite_font_check_is_hinted (PangoWin32Font *font)
   gboolean result = FALSE;
   gboolean dwrite_font_release = FALSE;
 
-  dwrite_font = get_dwrite_font_from_pango_win32_font (font, &dwrite_font_release);
+  dwrite_font_face = (IDWriteFontFace *)pango_win32_font_get_dwrite_font_face (font);
 
-  if (dwrite_font == NULL)
+  if (dwrite_font_face == NULL)
     {
-      g_warning ("Failed to retrieve IDWriteFont from PangoWin32Font");
+      dwrite_font = get_dwrite_font_from_pango_win32_font (font, &dwrite_font_release);
 
-      return FALSE;
+      if (dwrite_font != NULL)
+        dwrite_font_face = _pango_win32_get_dwrite_font_face_from_dwrite_font (dwrite_font);
+      else
+        {
+          g_warning ("Failed to retrieve IDWriteFont from PangoWin32Font");
+
+          return FALSE;
+        }
     }
 
-  if (SUCCEEDED (dwrite_font->CreateFontFace (&dwrite_font_face)) && dwrite_font_face != NULL)
+  if (dwrite_font_face != NULL)
     {
       UINT32 gasp_tag = DWRITE_MAKE_OPENTYPE_TAG ('g', 'a', 's', 'p');
       UINT32 table_size;
diff --git a/pango/pangowin32-private.h b/pango/pangowin32-private.h
index c66795fb0..2f9bbf601 100644
--- a/pango/pangowin32-private.h
+++ b/pango/pangowin32-private.h
@@ -290,6 +290,9 @@ gpointer        _pango_win32_copy_cmap (gpointer cmap,
 _PANGO_EXTERN
 gboolean        pango_win32_dwrite_font_check_is_hinted       (PangoWin32Font    *font);
 
+_PANGO_EXTERN
+void           *pango_win32_font_get_dwrite_font_face         (PangoWin32Font    *font);
+
 extern gboolean _pango_win32_debug;
 
 void                   pango_win32_insert_font                (PangoWin32FontMap     *win32fontmap,


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