[cairo-commit] goocanvas/src goocanvas.c, 1.25, 1.26 goocanvastext.c, 1.20, 1.21 goocanvastext.h, 1.9, 1.10
Damon Chaplin
commit at pdx.freedesktop.org
Mon Feb 25 06:11:30 PST 2008
Committed by: damon
Update of /cvs/cairo/goocanvas/src
In directory kemper:/tmp/cvs-serv15393/src
Modified Files:
goocanvas.c goocanvastext.c goocanvastext.h
Log Message:
2008-02-25 Damon Chaplin <damon at gnome.org>
* src/goocanvastext.c (goo_canvas_text_get_natural_extents)
(goo_canvas_text_model_get_natural_extents): added functions to get
the natural extents of the text.
Index: goocanvas.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvas.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- goocanvas.c 18 Nov 2007 14:26:20 -0000 1.25
+++ goocanvas.c 25 Feb 2008 14:12:25 -0000 1.26
@@ -579,6 +579,9 @@
{
gdouble line_width = 2.0;
+ if (!canvas)
+ return 2.0;
+
/* We use the same default as cairo when using pixels, i.e. 2 pixels.
For other units we use 2 points, or thereabouts. */
switch (canvas->units)
@@ -618,7 +621,7 @@
/* If the canvas is realized we can use the GDK function to create a cairo
context for the canvas window. Otherwise we create a small temporary
image surface. */
- if (canvas->canvas_window)
+ if (canvas && canvas->canvas_window)
{
cr = gdk_cairo_create (canvas->canvas_window);
}
Index: goocanvastext.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvastext.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- goocanvastext.c 13 Aug 2007 11:33:15 -0000 1.20
+++ goocanvastext.c 25 Feb 2008 14:12:25 -0000 1.21
@@ -365,15 +365,14 @@
static PangoLayout*
-goo_canvas_text_create_layout (GooCanvasText *text,
- cairo_t *cr,
- GooCanvasBounds *bounds,
- gdouble *origin_x_return,
- gdouble *origin_y_return)
+goo_canvas_text_create_layout (GooCanvasItemSimpleData *simple_data,
+ GooCanvasTextData *text_data,
+ gdouble layout_width,
+ cairo_t *cr,
+ GooCanvasBounds *bounds,
+ gdouble *origin_x_return,
+ gdouble *origin_y_return)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) text;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
- GooCanvasTextData *text_data = text->text_data;
GooCanvasStyle *style = simple_data->style;
GValue *svalue;
PangoLayout *layout;
@@ -390,8 +389,8 @@
layout = pango_cairo_create_layout (cr);
context = pango_layout_get_context (layout);
- if (text->layout_width > 0)
- pango_layout_set_width (layout, (double) text->layout_width * PANGO_SCALE);
+ if (layout_width > 0)
+ pango_layout_set_width (layout, (double) layout_width * PANGO_SCALE);
if (text_data->use_markup)
pango_layout_set_markup (layout, string, -1);
@@ -544,8 +543,9 @@
text->layout_width = text->text_data->width;
/* Compute the new bounds. */
- layout = goo_canvas_text_create_layout (text, cr, &simple->bounds,
- NULL, NULL);
+ layout = goo_canvas_text_create_layout (simple->simple_data, text->text_data,
+ text->layout_width, cr,
+ &simple->bounds, NULL, NULL);
g_object_unref (layout);
}
@@ -592,7 +592,8 @@
&& goo_canvas_text_is_unpainted (simple_data->style))
return FALSE;
- layout = goo_canvas_text_create_layout (text, cr, &bounds,
+ layout = goo_canvas_text_create_layout (simple_data, text->text_data,
+ text->layout_width, cr, &bounds,
&origin_x, &origin_y);
/* Convert the coordinates into Pango units. */
@@ -654,7 +655,9 @@
goo_canvas_style_set_fill_options (simple->simple_data->style, cr);
cairo_new_path (cr);
- layout = goo_canvas_text_create_layout (text, cr, &layout_bounds,
+ layout = goo_canvas_text_create_layout (simple->simple_data, text->text_data,
+ text->layout_width, cr,
+ &layout_bounds,
&origin_x, &origin_y);
cairo_move_to (cr, origin_x, origin_y);
pango_cairo_show_layout (cr, layout);
@@ -691,8 +694,9 @@
text->layout_width /= simple_data->transform->xx;
/* Create layout with given width. */
- layout = goo_canvas_text_create_layout (text, cr, &simple->bounds,
- NULL, NULL);
+ layout = goo_canvas_text_create_layout (simple_data, text->text_data,
+ text->layout_width, cr,
+ &simple->bounds, NULL, NULL);
g_object_unref (layout);
/* Convert to the parent's coordinate space. As above, we only need to
@@ -711,6 +715,36 @@
}
+/**
+ * goo_canvas_text_get_natural_extents:
+ * @text: a #GooCanvasText.
+ * @ink_rect: the location to return the ink rect, or %NULL.
+ * @logical_rect: the location to return the logical rect, or %NULL.
+ *
+ * Gets the natural extents of the text, in the text item's coordinate space.
+ *
+ * The final extents of the text may be different, if the text item is placed
+ * in a layout container such as #GooCanvasTable.
+ **/
+void
+goo_canvas_text_get_natural_extents (GooCanvasText *text,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect)
+{
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) text;
+ PangoLayout *layout;
+ cairo_t *cr;
+
+ cr = goo_canvas_create_cairo_context (simple->canvas);
+ layout = goo_canvas_text_create_layout (simple->simple_data, text->text_data,
+ text->text_data->width, cr, NULL,
+ NULL, NULL);
+ pango_layout_get_extents (layout, ink_rect, logical_rect);
+ g_object_unref (layout);
+ cairo_destroy (cr);
+}
+
+
static void
goo_canvas_text_set_model (GooCanvasItem *item,
GooCanvasItemModel *model)
@@ -947,6 +981,37 @@
}
+/**
+ * goo_canvas_text_model_get_natural_extents:
+ * @tmodel: a #GooCanvasTextModel.
+ * @ink_rect: the location to return the ink rect, or %NULL.
+ * @logical_rect: the location to return the logical rect, or %NULL.
+ *
+ * Gets the natural extents of the text, in the text item's coordinate space.
+ *
+ * The final extents of the text may be different, if the text item is placed
+ * in a layout container such as #GooCanvasTable.
+ **/
+void
+goo_canvas_text_model_get_natural_extents (GooCanvasTextModel *tmodel,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect)
+{
+ GooCanvasItemModelSimple *smodel = (GooCanvasItemModelSimple*) tmodel;
+ PangoLayout *layout;
+ cairo_t *cr;
+
+ cr = goo_canvas_create_cairo_context (NULL);
+ layout = goo_canvas_text_create_layout (&smodel->simple_data,
+ &tmodel->text_data,
+ tmodel->text_data.width,
+ cr, NULL, NULL, NULL);
+ pango_layout_get_extents (layout, ink_rect, logical_rect);
+ g_object_unref (layout);
+ cairo_destroy (cr);
+}
+
+
static void
item_model_interface_init (GooCanvasItemModelIface *iface)
{
Index: goocanvastext.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvastext.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- goocanvastext.h 13 Aug 2007 11:33:15 -0000 1.9
+++ goocanvastext.h 25 Feb 2008 14:12:25 -0000 1.10
@@ -75,6 +75,9 @@
GtkAnchorType anchor,
...);
+void goo_canvas_text_get_natural_extents (GooCanvasText *text,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect);
#define GOO_TYPE_CANVAS_TEXT_MODEL (goo_canvas_text_model_get_type ())
@@ -124,6 +127,10 @@
GtkAnchorType anchor,
...);
+void goo_canvas_text_model_get_natural_extents (GooCanvasTextModel *tmodel,
+ PangoRectangle *ink_rect,
+ PangoRectangle *logical_rect);
+
G_END_DECLS
More information about the cairo-commit
mailing list