[cairo-commit] goocanvas/src goocanvasitemsimple.c, 1.24, 1.25 goocanvasstyle.c, 1.5, 1.6 goocanvasstyle.h, 1.4, 1.5 goocanvastext.c, 1.14, 1.15 goocanvastext.h, 1.5, 1.6 goocanvasutils.c, 1.11, 1.12 goocanvasutils.h, 1.12, 1.13

Damon Chaplin commit at pdx.freedesktop.org
Sun Feb 25 10:25:59 PST 2007


Committed by: damon

Update of /cvs/cairo/goocanvas/src
In directory kemper:/tmp/cvs-serv10013/src

Modified Files:
	goocanvasitemsimple.c goocanvasstyle.c goocanvasstyle.h 
	goocanvastext.c goocanvastext.h goocanvasutils.c 
	goocanvasutils.h 
Log Message:
2007-02-25  Damon Chaplin  <damon at gnome.org>

	* src/goocanvasitemsimple.c: added "hint-metrics" property so people
	can use hinted metrics for prettier text if they aren't scaling the
	canvas at all.
	
	* src/goocanvasstyle.c: added goo_canvas_style_hint_metrics_id quark.

	* src/goocanvasutils.c (goo_cairo_hint_metrics_get_type): added enum
	stuff for cairo_hint_metrics_t.

	* src/goocanvastext.c (goo_canvas_text_create_layout): use hint metrics
	property.



Index: goocanvasitemsimple.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitemsimple.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- goocanvasitemsimple.c	25 Feb 2007 17:57:38 -0000	1.24
+++ goocanvasitemsimple.c	25 Feb 2007 18:25:52 -0000	1.25
@@ -58,6 +58,7 @@
   /* Font properties. */
   PROP_FONT,
   PROP_FONT_DESC,
+  PROP_HINT_METRICS,
 
   /* Convenience properties. */
   PROP_STROKE_COLOR,
@@ -195,6 +196,14 @@
 						       PANGO_TYPE_FONT_DESCRIPTION,
 						       G_PARAM_READWRITE));
 
+  g_object_class_install_property (gobject_class, PROP_HINT_METRICS,
+				   g_param_spec_enum ("hint-metrics",
+						      _("Hint Metrics"),
+						      _("The hinting to be used for font metrics"),
+						      GOO_TYPE_CAIRO_HINT_METRICS,
+						      CAIRO_HINT_METRICS_OFF,
+						      G_PARAM_READWRITE));
+
   /* Convenience properties - writable only. */
   g_object_class_install_property (gobject_class, PROP_STROKE_COLOR,
 				   g_param_spec_string ("stroke-color",
@@ -471,6 +480,10 @@
       svalue = goo_canvas_style_get_property (style, goo_canvas_style_font_desc_id);
       g_value_set_boxed (value, svalue ? svalue->data[0].v_pointer : NULL);
       break;
+    case PROP_HINT_METRICS:
+      svalue = goo_canvas_style_get_property (style, goo_canvas_style_hint_metrics_id);
+      g_value_set_enum (value, svalue ? svalue->data[0].v_long : CAIRO_HINT_METRICS_OFF);
+      break;
 
       /* Other properties. */
     case PROP_TRANSFORM:
@@ -622,6 +635,10 @@
       goo_canvas_style_set_property (style, goo_canvas_style_font_desc_id, value);
       recompute_bounds = TRUE;
       break;
+    case PROP_HINT_METRICS:
+      goo_canvas_style_set_property (style, goo_canvas_style_hint_metrics_id, value);
+      recompute_bounds = TRUE;
+      break;
 
       /* Convenience properties. */
     case PROP_STROKE_COLOR:

Index: goocanvasstyle.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasstyle.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- goocanvasstyle.c	25 Feb 2007 17:37:57 -0000	1.5
+++ goocanvasstyle.c	25 Feb 2007 18:25:52 -0000	1.6
@@ -105,6 +105,13 @@
  **/
 GQuark goo_canvas_style_font_desc_id;
 
+/**
+ * goo_canvas_style_hint_metrics_id:
+ * 
+ * Unique #GQuark identifier used for the standard hint metrics property.
+ **/
+GQuark goo_canvas_style_hint_metrics_id;
+
 static void goo_canvas_style_dispose  (GObject *object);
 static void goo_canvas_style_finalize (GObject *object);
 
@@ -133,6 +140,7 @@
       goo_canvas_style_line_join_miter_limit_id = g_quark_from_static_string ("GooCanvasStyle:line_join_miter_limit");
       goo_canvas_style_line_dash_id = g_quark_from_static_string ("GooCanvasStyle:line_dash");
       goo_canvas_style_font_desc_id = g_quark_from_static_string ("GooCanvasStyle:font_desc");
+      goo_canvas_style_hint_metrics_id = g_quark_from_static_string ("GooCanvasStyle:hint_metrics");
 
       initialized = TRUE;
     }

Index: goocanvasstyle.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasstyle.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- goocanvasstyle.h	9 Feb 2007 13:41:03 -0000	1.4
+++ goocanvasstyle.h	25 Feb 2007 18:25:52 -0000	1.5
@@ -24,6 +24,7 @@
 extern GQuark goo_canvas_style_line_join_miter_limit_id;
 extern GQuark goo_canvas_style_line_dash_id;
 extern GQuark goo_canvas_style_font_desc_id;
+extern GQuark goo_canvas_style_hint_metrics_id;
 
 
 /**

Index: goocanvastext.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvastext.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- goocanvastext.c	25 Feb 2007 17:37:57 -0000	1.14
+++ goocanvastext.c	25 Feb 2007 18:25:52 -0000	1.15
@@ -348,15 +348,13 @@
   double logical_width, logical_height, align_width, origin_x, origin_y;
   gchar *string;
   double x1_extension, x2_extension, y1_extension, y2_extension;
+  cairo_font_options_t *font_options;
+  cairo_hint_metrics_t hint_metrics = CAIRO_HINT_METRICS_OFF;
 
   string = text_data->text ? text_data->text : "";
 
   layout = pango_cairo_create_layout (cr);
-
-  /* Set the font options to ensure the text layout is the same whatever
-     the scale is. */
   context = pango_layout_get_context (layout);
-  pango_cairo_context_set_font_options (context, GOO_CANVAS_TEXT_GET_CLASS (text)->font_options);
 
   if (text_data->width > 0)
     pango_layout_set_width (layout, (double) text_data->width * PANGO_SCALE);
@@ -366,10 +364,22 @@
   else
     pango_layout_set_text (layout, string, -1);
 
-  svalue = goo_canvas_style_get_property (style, goo_canvas_style_font_desc_id);
+  svalue = goo_canvas_style_get_property (style,
+					  goo_canvas_style_font_desc_id);
   if (svalue)
     pango_layout_set_font_description (layout, svalue->data[0].v_pointer);
 
+  svalue = goo_canvas_style_get_property (style,
+					  goo_canvas_style_hint_metrics_id);
+  if (svalue)
+    hint_metrics = svalue->data[0].v_long;
+
+  font_options = cairo_font_options_create ();
+  cairo_font_options_set_hint_metrics (font_options, hint_metrics);
+  cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
+  pango_cairo_context_set_font_options (context, font_options);
+  cairo_font_options_destroy (font_options);
+
   if (text_data->alignment != PANGO_ALIGN_LEFT)
     pango_layout_set_alignment (layout, text_data->alignment);
 
@@ -652,13 +662,6 @@
   simple_class->simple_get_item_at   = goo_canvas_text_get_item_at;
 
   goo_canvas_text_install_common_properties (gobject_class);
-
-  /* Create the font options once and reuse it. */
-  klass->font_options = cairo_font_options_create ();
-  cairo_font_options_set_hint_metrics (klass->font_options,
-				       CAIRO_HINT_METRICS_OFF);
-  cairo_font_options_set_hint_style (klass->font_options,
-				     CAIRO_HINT_STYLE_NONE);
 }
 
 

Index: goocanvastext.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvastext.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- goocanvastext.h	9 Feb 2007 13:41:03 -0000	1.5
+++ goocanvastext.h	25 Feb 2007 18:25:52 -0000	1.6
@@ -53,9 +53,6 @@
 {
   GooCanvasItemSimpleClass parent_class;
 
-  /* The font options we always use. */
-  cairo_font_options_t *font_options;
-
   /*< private >*/
 
   /* Padding for future expansion */

Index: goocanvasutils.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasutils.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- goocanvasutils.c	25 Feb 2007 17:37:57 -0000	1.11
+++ goocanvasutils.c	25 Feb 2007 18:25:52 -0000	1.12
@@ -308,6 +308,23 @@
 }
 
 
+GType
+goo_cairo_hint_metrics_get_type (void)
+{
+  static GType etype = 0;
+  if (etype == 0) {
+    static const GEnumValue values[] = {
+      { CAIRO_HINT_METRICS_DEFAULT, "CAIRO_HINT_METRICS_DEFAULT", "default" },
+      { CAIRO_HINT_METRICS_OFF, "CAIRO_HINT_METRICS_OFF", "off" },
+      { CAIRO_HINT_METRICS_ON, "CAIRO_HINT_METRICS_ON", "on" },
+      { 0, NULL, NULL }
+    };
+    etype = g_enum_register_static ("GooCairoHintMetrics", values);
+  }
+  return etype;
+}
+
+
 /**
  * goo_canvas_line_dash_ref:
  * @dash: a #GooCanvasLineDash.

Index: goocanvasutils.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasutils.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- goocanvasutils.h	25 Feb 2007 17:37:57 -0000	1.12
+++ goocanvasutils.h	25 Feb 2007 18:25:52 -0000	1.13
@@ -238,6 +238,9 @@
 #define GOO_TYPE_CAIRO_LINE_JOIN   (goo_cairo_line_join_get_type ())
 GType		   goo_cairo_line_join_get_type (void) G_GNUC_CONST;
 
+#define GOO_TYPE_CAIRO_HINT_METRICS (goo_cairo_hint_metrics_get_type ())
+GType		   goo_cairo_hint_metrics_get_type (void) G_GNUC_CONST;
+
 
 G_END_DECLS
 



More information about the cairo-commit mailing list