[gimp] app: add "markup" property to GimpText



commit db6a669c4bdf7cf4609f7c6aed70e71756caa926
Author: Michael Natterer <mitch gimp org>
Date:   Fri Feb 26 00:11:25 2010 +0100

    app: add "markup" property to GimpText
    
    And prefer it over "text" when rendering. Everything is exactly as
    before if "markup" is never set.

 app/text/gimptext-vectors.c |    5 +++--
 app/text/gimptext.c         |   18 ++++++++++++++++++
 app/text/gimptext.h         |    1 +
 app/text/gimptextlayer.c    |    2 +-
 app/text/gimptextlayout.c   |    4 +++-
 5 files changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/app/text/gimptext-vectors.c b/app/text/gimptext-vectors.c
index a2a4ccd..52b79d9 100644
--- a/app/text/gimptext-vectors.c
+++ b/app/text/gimptext-vectors.c
@@ -62,13 +62,14 @@ gimp_text_vectors_new (GimpImage *image,
 
   vectors = gimp_vectors_new (image, NULL);
 
-  if (text->text)
+  if (text->text || text->markup)
     {
       GimpTextLayout  *layout;
       cairo_surface_t *surface;
       cairo_t         *cr;
 
-      gimp_object_set_name_safe (GIMP_OBJECT (vectors), text->text);
+      if (text->text)
+        gimp_object_set_name_safe (GIMP_OBJECT (vectors), text->text);
 
       context.vectors = vectors;
 
diff --git a/app/text/gimptext.c b/app/text/gimptext.c
index e570891..78843db 100644
--- a/app/text/gimptext.c
+++ b/app/text/gimptext.c
@@ -42,6 +42,7 @@ enum
 {
   PROP_0,
   PROP_TEXT,
+  PROP_MARKUP,
   PROP_FONT,
   PROP_FONT_SIZE,
   PROP_UNIT,
@@ -112,6 +113,10 @@ gimp_text_class_init (GimpTextClass *klass)
                                    "text", NULL,
                                    NULL,
                                    GIMP_PARAM_STATIC_STRINGS);
+  GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_MARKUP,
+                                   "markup", NULL,
+                                   NULL,
+                                   GIMP_PARAM_STATIC_STRINGS);
   GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_FONT,
                                    "font", NULL,
                                    "Sans",
@@ -249,6 +254,11 @@ gimp_text_finalize (GObject *object)
       g_free (text->text);
       text->text = NULL;
     }
+  if (text->markup)
+    {
+      g_free (text->markup);
+      text->markup = NULL;
+    }
   if (text->font)
     {
       g_free (text->font);
@@ -276,6 +286,9 @@ gimp_text_get_property (GObject      *object,
     case PROP_TEXT:
       g_value_set_string (value, text->text);
       break;
+    case PROP_MARKUP:
+      g_value_set_string (value, text->markup);
+      break;
     case PROP_FONT:
       g_value_set_string (value, text->font);
       break;
@@ -365,6 +378,10 @@ gimp_text_set_property (GObject      *object,
       g_free (text->text);
       text->text = g_value_dup_string (value);
       break;
+    case PROP_MARKUP:
+      g_free (text->markup);
+      text->markup = g_value_dup_string (value);
+      break;
     case PROP_FONT:
       {
         const gchar *font = g_value_get_string (value);
@@ -471,6 +488,7 @@ gimp_text_get_memsize (GimpObject *object,
   gint64    memsize = 0;
 
   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);
 
diff --git a/app/text/gimptext.h b/app/text/gimptext.h
index bd0e1ef..27048ac 100644
--- a/app/text/gimptext.h
+++ b/app/text/gimptext.h
@@ -41,6 +41,7 @@ struct _GimpText
   GimpObject             parent_instance;
 
   gchar                 *text;
+  gchar                 *markup;
   gchar                 *font;
   GimpUnit               unit;
   gdouble                font_size;
diff --git a/app/text/gimptextlayer.c b/app/text/gimptextlayer.c
index 1122827..a988c4d 100644
--- a/app/text/gimptextlayer.c
+++ b/app/text/gimptextlayer.c
@@ -369,7 +369,7 @@ gimp_text_layer_new (GimpImage *image,
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
   g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
 
-  if (! text->text)
+  if (! text->text && ! text->markup)
     return NULL;
 
   layer = g_object_new (GIMP_TYPE_TEXT_LAYER, NULL);
diff --git a/app/text/gimptextlayout.c b/app/text/gimptextlayout.c
index 2dcffa3..8eb0702 100644
--- a/app/text/gimptextlayout.c
+++ b/app/text/gimptextlayout.c
@@ -143,7 +143,9 @@ gimp_text_layout_new (GimpText  *text,
   pango_layout_set_font_description (layout->layout, font_desc);
   pango_font_description_free (font_desc);
 
-  if (text->text)
+  if (text->markup)
+    pango_layout_set_markup (layout->layout, text->markup, -1);
+  else if (text->text)
     pango_layout_set_text (layout->layout, text->text, -1);
   else
     pango_layout_set_text (layout->layout, NULL, 0);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]