Re: GnomeCanvasText properties (was: Re: The future of GdkFont declarations)



OK so how about this patch?

-- 
   .--= ULLA! =---------------------.   `We are not here to give users what
   \     http://cactus.rulez.org     \   they want'  -- RMS, at GUADEC 2001
    `---= cactus cactus rulez org =---'
``Tragedy is when I cut my finger. Comedy is when you fall down an open manhole cover and die.'' -- Mel Brooks
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libgnomecanvas/ChangeLog,v
retrieving revision 1.10
diff -u -u -r1.10 ChangeLog
--- ChangeLog	2001/04/29 14:11:05	1.10
+++ ChangeLog	2001/05/05 00:00:36
@@ -1,3 +1,14 @@
+2001-05-05  ERDI Gergo  <cactus cactus rulez org>
+
+	* libgnomecanvas/gnome-canvas-text.[ch]: new properties:
+	text_markup: the text of the canvas item, with inline Pango markup
+	tags
+	attributes: A read/writeable Pango attribute list of the rendered
+	text
+	style, variant, weight, stretch, size, size_points: atomic font properties
+	style_set, variant_set, weight_set, stretch_set, size_set: toggles
+	usage of font parameters on a per-parameter basis
+
 2001-04-29  Martin Baulig  <baulig suse de>
 
 	* configure.in: Don't check for gnome-maketypes.pl and
Index: libgnomecanvas/gnome-canvas-text.c
===================================================================
RCS file: /cvs/gnome/libgnomecanvas/libgnomecanvas/gnome-canvas-text.c,v
retrieving revision 1.53
diff -u -u -r1.53 gnome-canvas-text.c
--- libgnomecanvas/gnome-canvas-text.c	2001/04/12 14:53:19	1.53
+++ libgnomecanvas/gnome-canvas-text.c	2001/05/05 00:00:46
@@ -1,4 +1,6 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
+ * $Id$
  * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
  * All rights reserved.
  *
@@ -30,6 +32,7 @@
  *
  *
  * Author: Federico Mena <federico nuclecu unam mx>
+ * Port to Pango co-done by Gergő Érdi <cactus cactus rulez org>
  */
 
 #include <config.h>
@@ -42,17 +45,40 @@
 #include "libart_lgpl/art_rgb.h"
 #include "libart_lgpl/art_rgb_bitmap_affine.h"
 #include "gnome-canvas-util.h"
+#include "gnome-canvas-i18n.h"
 
 
 
 /* Object argument IDs */
 enum {
 	PROP_0,
+
+	/* Text contents */
 	PROP_TEXT,
+	PROP_MARKUP,
+
+	/* Position */
 	PROP_X,
 	PROP_Y,
+
+	/* Font */
 	PROP_FONT,
 	PROP_FONT_DESC,
+	PROP_FAMILY, PROP_FAMILY_SET,
+	
+	/* Style */
+	PROP_ATTRIBUTES,
+	PROP_STYLE,         PROP_STYLE_SET,
+	PROP_VARIANT,       PROP_VARIANT_SET,
+	PROP_WEIGHT,        PROP_WEIGHT_SET,
+	PROP_STRETCH,	    PROP_STRETCH_SET,
+	PROP_SIZE,          PROP_SIZE_SET,
+	PROP_SIZE_POINTS,
+	PROP_STRIKETHROUGH, PROP_STRIKETHROUGH_SET,
+	PROP_UNDERLINE,     PROP_UNDERLINE_SET,
+	PROP_RISE,          PROP_RISE_SET,
+
+	/* Clipping */
 	PROP_ANCHOR,
 	PROP_JUSTIFICATION,
 	PROP_CLIP_WIDTH,
@@ -60,10 +86,14 @@
 	PROP_CLIP,
 	PROP_X_OFFSET,
 	PROP_Y_OFFSET,
+
+	/* Coloring */
 	PROP_FILL_COLOR,
 	PROP_FILL_COLOR_GDK,
 	PROP_FILL_COLOR_RGBA,
 	PROP_FILL_STIPPLE,
+
+	/* Rendered size accessors */
 	PROP_TEXT_WIDTH,
 	PROP_TEXT_HEIGHT
 };
@@ -93,6 +123,13 @@
 				      double *x1, double *y1, double *x2, double *y2);
 static void gnome_canvas_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf);
 
+static void gnome_canvas_text_set_markup (GnomeCanvasText *textitem,
+					  const gchar     *markup);
+
+static void gnome_canvas_text_set_font_desc (GnomeCanvasText *textitem,
+					     PangoFontDescription *font_desc);
+static void gnome_canvas_text_apply_font_desc (GnomeCanvasText *textitem);
+
 static GnomeCanvasItemClass *parent_class;
 
 
@@ -146,38 +183,173 @@
 	gobject_class->set_property = gnome_canvas_text_set_property;
 	gobject_class->get_property = gnome_canvas_text_get_property;
 
+	/* Text */
         g_object_class_install_property
                 (gobject_class,
                  PROP_TEXT,
-                 g_param_spec_string ("text", NULL, NULL,
+                 g_param_spec_string ("text",
+				      _("Text"),
+				      _("Text to render"),
                                       NULL,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+
         g_object_class_install_property
                 (gobject_class,
+                 PROP_MARKUP,
+                 g_param_spec_string ("markup",
+				      _("Markup"),
+				      _("Marked up text to render"),
+				      NULL,
+                                      (G_PARAM_WRITABLE)));
+
+	/* Position */
+        g_object_class_install_property
+                (gobject_class,
                  PROP_X,
                  g_param_spec_double ("x", NULL, NULL,
 				      -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
 				      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_Y,
                  g_param_spec_double ("y", NULL, NULL,
 				      -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
 				      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        g_object_class_install_property
+
+
+	/* Font */
+	g_object_class_install_property
                 (gobject_class,
                  PROP_FONT,
-                 g_param_spec_string ("font", NULL, NULL,
+                 g_param_spec_string ("font",
+				      _("Font"),
+				      _("Font description as a string"),
                                       NULL,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+	
         g_object_class_install_property
-                (gobject_class,
-                 PROP_FONT_DESC,
-                 g_param_spec_boxed ("font_desc", NULL, NULL,
+		(gobject_class,
+		 PROP_FONT_DESC,
+		 g_param_spec_boxed ("font_desc",
+				     _("Font description"),
+				     _("Font description as a PangoFontDescription struct"),
 				     GTK_TYPE_PANGO_FONT_DESCRIPTION,
 				     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_FAMILY,
+		 g_param_spec_string ("family",
+				      _("Font family"),
+				      _("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
+				      NULL,
+				      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+	
+	/* Style */
         g_object_class_install_property
                 (gobject_class,
+                 PROP_ATTRIBUTES,
+                 g_param_spec_boxed ("attributes", NULL, NULL,
+				     PANGO_TYPE_ATTR_LIST,
+				     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+	
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_STYLE,
+		 g_param_spec_enum ("style",
+				    _("Font style"),
+				    _("Font style"),
+				    PANGO_TYPE_STYLE,
+				    PANGO_STYLE_NORMAL,
+				    G_PARAM_READABLE | G_PARAM_WRITABLE));
+	
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_VARIANT,
+		 g_param_spec_enum ("variant",
+				    _("Font variant"),
+				    _("Font variant"),
+				    PANGO_TYPE_VARIANT,
+				    PANGO_VARIANT_NORMAL,
+				    G_PARAM_READABLE | G_PARAM_WRITABLE));
+	
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_WEIGHT,
+		 g_param_spec_int ("weight",
+				   _("Font weight"),
+				   _("Font weight"),
+				   0,
+				   G_MAXINT,
+				   PANGO_WEIGHT_NORMAL,
+				   G_PARAM_READABLE | G_PARAM_WRITABLE));
+	
+	
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_STRETCH,
+		 g_param_spec_enum ("stretch",
+				    _("Font stretch"),
+				    _("Font stretch"),
+				    PANGO_TYPE_STRETCH,
+				    PANGO_STRETCH_NORMAL,
+				    G_PARAM_READABLE | G_PARAM_WRITABLE));
+	
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_SIZE,
+		 g_param_spec_int ("size",
+				   _("Font size"),
+				   _("Font size"),
+				   0,
+				   G_MAXINT,
+				   0,
+				   G_PARAM_READABLE | G_PARAM_WRITABLE));
+	
+	g_object_class_install_property
+		(gobject_class,
+		PROP_SIZE_POINTS,
+		g_param_spec_double ("size_points",
+				     _("Font points"),
+				     _("Font size in points"),
+				     0.0,
+				     G_MAXDOUBLE,
+				     0.0,
+				     G_PARAM_READABLE | G_PARAM_WRITABLE));  
+	
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_RISE,
+		 g_param_spec_int ("rise",
+				   _("Rise"),
+				   _("Offset of text above the baseline (below the baseline if rise is negative)"),
+				   -G_MAXINT,
+				   G_MAXINT,
+				   0,
+				   G_PARAM_READABLE | G_PARAM_WRITABLE));
+	
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_STRIKETHROUGH,
+		 g_param_spec_boolean ("strikethrough",
+				       _("Strikethrough"),
+				       _("Whether to strike through the text"),
+				       FALSE,
+				       G_PARAM_READABLE | G_PARAM_WRITABLE));
+	
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_UNDERLINE,
+		 g_param_spec_enum ("underline",
+				    _("Underline"),
+				    _("Style of underline for this text"),
+				    PANGO_TYPE_UNDERLINE,
+				    PANGO_UNDERLINE_NONE,
+				    G_PARAM_READABLE | G_PARAM_WRITABLE));
+	
+        g_object_class_install_property
+		(gobject_class,
                  PROP_ANCHOR,
                  g_param_spec_enum ("anchor", NULL, NULL,
                                     GTK_TYPE_ANCHOR_TYPE,
@@ -223,19 +395,25 @@
         g_object_class_install_property
                 (gobject_class,
                  PROP_FILL_COLOR,
-                 g_param_spec_string ("fill_color", NULL, NULL,
+                 g_param_spec_string ("fill_color",
+				      _("Color"),
+				      _("Text color, as string"),
                                       NULL,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_FILL_COLOR_GDK,
-                 g_param_spec_boxed ("fill_color_gdk", NULL, NULL,
+                 g_param_spec_boxed ("fill_color_gdk",
+				     _("Color"),
+				     _("Text color, as a GdkColor"),
 				     GDK_TYPE_COLOR,
 				     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_FILL_COLOR_RGBA,
-                 g_param_spec_uint ("fill_color_rgba", NULL, NULL,
+                 g_param_spec_uint ("fill_color_rgba",
+				    _("Color"),
+				    _("Text color, as an R/G/B/A combined integer"),
 				    0, G_MAXUINT, 0,
 				    (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
@@ -247,16 +425,60 @@
         g_object_class_install_property
                 (gobject_class,
                  PROP_TEXT_WIDTH,
-                 g_param_spec_double ("text_width", NULL, NULL,
+                 g_param_spec_double ("text_width",
+				      _("Text width"),
+				      _("Width of the rendered text"),
 				      0.0, G_MAXDOUBLE, 0.0,
 				      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_TEXT_HEIGHT,
-                 g_param_spec_double ("text_height", NULL, NULL,
+                 g_param_spec_double ("text_height",
+				      _("Text height"),
+				      _("Height of the rendered text"),
 				      0.0, G_MAXDOUBLE, 0.0,
 				      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
 
+	/* Style props are set (explicitly applied) or not */
+#define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (gobject_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE))
+
+	ADD_SET_PROP ("family_set", PROP_FAMILY_SET,
+		      _("Font family set"),
+		      _("Whether this tag affects the font family"));  
+	
+	ADD_SET_PROP ("style_set", PROP_STYLE_SET,
+		      _("Font style set"),
+		      _("Whether this tag affects the font style"));
+	
+	ADD_SET_PROP ("variant_set", PROP_VARIANT_SET,
+		      _("Font variant set"),
+		      _("Whether this tag affects the font variant"));
+	
+	ADD_SET_PROP ("weight_set", PROP_WEIGHT_SET,
+		      _("Font weight set"),
+		      _("Whether this tag affects the font weight"));
+	
+	ADD_SET_PROP ("stretch_set", PROP_STRETCH_SET,
+		      _("Font stretch set"),
+		      _("Whether this tag affects the font stretch"));
+	
+	ADD_SET_PROP ("size_set", PROP_SIZE_SET,
+		      _("Font size set"),
+		      _("Whether this tag affects the font size"));
+	
+	ADD_SET_PROP ("rise_set", PROP_RISE_SET,
+		      _("Rise set"),
+		      _("Whether this tag affects the rise"));
+	
+	ADD_SET_PROP ("strikethrough_set", PROP_STRIKETHROUGH_SET,
+		      _("Strikethrough set"),
+		      _("Whether this tag affects strikethrough"));
+	
+	ADD_SET_PROP ("underline_set", PROP_UNDERLINE_SET,
+		      _("Underline set"),
+		      _("Whether this tag affects underlining"));
+#undef ADD_SET_PROP
+	
 	object_class->destroy = gnome_canvas_text_destroy;
 
 	item_class->update = gnome_canvas_text_update;
@@ -281,6 +503,15 @@
 	text->xofs = 0.0;
 	text->yofs = 0.0;
 	text->layout = NULL;
+
+	text->font_desc.family_name = NULL;
+	
+	text->family_set  = FALSE;
+	text->style_set   = FALSE;
+	text->variant_set = FALSE;
+	text->weight_set  = FALSE;
+	text->stretch_set = FALSE;
+	text->size_set    = FALSE;
 }
 
 /* Destroy handler for the text item */
@@ -301,13 +532,16 @@
 	text->text = NULL;
 
 	if (text->layout)
-	  g_object_unref (G_OBJECT (text->layout));
+	    g_object_unref (G_OBJECT (text->layout));
 	text->layout = NULL;
-
-	if (text->font_desc)
-		pango_font_description_free (text->font_desc);
-	text->font_desc = NULL;
+	
+	if (text->font_desc.family_name)
+		g_free (text->font_desc.family_name);
+	text->font_desc.family_name = NULL;
 
+	if (text->attr_list)
+		pango_attr_list_unref (text->attr_list);
+	
 	if (text->stipple)
 		gdk_bitmap_unref (text->stipple);
 	text->stipple = NULL;
@@ -594,6 +828,12 @@
 		recalc_bounds (text);
 		break;
 
+	case PROP_MARKUP:
+		gnome_canvas_text_set_markup (text,
+					      g_value_get_string (value));
+		recalc_bounds (text);
+		break;
+
 	case PROP_X:
 		text->x = g_value_get_double (value);
 		recalc_bounds (text);
@@ -609,27 +849,142 @@
 
 		font_name = g_value_get_string (value);
 		if (font_name) {
-			if (text->font_desc)
-				pango_font_description_free (text->font_desc);
+			PangoFontDescription *font_desc;
 
-			text->font_desc = pango_font_description_from_string (font_name);
-
-			pango_layout_set_font_description (text->layout, text->font_desc);
+			font_desc = pango_font_description_from_string (font_name);
+			gnome_canvas_text_set_font_desc (text, font_desc);
+			pango_font_description_free (font_desc);
+			
+			gnome_canvas_text_apply_font_desc (text);
 			recalc_bounds (text);
+		} else {
+			text->family_set  = FALSE;
+			text->style_set   = FALSE;
+			text->variant_set = FALSE;
+			text->weight_set  = FALSE;
+			text->stretch_set = FALSE;
+			text->size_set    = FALSE;
+
+			gnome_canvas_text_apply_font_desc (text);
 		}
 		break;
 	}
 
 	case PROP_FONT_DESC:
-		if (text->font_desc)
-			pango_font_description_free (text->font_desc);
+		gnome_canvas_text_set_font_desc (
+			text, g_value_peek_pointer (value));
+		
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+
+	case PROP_FAMILY:
+		text->font_desc.family_name = g_strdup (g_value_get_string (value));
+		text->family_set = TRUE;
+		
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+
+	case PROP_FAMILY_SET:
+		text->family_set = g_value_get_boolean (value);
+
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+		
+	case PROP_STYLE:
+		text->font_desc.style = g_value_get_enum (value);
+		text->style_set = TRUE;
+		
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+
+	case PROP_STYLE_SET:
+		text->style_set = g_value_get_boolean (value);
 
-		text->font_desc = g_value_peek_pointer (value);
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+		
+	case PROP_VARIANT:
+		text->font_desc.variant = g_value_get_enum (value);
+		text->variant_set = TRUE;
+		
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+
+	case PROP_VARIANT_SET:
+		text->variant_set = g_value_get_boolean (value);
+
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+		
+	case PROP_WEIGHT:
+		text->font_desc.weight = g_value_get_int (value);
+		text->weight_set = TRUE;
+		
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+
+	case PROP_WEIGHT_SET:
+		text->weight_set = g_value_get_boolean (value);
+
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
 
-		pango_layout_set_font_description (text->layout, text->font_desc);
+	case PROP_STRETCH:
+		text->font_desc.stretch = g_value_get_enum (value);
+		text->stretch_set = TRUE;
+		
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+
+	case PROP_STRETCH_SET:
+		text->stretch_set = g_value_get_boolean (value);
+
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+
+	case PROP_SIZE:
+		text->font_desc.size = g_value_get_int (value);
+		text->size_set = TRUE;
+		
+		gnome_canvas_text_apply_font_desc (text);
 		recalc_bounds (text);
 		break;
 
+	case PROP_SIZE_POINTS:
+		text->font_desc.size = g_value_get_double (value) * PANGO_SCALE;
+		text->size_set = TRUE;
+		
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+		
+	case PROP_SIZE_SET:
+		text->size_set = g_value_get_boolean (value);
+
+		gnome_canvas_text_apply_font_desc (text);
+		recalc_bounds (text);
+		break;
+		
+	case PROP_ATTRIBUTES:
+		if (text->attr_list)
+			pango_attr_list_unref (text->attr_list);
+
+		text->attr_list = g_value_peek_pointer (value);
+
+		pango_layout_set_attributes (text->layout, text->attr_list);
+		recalc_bounds (text);
+
 	case PROP_ANCHOR:
 		text->anchor = g_value_get_enum (value);
 		recalc_bounds (text);
@@ -772,7 +1127,43 @@
 		break;
 
 	case PROP_FONT_DESC:
-		g_value_set_boxed (value, text->font_desc);
+		g_value_set_boxed (value, &(text->font_desc));
+		break;
+
+	case PROP_FAMILY:
+		g_value_set_string (value, text->font_desc.family_name);
+	case PROP_FAMILY_SET:
+		g_value_set_boolean (value, text->family_set);
+		
+	case PROP_STYLE:
+		g_value_set_enum (value, text->font_desc.style);
+	case PROP_STYLE_SET:
+		g_value_set_boolean (value, text->style_set);
+		
+	case PROP_VARIANT:
+		g_value_set_enum (value, text->font_desc.variant);
+	case PROP_VARIANT_SET:
+		g_value_set_boolean (value, text->variant_set);
+		
+	case PROP_WEIGHT:
+		g_value_set_int (value, text->font_desc.weight);
+	case PROP_WEIGHT_SET:
+		g_value_set_boolean (value, text->weight_set);
+		
+	case PROP_STRETCH:
+		g_value_set_enum (value, text->font_desc.stretch);
+	case PROP_STRETCH_SET:
+		g_value_set_boolean (value, text->stretch_set);
+		
+	case PROP_SIZE:
+		g_value_set_int (value, text->font_desc.size);
+	case PROP_SIZE_POINTS:
+		g_value_set_double (value, ((double)text->font_desc.size) / (double)PANGO_SCALE);
+	case PROP_SIZE_SET:
+		g_value_set_boolean (value, text->size_set);
+		
+	case PROP_ATTRIBUTES:
+		g_value_set_boxed (value, text->attr_list);
 		break;
 
 	case PROP_ANCHOR:
@@ -835,6 +1226,81 @@
 	}
 }
 
+/* */
+static void
+gnome_canvas_text_apply_font_desc (GnomeCanvasText *text)
+{
+	PangoFontDescription *font_desc =
+		pango_font_description_copy (
+			GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas)->style->font_desc);
+	
+	if (text->family_set && text->font_desc.family_name)
+	{
+		if (font_desc->family_name)
+			g_free (font_desc->family_name);
+		font_desc->family_name = g_strdup (text->font_desc.family_name);
+	}
+		
+	if (text->style_set)
+		font_desc->style = text->font_desc.style;
+
+	if (text->variant_set)
+		font_desc->variant = text->font_desc.variant;
+
+	if (text->weight_set)
+		font_desc->weight = text->font_desc.weight;
+	
+	if (text->stretch_set)
+		font_desc->stretch = text->font_desc.stretch;
+
+	if (text->size_set)
+		font_desc->size = text->font_desc.size;
+	
+	pango_layout_set_font_description (text->layout,
+					   font_desc);
+	pango_font_description_free (font_desc);
+}
+
+static void
+gnome_canvas_text_set_font_desc (GnomeCanvasText      *text,
+				 PangoFontDescription *font_desc)
+{
+	if (text->font_desc.family_name)
+		g_free (text->font_desc.family_name);
+
+	text->font_desc.family_name = g_strdup (font_desc->family_name);
+
+	text->font_desc.style   = font_desc->style;
+	text->font_desc.variant = font_desc->variant;
+	text->font_desc.weight  = font_desc->weight;
+	text->font_desc.stretch = font_desc->stretch;
+	text->font_desc.size    = font_desc->size;
+	
+	text->family_set  = TRUE;
+	text->style_set   = TRUE;
+	text->variant_set = TRUE;
+	text->weight_set  = TRUE;
+	text->stretch_set = TRUE;
+	text->size_set    = TRUE;
+}
+
+/* Setting the text from a Pango markup string */
+static void
+gnome_canvas_text_set_markup (GnomeCanvasText *textitem,
+			      const gchar     *markup)
+{
+	if (textitem->text)
+		g_free (textitem->text);
+	if (textitem->attr_list)
+		pango_attr_list_unref (textitem->attr_list);
+	
+	pango_layout_set_markup (textitem->layout, markup, -1);
+	
+	textitem->text = g_strdup (pango_layout_get_text (textitem->layout));
+	textitem->attr_list = pango_layout_get_attributes (textitem->layout);
+	pango_attr_list_ref (textitem->attr_list);
+}
+
 /* Update handler for the text item */
 static void
 gnome_canvas_text_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
@@ -905,7 +1371,7 @@
 
 	text = GNOME_CANVAS_TEXT (item);
 
-	if (!text->text || !text->font_desc)
+	if (!text->text)
 		return;
 
 	if (text->clip) {
@@ -941,7 +1407,7 @@
 
 	text = GNOME_CANVAS_TEXT (item);
 
-	if (!text->text || !text->font_desc)
+	if (!text->text)
 		return;
 
 	fg_color = text->rgba >> 8;
Index: libgnomecanvas/gnome-canvas-text.h
===================================================================
RCS file: /cvs/gnome/libgnomecanvas/libgnomecanvas/gnome-canvas-text.h,v
retrieving revision 1.18
diff -u -u -r1.18 gnome-canvas-text.h
--- libgnomecanvas/gnome-canvas-text.h	2001/04/18 23:54:53	1.18
+++ libgnomecanvas/gnome-canvas-text.h	2001/05/05 00:00:46
@@ -52,28 +52,45 @@
  * position.  If used in conjunction with the clipping rectangle, these could be used to implement
  * simple scrolling of the text within the clipping rectangle.
  *
+ * Properties marked with [*] also have _set properties associated
+ * with them, that determine if the specified value should be used
+ * instead of the default (style-defined) values
+ *
  * The following object arguments are available:
  *
  * name			type			read/write	description
  * ------------------------------------------------------------------------------------------
  * text			string			RW		The string of the text label
+ * markup		string			 W		A Pango markup string for the text label
+ *
  * x			double			RW		X coordinate of anchor point
  * y			double			RW		Y coordinate of anchor point
- * font			string			W		A string describing the font
+ *
+ * font			string			 W		A string describing the font
  * font_desc	        PangoFontDescription*	RW		Pointer to a PangoFontDescriptor
+ * attributes           PangoAttrList*          RW		Pointer to a Pango attribute list
+ * style		PangoStyle		RW		Pango style of font to use	[*]
+ * variant		PangoVariant		RW		Pango variant of font to use	[*]
+ * weight		int			RW		Pango weight of font to use	[*]
+ * stretch		PangoStretch		RW		Pango stretch of font to use	[*]
+ * size			int			RW		Size (in pixels) of font	[*]
+ * size_points		double			RW		Size (in points) of font
+ *
  * anchor		GtkAnchorType		RW		Anchor side for the text
  * justification	GtkJustification	RW		Justification for multiline text
- * fill_color		string			W		X color specification for text
- * fill_color_gdk	GdkColor*		RW		Pointer to an allocated GdkColor
- * fill_color_rgba	guint   		RW		RGBA value used for AA color.
- * fill_stipple		GdkBitmap*		RW		Stipple pattern for filling the text
  * clip_width		double			RW		Width of clip rectangle
  * clip_height		double			RW		Height of clip rectangle
  * clip			boolean			RW		Use clipping rectangle?
  * x_offset		double			RW		Horizontal offset distance from anchor position
  * y_offset		double			RW		Vertical offset distance from anchor position
+ *
  * text_width		double			R		Used to query the width of the rendered text
  * text_height		double			R		Used to query the rendered height of the text
+ *
+ * fill_color		string			 W		X color specification for text
+ * fill_color_gdk	GdkColor*		RW		Pointer to an allocated GdkColor
+ * fill_color_rgba	guint   		RW		RGBA value used for AA color.
+ * fill_stipple		GdkBitmap*		RW		Stipple pattern for filling the text
  */
 
 #define GNOME_TYPE_CANVAS_TEXT            (gnome_canvas_text_get_type ())
@@ -90,7 +107,8 @@
 struct _GnomeCanvasText {
 	GnomeCanvasItem item;
 
-	PangoFontDescription *font_desc; /* Font description for text */
+	PangoFontDescription font_desc; /* Font description for text */
+	PangoAttrList *attr_list;       /* Attribute list of the text (caching) */
 	char *text;			/* Text to display */
 	GdkBitmap *stipple;		/* Stipple for text */
 	GdkGC *gc;			/* GC for drawing text */
@@ -119,6 +137,13 @@
         guint32 rgba;			/* RGBA color for text */ /*AA*/
 
 	guint clip : 1;			/* Use clip rectangle? */
+
+	guint family_set  : 1;          /* Use specified font_family? */
+	guint style_set   : 1;          /* Use specified font style? */
+	guint variant_set : 1;          /* Use specified font variant? */
+	guint weight_set  : 1;          /* Use specified font weight? */
+	guint size_set    : 1;          /* Use specified font size? */
+	guint stretch_set : 1;          /* Use specified font stretch? */
 };
 
 struct _GnomeCanvasTextClass {


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