From 4a174206afa33ddc540a10f27bd5dfeeefb075ff Mon Sep 17 00:00:00 2001 From: Idriss Fekir Date: Tue, 21 May 2024 17:16:27 +0100 Subject: [PATCH] text: Fix loading XCFs with XLFD fonts --- app/text/gimpfont.c | 7 +++++++ app/text/gimpfont.h | 2 ++ app/text/gimptext-parasite.c | 4 +++- app/text/gimptext-parasite.h | 3 ++- app/text/gimptext-xlfd.c | 35 ++++++++++++++++++++++++++++------- app/text/gimptextlayer-xcf.c | 3 ++- 6 files changed, 44 insertions(+), 10 deletions(-) diff --git a/app/text/gimpfont.c b/app/text/gimpfont.c index e2837e992c..10257982cc 100644 --- a/app/text/gimpfont.c +++ b/app/text/gimpfont.c @@ -524,6 +524,13 @@ gimp_font_match_by_lookup_name (GimpFont *font, return !g_strcmp0 (font->lookup_name, name); } +gboolean +gimp_font_match_by_description (GimpFont *font, + const gchar *desc) +{ + return !g_strcmp0 (font->desc, desc); +} + const gchar* gimp_font_get_lookup_name (GimpFont *font) { diff --git a/app/text/gimpfont.h b/app/text/gimpfont.h index 8f3b37cc0c..8be6cf3f68 100644 --- a/app/text/gimpfont.h +++ b/app/text/gimpfont.h @@ -44,6 +44,8 @@ void gimp_font_set_lookup_name (GimpFont *font, gchar *name); gboolean gimp_font_match_by_lookup_name (GimpFont *font, const gchar *name); +gboolean gimp_font_match_by_description (GimpFont *font, + const gchar *desc); void gimp_font_set_font_info (GimpFont *font, gpointer font_info[]); void gimp_font_class_set_font_factory (GimpFontFactory *factory); diff --git a/app/text/gimptext-parasite.c b/app/text/gimptext-parasite.c index 998565aef7..f222d018d0 100644 --- a/app/text/gimptext-parasite.c +++ b/app/text/gimptext-parasite.c @@ -221,7 +221,8 @@ enum }; GimpText * -gimp_text_from_gdyntext_parasite (const GimpParasite *parasite) +gimp_text_from_gdyntext_parasite (Gimp *gimp, + const GimpParasite *parasite) { GimpText *retval = NULL; GimpTextJustification justify; @@ -281,6 +282,7 @@ gimp_text_from_gdyntext_parasite (const GimpParasite *parasite) color / 255.0f, 1.0); retval = g_object_new (GIMP_TYPE_TEXT, + "gimp", gimp, "text", text, "antialias", antialias, "justify", justify, diff --git a/app/text/gimptext-parasite.h b/app/text/gimptext-parasite.h index 58767b7b05..9b2cc376b2 100644 --- a/app/text/gimptext-parasite.h +++ b/app/text/gimptext-parasite.h @@ -30,7 +30,8 @@ GimpText * gimp_text_from_parasite (const GimpParasite *parasite, GError **error); const gchar * gimp_text_gdyntext_parasite_name (void) G_GNUC_CONST; -GimpText * gimp_text_from_gdyntext_parasite (const GimpParasite *parasite); +GimpText * gimp_text_from_gdyntext_parasite (Gimp *gimp, + const GimpParasite *parasite); #endif /* __GIMP_TEXT_PARASITE_H__ */ diff --git a/app/text/gimptext-xlfd.c b/app/text/gimptext-xlfd.c index 020b8d696a..c83a63e955 100644 --- a/app/text/gimptext-xlfd.c +++ b/app/text/gimptext-xlfd.c @@ -24,6 +24,7 @@ #include "config.h" #include +#include #include #include @@ -31,6 +32,11 @@ #include "libgimpbase/gimpbase.h" +#include "core/core-types.h" +#include "core/gimp.h" +#include "core/gimpcontainer.h" +#include "core/gimpdatafactory.h" + #include "text-types.h" #include "gimpfont.h" @@ -192,11 +198,27 @@ gimp_text_set_font_from_xlfd (GimpText *text, font_name = gimp_text_font_name_from_xlfd (xlfd); if (font_name != NULL) { - font = g_object_new (GIMP_TYPE_FONT, - "name", font_name, - NULL); - gimp_font_set_lookup_name (font, font_name); + PangoFontDescription *pfd = pango_font_description_from_string (font_name); + gchar *desc = pango_font_description_to_string (pfd); + GimpContainer *fonts_container; + + fonts_container = gimp_data_factory_get_container (text->gimp->font_factory); + + font = GIMP_FONT (gimp_container_search (fonts_container, + (GimpContainerSearchFunc) gimp_font_match_by_description, + (gpointer) desc)); + if (font == NULL) + font = GIMP_FONT (gimp_font_get_standard ()); + + pango_font_description_free (pfd); + g_free (desc); } + else + { + font = GIMP_FONT (gimp_font_get_standard ()); + } + + g_object_ref (font); #if GIMP_TEXT_DEBUG g_printerr ("XLFD: %s font: %s\n", xlfd, font ? font : "(null)"); @@ -207,10 +229,10 @@ gimp_text_set_font_from_xlfd (GimpText *text, g_object_set (text, "font-size", size, "font-size-unit", size_unit, - font_name ? "font" : NULL, font, + "font", font, NULL); } - else if (font) + else { g_object_set (text, "font", font, @@ -218,7 +240,6 @@ gimp_text_set_font_from_xlfd (GimpText *text, } g_free (font_name); - g_object_unref (font); } /** diff --git a/app/text/gimptextlayer-xcf.c b/app/text/gimptextlayer-xcf.c index 89b78eef7f..bcff068c94 100644 --- a/app/text/gimptextlayer-xcf.c +++ b/app/text/gimptextlayer-xcf.c @@ -97,7 +97,8 @@ gimp_text_layer_xcf_load_hack (GimpLayer **layer) if (parasite) { - text = gimp_text_from_gdyntext_parasite (parasite); + text = gimp_text_from_gdyntext_parasite (gimp_item_get_image (GIMP_ITEM (*layer))->gimp, + parasite); before_xcf_v19 = TRUE; } }