From cade006c9ef7cbbd1aefbf5c12a2c74151f031c8 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Mon, 11 Apr 2022 22:10:30 +0200 Subject: pangowin32: try harder to load a font load_fontset() in pangowin32 has various fallback code in case no font is found, but load_font() doesn't and just returns NULL in more cases. I saw that the other backends like fc and coretext just call load_fontset() in load_font() and return the first one. This copies this strategy to the win32 backend. --- pango/pangowin32-fontmap.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c index 43cffc37..4e6342a5 100644 --- a/pango/pangowin32-fontmap.c +++ b/pango/pangowin32-fontmap.c @@ -83,6 +83,9 @@ static void pango_win32_font_map_finalize (GObject static PangoFont *pango_win32_font_map_load_font (PangoFontMap *fontmap, PangoContext *context, const PangoFontDescription *description); +static PangoFont *pango_win32_font_map_real_load_font (PangoFontMap *fontmap, + PangoContext *context, + const PangoFontDescription *description); static PangoFontset *pango_win32_font_map_load_fontset (PangoFontMap *fontmap, PangoContext *context, const PangoFontDescription *desc, @@ -794,7 +797,7 @@ _pango_win32_font_map_class_init (PangoWin32FontMapClass *class) class->find_font = pango_win32_font_map_real_find_font; object_class->finalize = pango_win32_font_map_finalize; - fontmap_class->load_font = pango_win32_font_map_load_font; + fontmap_class->load_font = pango_win32_font_map_real_load_font; /* we now need a load_fontset implementation for the Win32 backend */ fontmap_class->load_fontset = pango_win32_font_map_load_fontset; fontmap_class->list_families = pango_win32_font_map_list_families; @@ -1011,6 +1014,46 @@ pango_win32_get_font_family (PangoWin32FontMap *win32fontmap, return win32family; } +static gboolean +get_first_font (PangoFontset *fontset G_GNUC_UNUSED, + PangoFont *font, + gpointer data) +{ + *(PangoFont **)data = font; + + return TRUE; +} + +static PangoFont * +pango_win32_font_map_real_load_font (PangoFontMap *fontmap, + PangoContext *context, + const PangoFontDescription *description) +{ + PangoLanguage *language; + PangoFontset *fontset; + PangoFont *font = NULL; + + if (context) + language = pango_context_get_language (context); + else + language = NULL; + + fontset = pango_font_map_load_fontset (fontmap, context, + description, language); + + if (fontset) + { + pango_fontset_foreach (fontset, get_first_font, &font); + + if (font) + g_object_ref (font); + + g_object_unref (fontset); + } + + return font; +} + static PangoFont * pango_win32_font_map_load_font (PangoFontMap *fontmap, PangoContext *context, -- cgit v1.2.1