Re: The future of GdkFont declarations



On 2 May 2001, Havoc Pennington wrote:

> To do this it looks like you need to fix GnomeCanvasText; it should
> have similar parameters to GtkLabel/GtkCellRendererText/GtkTextTag. At
> minimum a "markup" property, probably also the weight, style, stretch,
> etc. stuff; should just cut-and-paste from the cell renderer so you
> get exactly the same property names and types.

Something like the attached patch?

Notes:
	* It uses a glib box for PangoAttrList which is not defined in
GTK+. I modified my local GTK+ copy to get it to compile -- Martin told me
on iRC that the Pango types should be eventually defined in Pango itself
(which sounds quite logical to me) and that they are looking for someone
to do this. Does it involve more than writing the .defs files for boxed
types?
	* It doesn't have all the properties from GtkCellRendererText
because I didn't want to bother until you tell me I am on the right track
at all with the current patch
	* I have no idea why it doesn't affect the AA canvas (at least
when I modified canvas-primitives.c to see if anything happens, <span
foreground="red"> only worked in the non-AA canvas)

Bye,
	Cactus

-- 
   .--= ULLA! =---------------------.   `We are not here to give users what
   \     http://cactus.rulez.org     \   they want'  -- RMS, at GUADEC 2001
    `---= cactus cactus rulez org =---'
Sometimes I think I'd be better off dead. No, wait. Not me, you.
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/03 18:48:54
@@ -1,3 +1,11 @@
+2001-05-03  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
+	attr_list: A read/writeable Pango attribute list of the rendered
+	text
+
 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/03 18:49:19
@@ -49,10 +49,12 @@
 enum {
 	PROP_0,
 	PROP_TEXT,
+	PROP_TEXT_MARKUP,
 	PROP_X,
 	PROP_Y,
 	PROP_FONT,
 	PROP_FONT_DESC,
+	PROP_ATTR_LIST,
 	PROP_ANCHOR,
 	PROP_JUSTIFICATION,
 	PROP_CLIP_WIDTH,
@@ -93,6 +95,9 @@
 				      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 GnomeCanvasItemClass *parent_class;
 
 
@@ -154,6 +159,12 @@
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
+                 PROP_TEXT_MARKUP,
+                 g_param_spec_string ("text_markup", NULL, NULL,
+                                      NULL,
+                                      (G_PARAM_WRITABLE)));
+        g_object_class_install_property
+                (gobject_class,
                  PROP_X,
                  g_param_spec_double ("x", NULL, NULL,
 				      -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
@@ -178,6 +189,12 @@
 				     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
+                 PROP_ATTR_LIST,
+                 g_param_spec_boxed ("attr_list", NULL, NULL,
+				     GTK_TYPE_PANGO_ATTR_LIST,
+				     (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,
@@ -308,6 +325,9 @@
 		pango_font_description_free (text->font_desc);
 	text->font_desc = 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 +614,12 @@
 		recalc_bounds (text);
 		break;
 
+	case PROP_TEXT_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);
@@ -630,6 +656,15 @@
 		recalc_bounds (text);
 		break;
 
+	case PROP_ATTR_LIST:
+		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);
@@ -775,6 +810,10 @@
 		g_value_set_boxed (value, text->font_desc);
 		break;
 
+	case PROP_ATTR_LIST:
+		g_value_set_boxed (value, text->attr_list);
+		break;
+
 	case PROP_ANCHOR:
 		g_value_set_enum (value, text->anchor);
 		break;
@@ -833,6 +872,22 @@
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 		break;
 	}
+}
+
+/* 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_attr_list_copy (pango_layout_get_attributes (textitem->layout));
 }
 
 /* Update handler for the text item */
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/03 18:49:22
@@ -57,13 +57,15 @@
  * name			type			read/write	description
  * ------------------------------------------------------------------------------------------
  * text			string			RW		The string of the text label
+ * text_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
+ * attr_list            PangoAttrList*          RW		Pointer to a Pango attribute list
  * 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		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
@@ -91,6 +93,7 @@
 	GnomeCanvasItem item;
 
 	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 */


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