From c050fe202f1ef4657e64d48d363188240774f90f Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Wed, 14 Dec 2022 12:56:05 +0800 Subject: pangowin32-fontmap.c: Allow some support for loading custom fonts Previously, when using GDI, we are able to add custom fonts to the system font collection using AddFontResource()/AddFontResourceEx(), but this is not enough as we transition to DirectWrite. Allow some support for this for people that are using AddFontResource() (but not yet AddFontResourceEx()), by using the GDI interop support in DirectWrite. Let people know that currently AddFontResource() should be used for the moment for this support to work, not AddFontResourceEx(). --- pango/pangowin32-dwrite-fontmap.cpp | 8 ++++++-- pango/pangowin32-fontmap.c | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pango/pangowin32-dwrite-fontmap.cpp b/pango/pangowin32-dwrite-fontmap.cpp index a2c03675..377544a9 100644 --- a/pango/pangowin32-dwrite-fontmap.cpp +++ b/pango/pangowin32-dwrite-fontmap.cpp @@ -208,8 +208,12 @@ pango_win32_logfontw_get_dwrite_font (LOGFONTW *logfontw) hr = dwrite_items->gdi_interop->CreateFontFromLOGFONT (logfontw, &font); if (FAILED (hr) || font == NULL) - g_warning ("IDWriteFactory::GdiInterop::CreateFontFromLOGFONT failed with error %x\n", - (unsigned)hr); + { + g_warning ("IDWriteFactory::GdiInterop::CreateFontFromLOGFONT failed with error %x\n", + (unsigned)hr); + if (hr == DWRITE_E_NOFONT) + g_message ("Did you create your LOGFONTW using AddFontResource() instead of AddFontResourceEx()?"); + } return font; } diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c index 4cc95787..9b8f6e4b 100644 --- a/pango/pangowin32-fontmap.c +++ b/pango/pangowin32-fontmap.c @@ -193,7 +193,10 @@ pango_win32_inner_enum_proc (LOGFONTW *lfp, * Asian fonts with @ prepended to their name, ignore them. */ if (lfp->lfFaceName[0] != '@') - pango_win32_insert_font (win32fontmap, lfp, NULL, FALSE); + { + gpointer dwrite_font = pango_win32_logfontw_get_dwrite_font (lfp); + pango_win32_insert_font (win32fontmap, lfp, dwrite_font, FALSE); + } return 1; } @@ -212,17 +215,24 @@ pango_win32_enum_proc (LOGFONTW *lfp, { LOGFONTW lf; struct EnumProcData *data = (struct EnumProcData *) lParam; + PangoWin32FontMap *map = data->font_map; PING (("%S: %lu %lx", lfp->lfFaceName, fontType, metrics->ntmFlags)); - /* Do not enum Type-1 fonts */ - if (fontType == TRUETYPE_FONTTYPE || metrics->ntmFlags & NTM_PS_OPENTYPE) + /* Do not enum Type-1 fonts, and ignore any fonts in the system font + * collection that was previously picked up by DirectWrite + * (IDWriteFactory->GetSystemFontCollection() via + * pango_win32_dwrite_font_map_populate()) + */ + + if (!g_hash_table_lookup (map->fonts, lfp) && + (fontType == TRUETYPE_FONTTYPE || metrics->ntmFlags & NTM_PS_OPENTYPE)) { lf = *lfp; EnumFontFamiliesExW (data->hdc, &lf, (FONTENUMPROCW) pango_win32_inner_enum_proc, - (LPARAM) data->font_map, 0); + (LPARAM) map, 0); } return 1; @@ -720,7 +730,6 @@ _pango_win32_font_map_init (PangoWin32FontMap *win32fontmap) pango_win32_dwrite_font_map_populate (win32fontmap); -#if 0 /* XXX: Implement fallback mode to GDI? */ memset (&logfont, 0, sizeof (logfont)); logfont.lfCharSet = DEFAULT_CHARSET; @@ -730,7 +739,6 @@ _pango_win32_font_map_init (PangoWin32FontMap *win32fontmap) EnumFontFamiliesExW (hdc, &logfont, (FONTENUMPROCW) pango_win32_enum_proc, (LPARAM) &enum_proc_data, 0); -#endif g_hash_table_foreach (win32fontmap->families, synthesize_foreach, win32fontmap); -- cgit v1.2.1