summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2023-01-15 16:08:55 +0000
committerMatthias Clasen <mclasen@redhat.com>2023-01-15 16:08:55 +0000
commit5a892583a5f09b7ade3aec7718fe401c80252bd2 (patch)
tree2384460563e667bb84ee9d6cdd13400e86aea6b7
parent58a38d6a4ba2152668a88316a3ddcef6842db072 (diff)
parentc7d7c9eab24ef52596f43f0e698bb6e7cb7f027b (diff)
downloadpango-5a892583a5f09b7ade3aec7718fe401c80252bd2.tar.gz
Merge branch 'dwrite-cleanups' into 'main'
PangoWin32: Cleanup DirectWrite code a bit See merge request GNOME/pango!667
-rw-r--r--pango/pangocairo-win32font.c1
-rw-r--r--pango/pangowin32-dwrite-fontmap.cpp74
-rw-r--r--pango/pangowin32.c19
3 files changed, 39 insertions, 55 deletions
diff --git a/pango/pangocairo-win32font.c b/pango/pangocairo-win32font.c
index 0141c414..9d52dbcf 100644
--- a/pango/pangocairo-win32font.c
+++ b/pango/pangocairo-win32font.c
@@ -76,7 +76,6 @@ pango_cairo_win32_font_create_font_face (PangoCairoFont *font)
PangoCairoWin32Font *cwfont = PANGO_CAIRO_WIN32_FONT (font);
PangoWin32Font *win32font = &cwfont->font;
void *dwrite_font_face = NULL;
- gpointer dwrite_font = NULL;
#ifdef HAVE_CAIRO_WIN32_DIRECTWRITE
dwrite_font_face = pango_win32_font_get_dwrite_font_face (win32font);
diff --git a/pango/pangowin32-dwrite-fontmap.cpp b/pango/pangowin32-dwrite-fontmap.cpp
index a2c03675..2db0972a 100644
--- a/pango/pangowin32-dwrite-fontmap.cpp
+++ b/pango/pangowin32-dwrite-fontmap.cpp
@@ -103,6 +103,32 @@ _pango_win32_get_dwrite_font_face_from_dwrite_font (IDWriteFont *font)
return NULL;
}
+static IDWriteFont *
+get_dwrite_font_from_pango_win32_font (PangoWin32Font *font)
+{
+ PangoWin32DWriteItems *dwrite_items = pango_win32_get_direct_write_items ();
+ IDWriteFont *dwrite_font = NULL;
+ PangoWin32FontMap *fontmap = PANGO_WIN32_FONT_MAP (font->fontmap);
+
+ dwrite_font = (IDWriteFont *) g_hash_table_lookup (fontmap->dwrite_fonts,
+ &font->logfontw);
+
+ /* create the IDWriteFont from the logfont underlying the PangoWin32Font if needed */
+ if (dwrite_font == NULL)
+ {
+ if (SUCCEEDED (dwrite_items->gdi_interop->CreateFontFromLOGFONT (&font->logfontw,
+ &dwrite_font)) &&
+ dwrite_font != NULL)
+ {
+ g_hash_table_insert (fontmap->dwrite_fonts,
+ &font->logfontw,
+ dwrite_font);
+ }
+ }
+
+ return dwrite_font;
+}
+
void *
pango_win32_font_get_dwrite_font_face (PangoWin32Font *font)
{
@@ -111,7 +137,7 @@ pango_win32_font_get_dwrite_font_face (PangoWin32Font *font)
IDWriteFont *dwrite_font = NULL;
IDWriteFontFace *face = NULL;
- dwrite_font = (IDWriteFont *) g_hash_table_lookup (win32fontmap->dwrite_fonts, &win32font->logfontw);
+ dwrite_font = get_dwrite_font_from_pango_win32_font (font);
if (dwrite_font != NULL)
return (void *)_pango_win32_get_dwrite_font_face_from_dwrite_font (dwrite_font);
@@ -424,7 +450,7 @@ pango_win32_font_description_from_logfontw_dwrite (const LOGFONTW *logfontw)
PangoStretch stretch;
PangoWin32DWriteItems *dwrite_items;
- dwrite_items = pango_win32_init_direct_write ();
+ dwrite_items = pango_win32_get_direct_write_items ();
if (dwrite_items == NULL)
return NULL;
@@ -452,30 +478,6 @@ pango_win32_font_description_from_logfontw_dwrite (const LOGFONTW *logfontw)
return desc;
}
-static IDWriteFont *
-get_dwrite_font_from_pango_win32_font (PangoWin32Font *font,
- gboolean *is_cleanup_dwrite_font)
-{
- PangoWin32DWriteItems *dwrite_items = pango_win32_get_direct_write_items ();
- IDWriteFont *dwrite_font = NULL;
-
- dwrite_font = (IDWriteFont *) g_hash_table_lookup (PANGO_WIN32_FONT_MAP (font->fontmap)->dwrite_fonts,
- &font->logfontw);
-
- /* create the IDWriteFont from the logfont underlying the PangoWin32Font if needed */
- if (dwrite_font == NULL)
- {
- if (SUCCEEDED (dwrite_items->gdi_interop->CreateFontFromLOGFONT (&font->logfontw,
- &dwrite_font)) &&
- dwrite_font != NULL)
- *is_cleanup_dwrite_font = TRUE;
- else
- dwrite_font = NULL;
- }
-
- return dwrite_font;
-}
-
/* macros to help parse the 'gasp' font table, referring to FreeType2 */
#define DWRITE_UCHAR_USHORT( p, i, s ) ( (unsigned short)( ((const unsigned char *)(p))[(i)] ) << (s) )
@@ -490,28 +492,11 @@ get_dwrite_font_from_pango_win32_font (PangoWin32Font *font,
gboolean
pango_win32_dwrite_font_check_is_hinted (PangoWin32Font *font)
{
- IDWriteFont *dwrite_font = NULL;
IDWriteFontFace *dwrite_font_face = NULL;
- gboolean failed = FALSE;
gboolean result = FALSE;
- gboolean dwrite_font_release = FALSE;
dwrite_font_face = (IDWriteFontFace *)pango_win32_font_get_dwrite_font_face (font);
- if (dwrite_font_face == NULL)
- {
- dwrite_font = get_dwrite_font_from_pango_win32_font (font, &dwrite_font_release);
-
- 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 (dwrite_font_face != NULL)
{
UINT32 gasp_tag = DWRITE_MAKE_OPENTYPE_TAG ('g', 'a', 's', 'p');
@@ -553,9 +538,6 @@ pango_win32_dwrite_font_check_is_hinted (PangoWin32Font *font)
dwrite_font_face->Release ();
}
- if (dwrite_font_release)
- dwrite_font->Release ();
-
return result;
}
diff --git a/pango/pangowin32.c b/pango/pangowin32.c
index 5a26ee98..7b6325a5 100644
--- a/pango/pangowin32.c
+++ b/pango/pangowin32.c
@@ -133,7 +133,6 @@ HDC
_pango_win32_get_display_dc (void)
{
HDC hdc = g_private_get (&display_dc_key);
- PangoWin32DWriteItems *items;
if (hdc == NULL)
{
@@ -154,12 +153,8 @@ _pango_win32_get_display_dc (void)
#endif
}
- items = g_private_get (&dwrite_items);
- if (items == NULL)
- {
- items = pango_win32_init_direct_write ();
- g_private_set (&dwrite_items, items);
- }
+ /* ensure DirectWrite is initialized */
+ pango_win32_get_direct_write_items ();
return hdc;
}
@@ -167,7 +162,15 @@ _pango_win32_get_display_dc (void)
PangoWin32DWriteItems *
pango_win32_get_direct_write_items (void)
{
- return g_private_get (&dwrite_items);
+ PangoWin32DWriteItems *items = g_private_get (&dwrite_items);
+
+ if (items == NULL)
+ {
+ items = pango_win32_init_direct_write ();
+ g_private_set (&dwrite_items, items);
+ }
+
+ return items;
}
/**