diff --git a/app/core/gimp-memsize.c b/app/core/gimp-memsize.c index a45b890d99..2c0af86425 100644 --- a/app/core/gimp-memsize.c +++ b/app/core/gimp-memsize.c @@ -275,6 +275,8 @@ gimp_g_value_get_memsize (GValue *value) { if (strcmp ("GimpPattern", G_VALUE_TYPE_NAME (value)) == 0) memsize += gimp_g_object_get_memsize (g_value_get_object (value)); + else if (strcmp ("GimpFont", G_VALUE_TYPE_NAME (value)) == 0) + memsize += gimp_g_object_get_memsize (g_value_get_object (value)); else g_printerr ("%s: unhandled object value type: %s\n", G_STRFUNC, G_VALUE_TYPE_NAME (value)); diff --git a/app/pdb/text-layer-cmds.c b/app/pdb/text-layer-cmds.c index a50592b9ee..28bb6c31ca 100644 --- a/app/pdb/text-layer-cmds.c +++ b/app/pdb/text-layer-cmds.c @@ -38,6 +38,7 @@ #include "core/gimpcontext.h" #include "core/gimpimage.h" #include "core/gimpparamspecs.h" +#include "text/gimpfont.h" #include "text/gimptext.h" #include "text/gimptextlayer.h" @@ -260,9 +261,13 @@ text_layer_get_font_invoker (GimpProcedure *procedure, if (success) { + GimpFont *font_obj; + g_object_get (gimp_text_layer_get_text (layer), - "font", &font, + "font", &font_obj, NULL); + font = g_strdup (gimp_font_get_lookup_name (font_obj)); + g_object_unref (font_obj); } return_vals = gimp_procedure_get_return_values (procedure, success, diff --git a/app/text/gimpfont.c b/app/text/gimpfont.c index 0571308afa..1f27c975a1 100644 --- a/app/text/gimpfont.c +++ b/app/text/gimpfont.c @@ -42,6 +42,8 @@ #include "core/gimptempbuf.h" +#include "core/gimp-memsize.h" + #include "gimpfont.h" #include "gimp-intl.h" @@ -106,6 +108,8 @@ static GimpTempBuf * gimp_font_get_new_preview (GimpViewable *viewable, static const gchar * gimp_font_get_sample_string (PangoContext *context, PangoFontDescription *font_desc); +static gint64 gimp_font_get_memsize (GimpObject *object, + gint64 *gui_size); G_DEFINE_TYPE (GimpFont, gimp_font, GIMP_TYPE_DATA) @@ -122,7 +126,7 @@ gboolean gimp_font_match_by_lookup_name (GimpFont *font, const gchar *name) { - return !g_strcmp0 (gimp_font_get_lookup_name (font), name); + return !g_strcmp0 (font->lookup_name, name); } const gchar* @@ -134,11 +138,13 @@ gimp_font_get_lookup_name (GimpFont *font) static void gimp_font_class_init (GimpFontClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass); + GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass); object_class->finalize = gimp_font_finalize; object_class->set_property = gimp_font_set_property; + gimp_object_class->get_memsize = gimp_font_get_memsize; viewable_class->get_preview_size = gimp_font_get_preview_size; viewable_class->get_popup_size = gimp_font_get_popup_size; @@ -192,6 +198,19 @@ gimp_font_set_property (GObject *object, } } +static gint64 +gimp_font_get_memsize (GimpObject *object, + gint64 *gui_size) +{ + GimpFont *font = GIMP_FONT (object); + gint64 memsize = 0; + + memsize += gimp_string_get_memsize (font->lookup_name); + + return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, + gui_size); +} + static void gimp_font_get_preview_size (GimpViewable *viewable, gint size, @@ -221,7 +240,7 @@ gimp_font_get_popup_size (GimpViewable *viewable, if (! font->pango_context) return FALSE; - name = gimp_font_get_lookup_name (font); + name = font->lookup_name; font_desc = pango_font_description_from_string (name); g_return_val_if_fail (font_desc != NULL, FALSE); @@ -276,7 +295,7 @@ gimp_font_get_new_preview (GimpViewable *viewable, PangoFontDescription *font_desc; const gchar *name; - name = gimp_font_get_lookup_name (font); + name = font->lookup_name; DEBUGPRINT (("%s: ", name)); diff --git a/app/text/gimptext.c b/app/text/gimptext.c index 87456fec06..26c5fdb4aa 100644 --- a/app/text/gimptext.c +++ b/app/text/gimptext.c @@ -34,6 +34,8 @@ #include "text-types.h" +#include "gimpfont.h" + #include "core/gimp.h" #include "core/gimp-memsize.h" #include "core/gimp-utils.h" @@ -176,11 +178,9 @@ gimp_text_class_init (GimpTextClass *klass) NULL, GIMP_PARAM_STATIC_STRINGS); - GIMP_CONFIG_PROP_STRING (object_class, PROP_FONT, - "font", - NULL, NULL, - "Sans-serif", - GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_PROP_FONT (object_class, PROP_FONT, + "font", NULL, NULL, + GIMP_CONFIG_PARAM_FLAGS); GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_FONT_SIZE, "font-size", @@ -415,8 +415,8 @@ gimp_text_finalize (GObject *object) g_clear_pointer (&text->text, g_free); g_clear_pointer (&text->markup, g_free); - g_clear_pointer (&text->font, g_free); g_clear_pointer (&text->language, g_free); + g_clear_object (&text->font); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -438,7 +438,7 @@ gimp_text_get_property (GObject *object, g_value_set_string (value, text->markup); break; case PROP_FONT: - g_value_set_string (value, text->font); + g_value_set_object (value, text->font); break; case PROP_FONT_SIZE: g_value_set_double (value, text->font_size); @@ -580,23 +580,10 @@ gimp_text_set_property (GObject *object, break; case PROP_FONT: { - const gchar *font = g_value_get_string (value); + GimpFont *font = g_value_get_object (value); - g_free (text->font); - - if (font) - { - gsize len = strlen (font); - - if (g_str_has_suffix (font, " Not-Rotated")) - len -= strlen ( " Not-Rotated"); - - text->font = g_strndup (font, len); - } - else - { - text->font = NULL; - } + if (font != text->font) + g_set_object (&text->font, font); } break; case PROP_FONT_SIZE: @@ -748,7 +735,6 @@ gimp_text_get_memsize (GimpObject *object, memsize += gimp_string_get_memsize (text->text); memsize += gimp_string_get_memsize (text->markup); - memsize += gimp_string_get_memsize (text->font); memsize += gimp_string_get_memsize (text->language); return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, diff --git a/app/text/gimptext.h b/app/text/gimptext.h index d06b4494a9..6b6434edd1 100644 --- a/app/text/gimptext.h +++ b/app/text/gimptext.h @@ -41,7 +41,7 @@ struct _GimpText gchar *text; gchar *markup; - gchar *font; + GimpFont *font; GimpUnit unit; gdouble font_size; gboolean antialias; diff --git a/app/text/gimptextlayout.c b/app/text/gimptextlayout.c index 93082e1c32..50cd670d8d 100644 --- a/app/text/gimptextlayout.c +++ b/app/text/gimptextlayout.c @@ -34,6 +34,8 @@ #include "core/gimperror.h" +#include "gimpfont.h" + #include "gimptext.h" #include "gimptextlayout.h" @@ -116,7 +118,7 @@ gimp_text_layout_new (GimpText *text, g_return_val_if_fail (GIMP_IS_TEXT (text), NULL); - font_desc = pango_font_description_from_string (text->font); + font_desc = pango_font_description_from_string (gimp_font_get_lookup_name (text->font)); g_return_val_if_fail (font_desc != NULL, NULL); size = pango_units_from_double (gimp_units_to_points (text->font_size, diff --git a/app/tools/gimptextoptions.c b/app/tools/gimptextoptions.c index fc5450f890..118a7f6648 100644 --- a/app/tools/gimptextoptions.c +++ b/app/tools/gimptextoptions.c @@ -41,6 +41,8 @@ #include "text/gimptext.h" +#include "text/gimpfont.h" + #include "widgets/gimpcolorpanel.h" #include "widgets/gimpmenufactory.h" #include "widgets/gimppropwidgets.h" @@ -648,11 +650,14 @@ gimp_text_options_notify_font (GimpContext *context, GParamSpec *pspec, GimpText *text) { + if (gimp_context_get_font (context) == text->font) + return; + g_signal_handlers_block_by_func (text, gimp_text_options_notify_text_font, context); - g_object_set (text, "font", gimp_context_get_font_name (context), NULL); + g_object_set (text, "font", gimp_context_get_font (context), NULL); g_signal_handlers_unblock_by_func (text, gimp_text_options_notify_text_font, @@ -667,7 +672,7 @@ gimp_text_options_notify_text_font (GimpText *text, g_signal_handlers_block_by_func (context, gimp_text_options_notify_font, text); - gimp_context_set_font_name (context, text->font); + gimp_context_set_font (context, text->font); g_signal_handlers_unblock_by_func (context, gimp_text_options_notify_font, text); @@ -728,7 +733,7 @@ gimp_text_options_connect_text (GimpTextOptions *options, g_object_set (text, "color", &color, - "font", gimp_context_get_font_name (context), + "font", gimp_context_get_font (context), NULL); gimp_config_connect (G_OBJECT (options), G_OBJECT (text), NULL); diff --git a/app/widgets/gimptextstyleeditor.c b/app/widgets/gimptextstyleeditor.c index a835a61da1..68062227b1 100644 --- a/app/widgets/gimptextstyleeditor.c +++ b/app/widgets/gimptextstyleeditor.c @@ -723,7 +723,7 @@ gimp_text_style_editor_set_default_font (GimpTextStyleEditor *editor) gimp_text_style_editor_font_changed, editor); - gimp_context_set_font_name (editor->context, editor->text->font); + gimp_context_set_font (editor->context, editor->text->font); g_signal_handlers_unblock_by_func (editor->context, gimp_text_style_editor_font_changed, diff --git a/libgimpconfig/gimpconfig-params.h b/libgimpconfig/gimpconfig-params.h index ed1df75600..87e2d98b93 100644 --- a/libgimpconfig/gimpconfig-params.h +++ b/libgimpconfig/gimpconfig-params.h @@ -182,6 +182,11 @@ G_BEGIN_DECLS default,\ flags | GIMP_CONFIG_PARAM_FLAGS)) +#define GIMP_CONFIG_PROP_FONT(class, id, name, nick, blurb, flags) \ + g_object_class_install_property (class, id,\ + g_param_spec_object (name, nick, blurb,\ + GIMP_TYPE_FONT,\ + flags | GIMP_CONFIG_PARAM_FLAGS)) /* object, boxed and pointer properties are _not_ G_PARAM_CONSTRUCT */ diff --git a/pdb/groups/text_layer.pdb b/pdb/groups/text_layer.pdb index 37209315d7..eaa98accee 100644 --- a/pdb/groups/text_layer.pdb +++ b/pdb/groups/text_layer.pdb @@ -249,9 +249,13 @@ HELP %invoke = ( code => <<'CODE' { + GimpFont *font_obj; + g_object_get (gimp_text_layer_get_text (layer), - "font", &font, + "font", &font_obj, NULL); + font = g_strdup (gimp_font_get_lookup_name (font_obj)); + g_object_unref (font_obj); } CODE ); @@ -990,6 +994,7 @@ CODE @headers = qw( "libgimpbase/gimpbase.h" "core/gimpcontext.h" + "text/gimpfont.h" "text/gimptext.h" "text/gimptextlayer.h" "gimppdb-utils.h"