summaryrefslogtreecommitdiff
path: root/pango/pangowin32-dwrite-fontmap.cpp
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 /pango/pangowin32-dwrite-fontmap.cpp
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.
Diffstat (limited to 'pango/pangowin32-dwrite-fontmap.cpp')
-rw-r--r--pango/pangowin32-dwrite-fontmap.cpp54
1 files changed, 46 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;