summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2022-08-15 17:32:57 +0800
committerChun-wei Fan <fanchunwei@src.gnome.org>2022-09-26 11:04:26 +0800
commit7179fd3cd89c600381fd0fd22d3d60731977ed56 (patch)
tree416e3f089a12a648d3adce69e066e724cc187da1
parentbde6de5a7d925f12d49014cc297fb742e3c73068 (diff)
downloadpango-7179fd3cd89c600381fd0fd22d3d60731977ed56.tar.gz
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.
-rw-r--r--pango/pangowin32-dwrite-fontmap.cpp54
-rw-r--r--pango/pangowin32-private.h3
2 files changed, 49 insertions, 8 deletions
diff --git a/pango/pangowin32-dwrite-fontmap.cpp b/pango/pangowin32-dwrite-fontmap.cpp
index 7451bf97..48770224 100644
--- a/pango/pangowin32-dwrite-fontmap.cpp
+++ b/pango/pangowin32-dwrite-fontmap.cpp
@@ -87,6 +87,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)
{
@@ -132,10 +164,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;
}
@@ -465,16 +496,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 c66795fb..2f9bbf60 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,