[cairo-commit] libsvg-cairo/src svg_cairo.c,1.39,1.40

Keith Packard commit at pdx.freedesktop.org
Mon Jul 18 14:56:01 PDT 2005


Committed by: keithp

Update of /cvs/cairo/libsvg-cairo/src
In directory gabe:/tmp/cvs-serv9632/src

Modified Files:
	svg_cairo.c 
Log Message:
2005-07-18  Keith Packard  <keithp at keithp.com>

* src/svg_cairo.c: (_svg_cairo_render_text),
(_svg_cairo_render_image), (_svg_cairo_text_extents),
(_svg_cairo_measure_position):
Add primitive support for <tspan> code in libsvg,
this required redoing the text api to measure and
position text in pixels.

Index: svg_cairo.c
===================================================================
RCS file: /cvs/cairo/libsvg-cairo/src/svg_cairo.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- svg_cairo.c	12 Jul 2005 19:37:43 -0000	1.39
+++ svg_cairo.c	18 Jul 2005 21:55:59 -0000	1.40
@@ -20,7 +20,6 @@
  */
 
 #include <stdlib.h>
-#define __USE_SVID
 #include <string.h>
 
 #include "svg-cairo-internal.h"
@@ -172,8 +171,8 @@
 
 static svg_status_t
 _svg_cairo_render_text (void 	      *closure,
-			svg_length_t  *x_len,
-			svg_length_t  *y_len,
+			double	      x,
+			double	      y,
 			const char    *utf8);
 
 static svg_status_t
@@ -187,6 +186,19 @@
 			 svg_length_t	*height);
 
 static svg_status_t
+_svg_cairo_text_extents (void	      *closure,
+			 const char   *utf8,
+			 double	      *x,
+			 double	      *y);
+
+static svg_status_t
+_svg_cairo_measure_position (void	    *closure,
+			     svg_length_t   *ix,
+			     svg_length_t   *iy,
+			     double	    *ox,
+			     double	    *oy);
+			   
+static svg_status_t
 _cairo_status_to_svg_status (cairo_status_t xr_status);
 
 static svg_status_t
@@ -241,7 +253,9 @@
     _svg_cairo_render_ellipse,
     _svg_cairo_render_rect,
     _svg_cairo_render_text,
-    _svg_cairo_render_image
+    _svg_cairo_render_image,
+    _svg_cairo_text_extents,
+    _svg_cairo_measure_position,
 };
 
 svg_cairo_status_t
@@ -1184,12 +1198,11 @@
 
 static svg_status_t
 _svg_cairo_render_text (void *closure,
-			svg_length_t *x_len,
-			svg_length_t *y_len,
+			double x,
+			double y,
 			const char *utf8)
 {
     svg_cairo_t *svg_cairo = closure;
-    double x, y;
     svg_status_t status;
     svg_paint_t *fill_paint, *stroke_paint;
     double rel_x = 0, rel_y = 0;
@@ -1204,9 +1217,6 @@
     if (utf8 == NULL || *utf8 == '\0')
 	return SVG_STATUS_SUCCESS;
 
-    _svg_cairo_length_to_pixel (svg_cairo, x_len, &x);
-    _svg_cairo_length_to_pixel (svg_cairo, y_len, &y);
-
     status = _svg_cairo_move_to (svg_cairo, x, y);
     if (status)
 	return status;
@@ -1309,7 +1319,10 @@
     cairo_scale (svg_cairo->cr, width / data_width, height / data_height);
 
     cairo_set_source_surface (svg_cairo->cr, surface, 0, 0);
-    cairo_paint_with_alpha (svg_cairo->cr, svg_cairo->state->opacity);
+    if (svg_cairo->state->opacity != 1.0)
+	cairo_paint_with_alpha (svg_cairo->cr, svg_cairo->state->opacity);
+    else
+	cairo_paint (svg_cairo->cr);
     
     cairo_surface_destroy (surface);
 
@@ -1330,6 +1343,53 @@
     }
 }
 
+static svg_status_t
+_svg_cairo_text_extents (void	      *closure,
+			 const char   *utf8,
+			 double	      *x,
+			 double	      *y)
+{
+    svg_cairo_t *svg_cairo = closure;
+
+#if HAVE_PANGOCAIRO
+    PangoRectangle log;
+    PangoLayout *layout;
+    PangoLayoutLine *line;
+    
+    layout = pango_cairo_create_layout (svg_cairo->cr);
+    pango_layout_set_font_description (layout, svg_cairo->state->font_description);
+    pango_layout_set_text (layout, utf8, -1);
+    line = pango_layout_get_lines (layout)->data;
+    pango_layout_get_extents (layout, NULL, &log);
+    *x = (double) log.width / PANGO_SCALE;
+    *y = 0;
+    g_object_unref (layout);
+#else
+    cairo_text_extents_t extents;
+    
+    _svg_cairo_select_font (svg_cairo);
+    cairo_text_extents (svg_cairo->cr, utf8, &extents);
+    *x = extents.x_advance;
+    *y = extents.y_advance;
+#endif
+    return SVG_STATUS_SUCCESS;
+}
+
+static svg_status_t
+_svg_cairo_measure_position (void	    *closure,
+			     svg_length_t   *ix,
+			     svg_length_t   *iy,
+			     double	    *ox,
+			     double	    *oy)
+{
+    svg_cairo_t *svg_cairo = closure;
+
+    _svg_cairo_length_to_pixel (svg_cairo, ix, ox);
+    _svg_cairo_length_to_pixel (svg_cairo, iy, oy);
+
+    return SVG_STATUS_SUCCESS;
+}
+			   
 static void
 _svg_cairo_copy_cairo_state (svg_cairo_t *svg_cairo,
 			     cairo_t     *old_cr,




More information about the cairo-commit mailing list