mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 17:33:25 +00:00
GimpText: Fix crash when serializing text with missing font.
For some reason pango returns a FontDescription with name "Normal" when called with empty string. This caused crashes in pango markup serialization. This patch checks if the font before serialization is a valid font object, otherwise fallback to the fallback font. Also font's reference count wasn't increased in one case when opening xcf file with a text layer.
This commit is contained in:
parent
12806b2830
commit
9d43b2cfc2
2 changed files with 17 additions and 1 deletions
|
@ -333,7 +333,12 @@ gimp_font_deserialize_create (GType type,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_scanner_peek_next_token (scanner) == G_TOKEN_RIGHT_PAREN)
|
if (g_scanner_peek_next_token (scanner) == G_TOKEN_RIGHT_PAREN)
|
||||||
return GIMP_CONFIG (GIMP_FONT (gimp_font_get_standard ()));
|
{
|
||||||
|
font = GIMP_FONT (gimp_font_get_standard ());
|
||||||
|
g_object_ref (font);
|
||||||
|
|
||||||
|
return GIMP_CONFIG (font);
|
||||||
|
}
|
||||||
|
|
||||||
scope_id = g_type_qname (type);
|
scope_id = g_type_qname (type);
|
||||||
old_scope_id = g_scanner_set_scope (scanner, scope_id);
|
old_scope_id = g_scanner_set_scope (scanner, scope_id);
|
||||||
|
|
|
@ -587,6 +587,9 @@ gimp_text_set_property (GObject *object,
|
||||||
|
|
||||||
if (font != text->font && font != NULL)
|
if (font != text->font && font != NULL)
|
||||||
g_set_object (&text->font, font);
|
g_set_object (&text->font, font);
|
||||||
|
/* this is defensive to avoid some crashes */
|
||||||
|
else if (font == NULL)
|
||||||
|
g_set_object (&text->font, GIMP_FONT (gimp_font_get_standard ()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PROP_FONT_SIZE:
|
case PROP_FONT_SIZE:
|
||||||
|
@ -844,6 +847,12 @@ gimp_text_serialize_property (GimpConfig *config,
|
||||||
font = GIMP_FONT (gimp_container_search (container,
|
font = GIMP_FONT (gimp_container_search (container,
|
||||||
(GimpContainerSearchFunc) gimp_font_match_by_lookup_name,
|
(GimpContainerSearchFunc) gimp_font_match_by_lookup_name,
|
||||||
(gpointer) altered_font_name));
|
(gpointer) altered_font_name));
|
||||||
|
/* in case pango returns a non existant font name */
|
||||||
|
if (font == NULL)
|
||||||
|
{
|
||||||
|
font = GIMP_FONT (gimp_font_get_standard ());
|
||||||
|
font_name = "gimpfont";
|
||||||
|
}
|
||||||
|
|
||||||
gimp_config_writer_open (writer, "markupfont");
|
gimp_config_writer_open (writer, "markupfont");
|
||||||
/*lookupname format is "gimpfont%d" we keep only the "font%d",
|
/*lookupname format is "gimpfont%d" we keep only the "font%d",
|
||||||
|
@ -955,6 +964,7 @@ gimp_text_deserialize_property (GimpConfig *object,
|
||||||
scanner,
|
scanner,
|
||||||
-1,
|
-1,
|
||||||
NULL));
|
NULL));
|
||||||
|
g_assert (GIMP_IS_FONT (font));
|
||||||
replaced_markup = g_markup_printf_escaped (" font=\"%s\"", markup_fontname);
|
replaced_markup = g_markup_printf_escaped (" font=\"%s\"", markup_fontname);
|
||||||
new_markup = g_strdup_printf (" gimpfont=\"%s\"", gimp_font_get_lookup_name (font));
|
new_markup = g_strdup_printf (" gimpfont=\"%s\"", gimp_font_get_lookup_name (font));
|
||||||
g_string_replace (markup_str, replaced_markup, new_markup, 0);
|
g_string_replace (markup_str, replaced_markup, new_markup, 0);
|
||||||
|
@ -993,6 +1003,7 @@ gimp_text_deserialize_property (GimpConfig *object,
|
||||||
scanner,
|
scanner,
|
||||||
-1,
|
-1,
|
||||||
NULL));
|
NULL));
|
||||||
|
g_assert (GIMP_IS_FONT (font));
|
||||||
g_scanner_get_next_token (scanner); /* ) */
|
g_scanner_get_next_token (scanner); /* ) */
|
||||||
g_scanner_get_next_token (scanner); /* ) */
|
g_scanner_get_next_token (scanner); /* ) */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue