[cairo-commit] cairo-demo/png ChangeLog, 1.25, 1.26 Makefile, 1.14, 1.15 bevels.c, 1.3, 1.4 caps_joins.c, 1.3, 1.4 hering.c, 1.3, 1.4 outline.c, 1.6, 1.7 snapping.c, 1.5, 1.6 spiral.c, 1.3, 1.4 splines_tolerance.c, 1.3, 1.4 star_and_ring.c, 1.1, 1.2 stars.c, 1.3, 1.4 text-rotate.c, 1.3, 1.4 text.c, 1.8, 1.9

Carl Worth commit at pdx.freedesktop.org
Tue May 17 07:31:45 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo-demo/png
In directory gabe:/tmp/cvs-serv736

Modified Files:
	ChangeLog Makefile bevels.c caps_joins.c hering.c outline.c 
	snapping.c spiral.c splines_tolerance.c star_and_ring.c 
	stars.c text-rotate.c text.c 
Log Message:

        * Makefile:
        * bevels.c: (set_hex_color), (main):
        * caps_joins.c: (main), (stroke_v_twice), (draw_caps_joins):
        * hering.c: (main), (draw_hering):
        * outline.c: (main), (create_gradient), (draw_outlines):
        * snapping.c: (snap_point_for_fill), (snap_point_for_stroke),
        (snap_line_width), (snap_path_for_fill), (snap_path_for_stroke),
        (draw_nested), (main):
        * spiral.c: (main), (draw_spiral):
        * splines_tolerance.c: (main), (draw_splines):
        * star_and_ring.c: (star_path), (fill_ring), (fill_star), (main):
        * stars.c: (main), (draw_stars):
        * text-rotate.c: (main):
        * text.c: (box_text), (box_glyphs), (main):
        Update all programs to match recent cairo API changes.


Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/ChangeLog,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- ChangeLog	2 Apr 2005 04:20:39 -0000	1.25
+++ ChangeLog	17 May 2005 14:31:42 -0000	1.26
@@ -1,3 +1,21 @@
+2005-05-17  Carl Worth  <cworth at cworth.org>
+
+	* Makefile:
+	* bevels.c: (set_hex_color), (main):
+	* caps_joins.c: (main), (stroke_v_twice), (draw_caps_joins):
+	* hering.c: (main), (draw_hering):
+	* outline.c: (main), (create_gradient), (draw_outlines):
+	* snapping.c: (snap_point_for_fill), (snap_point_for_stroke),
+	(snap_line_width), (snap_path_for_fill), (snap_path_for_stroke),
+	(draw_nested), (main):
+	* spiral.c: (main), (draw_spiral):
+	* splines_tolerance.c: (main), (draw_splines):
+	* star_and_ring.c: (star_path), (fill_ring), (fill_star), (main):
+	* stars.c: (main), (draw_stars):
+	* text-rotate.c: (main):
+	* text.c: (box_text), (box_glyphs), (main):
+	Update all programs to match recent cairo API changes.
+
 2005-04-01  Carl Worth  <cworth at cworth.org>
 
 	* caps_joins.c:

Index: Makefile
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/Makefile,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- Makefile	18 Mar 2005 15:26:53 -0000	1.14
+++ Makefile	17 May 2005 14:31:42 -0000	1.15
@@ -17,10 +17,8 @@
 %.o: %.c
 	$(CC) -c $(CFLAGS) $(CPPFLAGS) ${MYCFLAGS} $< -o $@
 
-%: %.c write_png.o
+%: %.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) ${MYCFLAGS} ${MYLDFLAGS} $^ -o $@
 
-write_png.o: write_png.c write_png.h
-
 clean:
 	rm -f ${EXAMPLES} *.o *.png

Index: bevels.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/bevels.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- bevels.c	18 Oct 2004 22:37:34 -0000	1.3
+++ bevels.c	17 May 2005 14:31:43 -0000	1.4
@@ -53,6 +53,7 @@
 
 #include <cairo.h>
 #include <math.h>
+#include <stdint.h>
 
 #include "write_png.h"
 
@@ -60,7 +61,7 @@
 #define HEIGHT 70
 #define STRIDE (WIDTH * 4)
 
-char image[STRIDE*HEIGHT];
+unsigned char image[STRIDE*HEIGHT];
 
 typedef struct hex_color
 {
@@ -77,7 +78,7 @@
 static void
 set_hex_color (cairo_t *cr, hex_color_t color)
 {
-    cairo_set_rgb_color (cr,
+    cairo_set_source_rgb (cr,
 			 color.r / 255.0,
 			 color.g / 255.0,
 			 color.b / 255.0);
@@ -291,11 +292,11 @@
 main (void)
 {
     cairo_t *cr;
+    cairo_surface_t *surface;
 
-    cr = cairo_create ();
-
-    cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32,
-		      WIDTH, HEIGHT, STRIDE);
+    surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32,
+						   WIDTH, HEIGHT, STRIDE);
+    cr = cairo_create (surface);
 
     cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
     set_hex_color (cr, BG_COLOR);
@@ -303,10 +304,12 @@
 
     draw_bevels (cr, WIDTH, HEIGHT);
 
-    write_png_argb32 (image, "bevels.png", WIDTH, HEIGHT, STRIDE);
+    cairo_surface_write_to_png (surface, "bevels.png");
 
     cairo_destroy (cr);
 
+    cairo_surface_destroy (surface);
+
     return 0;
 }
 

Index: caps_joins.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/caps_joins.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- caps_joins.c	2 Apr 2005 04:20:39 -0000	1.3
+++ caps_joins.c	17 May 2005 14:31:43 -0000	1.4
@@ -42,28 +42,31 @@
 #define HEIGHT 600
 #define STRIDE (WIDTH * 4)
 
-char image[STRIDE*HEIGHT];
+unsigned char image[STRIDE*HEIGHT];
 
 int
 main (void)
 {
+    cairo_surface_t *surface;
     cairo_t *cr;
 
-    cr = cairo_create ();
+    surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32,
+						   WIDTH, HEIGHT, STRIDE);
 
-    cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32,
-		      WIDTH, HEIGHT, STRIDE);
+    cr = cairo_create (surface);
 
     cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
-    cairo_set_rgb_color (cr, 1, 1, 1);
+    cairo_set_source_rgb (cr, 1, 1, 1);
     cairo_fill (cr);
 
     draw_caps_joins (cr, WIDTH, HEIGHT);
 
-    write_png_argb32 (image, "caps_joins.png", WIDTH, HEIGHT, STRIDE);
+    cairo_surface_write_to_png (surface, "caps_joins.png");
 
     cairo_destroy (cr);
 
+    cairo_surface_destroy (surface);
+
     return 0;
 }
 
@@ -82,7 +85,7 @@
     {
 	cairo_set_line_width (cr, 2.0);
 	cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
-	cairo_set_rgb_color (cr, 1, 1, 1);
+	cairo_set_source_rgb (cr, 1, 1, 1);
 	cairo_stroke (cr);
     }
     cairo_restore (cr);
@@ -96,7 +99,7 @@
     int line_width = height / 12 & (~1);
 
     cairo_set_line_width (cr, line_width);
-    cairo_set_rgb_color (cr, 0, 0, 0);
+    cairo_set_source_rgb (cr, 0, 0, 0);
 
     cairo_translate (cr, line_width, line_width);
     width -= 2 *line_width;

Index: hering.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/hering.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- hering.c	2 Apr 2005 04:20:39 -0000	1.3
+++ hering.c	17 May 2005 14:31:43 -0000	1.4
@@ -37,28 +37,30 @@
 #define HEIGHT 600
 #define STRIDE (WIDTH * 4)
 
-char image[STRIDE*HEIGHT];
+unsigned char image[STRIDE*HEIGHT];
 
 int
 main (void)
 {
+    cairo_surface_t *surface;
     cairo_t *cr;
 
-    cr = cairo_create ();
-
-    cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32,
-		      WIDTH, HEIGHT, STRIDE);
+    surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32,
+						   WIDTH, HEIGHT, STRIDE);
+    cr = cairo_create (surface);
 
     cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
-    cairo_set_rgb_color (cr, 1, 1, 1);
+    cairo_set_source_rgb (cr, 1, 1, 1);
     cairo_fill (cr);
 
     draw_hering (cr, WIDTH, HEIGHT);
 
-    write_png_argb32 (image, "hering.png", WIDTH, HEIGHT, STRIDE);
+    cairo_surface_write_to_png (surface, "hering.png");
 
     cairo_destroy (cr);
 
+    cairo_surface_destroy (surface);
+
     return 0;
 }
 
@@ -71,7 +73,7 @@
 
     int i;
 
-    cairo_set_rgb_color (cr, 0, 0, 0);
+    cairo_set_source_rgb (cr, 0, 0, 0);
     cairo_set_line_width (cr, 2.0);
 
     cairo_save (cr);
@@ -90,7 +92,7 @@
     cairo_restore (cr);
 
     cairo_set_line_width (cr, 6);
-    cairo_set_rgb_color (cr, 1, 0, 0);
+    cairo_set_source_rgb (cr, 1, 0, 0);
 
     cairo_move_to (cr, width / 4, 0);
     cairo_rel_line_to (cr, 0, height);

Index: outline.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/outline.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- outline.c	2 Apr 2005 04:20:39 -0000	1.6
+++ outline.c	17 May 2005 14:31:43 -0000	1.7
@@ -48,71 +48,50 @@
 #define HEIGHT 500
 #define STRIDE (WIDTH * 4)
 
-char image[STRIDE*HEIGHT];
+unsigned char image[STRIDE*HEIGHT];
 
 int
 main (void)
 {
+    cairo_surface_t *surface;
     cairo_t *cr;
 
-    cr = cairo_create ();
-
-    cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32,
-		      WIDTH, HEIGHT, STRIDE);
+    surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32,
+						   WIDTH, HEIGHT, STRIDE);
+    cr = cairo_create (surface);
 
     cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
-    cairo_set_rgb_color (cr, 1, 1, 1);
+    cairo_set_source_rgb (cr, 1, 1, 1);
     cairo_fill (cr);
 
     draw_outlines (cr, WIDTH, HEIGHT);
 
-    write_png_argb32 (image, "outline.png", WIDTH, HEIGHT, STRIDE);
+    cairo_surface_write_to_png (surface, "outline.png");
 
     cairo_destroy (cr);
 
+    cairo_surface_destroy (surface);
+
     return 0;
 }
 
 cairo_pattern_t *
 create_gradient (cairo_t *cr, double width, double height)
 {
-    cairo_surface_t *gradient;
-    cairo_matrix_t *matrix;
-    cairo_pattern_t *gradient_pattern;
-
-    cairo_save (cr);
-
-    gradient = cairo_surface_create_similar (cairo_current_target_surface (cr),
-					     CAIRO_FORMAT_ARGB32,
-					     3, 2);
-    cairo_set_target_surface (cr, gradient);
-
-    cairo_set_rgb_color (cr, 0, 0, 0);
-    cairo_rectangle (cr, 0, 0, 1, 2);
-    cairo_fill (cr);
+    cairo_pattern_t *gradient;
 
-    cairo_set_rgb_color (cr, 1, 1, 1);
-    cairo_rectangle (cr, 1, 0, 1, 2);
-    cairo_fill (cr);
+    gradient = cairo_pattern_create_linear (0, 0, width, 0);
 
-    cairo_set_rgb_color (cr, 0, 0, 0);
-    cairo_rectangle (cr, 2, 0, 1, 2);
-    cairo_fill (cr);
+    cairo_pattern_add_color_stop_rgb (gradient, 0.0,
+				      0., 0., 0.);
 
-    cairo_restore (cr);
+    cairo_pattern_add_color_stop_rgb (gradient, 0.5,
+				      1., 1., 1.);
 
-    matrix = cairo_matrix_create ();
-    cairo_matrix_scale (matrix,
-		   2.0 / width,
-		   1.0 / height);
-    
-    gradient_pattern = cairo_pattern_create_for_surface (gradient);
-    cairo_surface_destroy (gradient);
-    cairo_pattern_set_matrix (gradient_pattern, matrix);
-    cairo_pattern_set_filter (gradient_pattern, CAIRO_FILTER_BILINEAR);
-    cairo_matrix_destroy (matrix);
+    cairo_pattern_add_color_stop_rgb (gradient, 1.0,
+				      0., 0., 0.);
 
-    return gradient_pattern;
+    return gradient;
 }
 
 void
@@ -127,15 +106,15 @@
 
     gradient = create_gradient (cr, width, height);
 
-    cairo_set_pattern (cr, gradient);
+    cairo_set_source (cr, gradient);
     draw_flat (cr, width, height);
 
     cairo_translate (cr, width + pad, 0);
-    cairo_set_pattern (cr, gradient);
+    cairo_set_source (cr, gradient);
     draw_tent (cr, width, height);
 
     cairo_translate (cr, width + pad, 0);
-    cairo_set_pattern (cr, gradient);
+    cairo_set_source (cr, gradient);
     draw_cylinder (cr, width, height);
 
     cairo_restore (cr);

Index: snapping.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/snapping.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- snapping.c	4 Nov 2004 02:52:06 -0000	1.5
+++ snapping.c	17 May 2005 14:31:43 -0000	1.6
@@ -49,7 +49,7 @@
 #define HEIGHT 175
 #define STRIDE (WIDTH * 4)
 
-char image[STRIDE*HEIGHT];
+unsigned char image[STRIDE*HEIGHT];
 
 /* These snapping functions are designed to work properly with a
  * matrix that has only scale and translate components. I make no
@@ -63,10 +63,10 @@
 snap_point_for_fill (cairo_t *cr, double *x, double *y)
 {
     /* Convert to device space, round, then convert back to user space. */
-    cairo_transform_point (cr, x, y);
+    cairo_user_to_device (cr, x, y);
     *x = floor (*x + 0.5);
     *y = floor (*y + 0.5);
-    cairo_inverse_transform_point (cr, x, y);
+    cairo_device_to_user (cr, x, y);
 }
 
 /* Snap the given path coordinate as appropriate for a path to be
@@ -91,20 +91,20 @@
      * Round in device space after adding the fractional portion of
      * one-half the (device space) line width.
      */
-    x_width_dev_2 = y_width_dev_2 = cairo_current_line_width (cr);
-    cairo_transform_distance (cr, &x_width_dev_2, &y_width_dev_2);
+    x_width_dev_2 = y_width_dev_2 = cairo_get_line_width (cr);
+    cairo_user_to_device_distance (cr, &x_width_dev_2, &y_width_dev_2);
     x_width_dev_2 *= 0.5;
     y_width_dev_2 *= 0.5;
 
     x_offset = x_width_dev_2 - (int) (x_width_dev_2);
     y_offset = y_width_dev_2 - (int) (y_width_dev_2);
 
-    cairo_transform_point (cr, x, y);
+    cairo_user_to_device (cr, x, y);
     *x = floor (*x + x_offset + 0.5);
     *y = floor (*y + y_offset + 0.5);
     *x -= x_offset;
     *y -= y_offset;
-    cairo_inverse_transform_point (cr, x, y);
+    cairo_device_to_user (cr, x, y);
 }
 
 /* Snap the line width so that it is an integer number of device
@@ -120,9 +120,9 @@
     double x_width_snapped, y_width_snapped;
     double x_error, y_error;
 
-    x_width = y_width = cairo_current_line_width (cr);
+    x_width = y_width = cairo_get_line_width (cr);
 
-    cairo_transform_distance (cr, &x_width, &y_width);
+    cairo_user_to_device_distance (cr, &x_width, &y_width);
 
     /* If the line width is less than 1 then it will round to 0 and
      * disappear. Instead, we clamp it to 1.0, but we must preserve
@@ -146,7 +146,7 @@
     x_error = fabs (x_width - x_width_snapped);
     y_error = fabs (y_width - y_width_snapped);
 
-    cairo_inverse_transform_distance (cr, &x_width_snapped, &y_width_snapped);
+    cairo_device_to_user_distance (cr, &x_width_snapped, &y_width_snapped);
 
     if (x_error > y_error)
 	cairo_set_line_width (cr, x_width_snapped);
@@ -225,34 +225,79 @@
 static void
 snap_path_for_fill (cairo_t *cr)
 {
+    int i;
+    cairo_path_t *path;
+    cairo_path_data_t *data;
+  
     snap_path_closure_t spc;
+
     spc.first = 1;
     spc.fill = 1;
     spc.cr = cr;
-    cairo_current_path (cr,
-			spc_move_to,
-			spc_line_to,
-			spc_curve_to,
-			spc_close_path,
-			&spc);
+
+    path = cairo_copy_path (cr);
+  
+    for (i=0; i < path->num_data; i += path->data[i].header.length) {
+	data = &path->data[i];
+	switch (data->header.type) {
+	case CAIRO_PATH_MOVE_TO:
+	    spc_move_to (&spc, data[1].point.x, data[1].point.y);
+	    break;
+	case CAIRO_PATH_LINE_TO:
+	    spc_line_to (&spc, data[1].point.x, data[1].point.y);
+	    break;
+	case CAIRO_PATH_CURVE_TO:
+	    spc_curve_to (&spc, data[1].point.x, data[1].point.y,
+			  data[2].point.x, data[2].point.y,
+			  data[3].point.x, data[3].point.y);
+	    break;
+	case CAIRO_PATH_CLOSE_PATH:
+	    spc_close_path (&spc);
+	    break;
+	}
+    }
+  
+    cairo_path_destroy (path);
 }
 
 static void
 snap_path_for_stroke (cairo_t *cr)
 {
+    int i;
+    cairo_path_t *path;
+    cairo_path_data_t *data;
+
     snap_path_closure_t spc;
+
     spc.first = 1;
     spc.fill = 0;
     spc.cr = cr;
 
     snap_line_width (cr);
 
-    cairo_current_path (cr,
-			spc_move_to,
-			spc_line_to,
-			spc_curve_to,
-			spc_close_path,
-			&spc);
+    path = cairo_copy_path (cr);
+  
+    for (i=0; i < path->num_data; i += path->data[i].header.length) {
+	data = &path->data[i];
+	switch (data->header.type) {
+	case CAIRO_PATH_MOVE_TO:
+	    spc_move_to (&spc, data[1].point.x, data[1].point.y);
+	    break;
+	case CAIRO_PATH_LINE_TO:
+	    spc_line_to (&spc, data[1].point.x, data[1].point.y);
+	    break;
+	case CAIRO_PATH_CURVE_TO:
+	    spc_curve_to (&spc, data[1].point.x, data[1].point.y,
+			  data[2].point.x, data[2].point.y,
+			  data[3].point.x, data[3].point.y);
+	    break;
+	case CAIRO_PATH_CLOSE_PATH:
+	    spc_close_path (&spc);
+	    break;
+	}
+    }
+  
+    cairo_path_destroy (path);
 }
 
 typedef enum { NESTED_FILLS, NESTED_STROKES } nested_style_t;
@@ -286,14 +331,14 @@
 		if (snapping == SNAPPING)
 		    snap_path_for_fill (cr);
 		if (i % 2 == 0)
-		    cairo_set_rgb_color (cr, 1, 1, 1);
+		    cairo_set_source_rgb (cr, 1, 1, 1);
 		else
-		    cairo_set_rgb_color (cr, 0, 0, 0);
+		    cairo_set_source_rgb (cr, 0, 0, 0);
 		cairo_fill (cr);
 	    } else {
 		if (snapping == SNAPPING)
 		    snap_path_for_stroke (cr);
-		cairo_set_rgb_color (cr, 1, 1, 1);
+		cairo_set_source_rgb (cr, 1, 1, 1);
 		cairo_stroke (cr);
 	    }
 	}
@@ -328,23 +373,26 @@
 int
 main (void)
 {
+    cairo_surface_t *surface;
     cairo_t *cr;
 
-    cr = cairo_create ();
+    surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32,
+						   WIDTH, HEIGHT, STRIDE);
 
-    cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32,
-			    WIDTH, HEIGHT, STRIDE);
+    cr = cairo_create (surface);
 
     cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
-    cairo_set_rgb_color (cr, 0, 0, 0);
+    cairo_set_source_rgb (cr, 0, 0, 0);
     cairo_fill (cr);
 
     draw (cr, WIDTH, HEIGHT);
 
-    write_png_argb32 (image, "snapping.png", WIDTH, HEIGHT, STRIDE);
+    cairo_surface_write_to_png (surface, "snapping.png");
 
     cairo_destroy (cr);
 
+    cairo_surface_destroy (surface);
+
     return 0;
 }
 

Index: spiral.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/spiral.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- spiral.c	2 Apr 2005 04:20:39 -0000	1.3
+++ spiral.c	17 May 2005 14:31:43 -0000	1.4
@@ -36,28 +36,31 @@
 #define HEIGHT 600
 #define STRIDE (WIDTH * 4)
 
-char image[STRIDE*HEIGHT];
+unsigned char image[STRIDE*HEIGHT];
 
 int
 main (void)
 {
+    cairo_surface_t *surface;
     cairo_t *cr;
 
-    cr = cairo_create ();
+    surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32,
+						   WIDTH, HEIGHT, STRIDE);
 
-    cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32,
-		      WIDTH, HEIGHT, STRIDE);
+    cr = cairo_create (surface);
 
     cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
-    cairo_set_rgb_color (cr, 1, 1, 1);
+    cairo_set_source_rgb (cr, 1, 1, 1);
     cairo_fill (cr);
 
     draw_spiral (cr, WIDTH, HEIGHT);
 
-    write_png_argb32 (image, "spiral.png", WIDTH, HEIGHT, STRIDE);
+    cairo_surface_write_to_png (surface, "spiral.png");
 
     cairo_destroy (cr);
 
+    cairo_surface_destroy (surface);
+
     return 0;
 }
 
@@ -79,6 +82,6 @@
 	cairo_rel_line_to (cr, width - wd * (2 * i + 1), 0);
     }
 
-    cairo_set_rgb_color (cr, 0, 0, 1);
+    cairo_set_source_rgb (cr, 0, 0, 1);
     cairo_stroke (cr);
 }

Index: splines_tolerance.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/splines_tolerance.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- splines_tolerance.c	2 Apr 2005 04:20:39 -0000	1.3
+++ splines_tolerance.c	17 May 2005 14:31:43 -0000	1.4
@@ -39,28 +39,31 @@
 #define HEIGHT 300
 #define STRIDE (WIDTH * 4)
 
-char image[STRIDE*HEIGHT];
+unsigned char image[STRIDE*HEIGHT];
 
 int
 main (void)
 {
+    cairo_surface_t *surface;
     cairo_t *cr;
 
-    cr = cairo_create ();
+    surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32,
+						   WIDTH, HEIGHT, STRIDE);
 
-    cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32,
-		      WIDTH, HEIGHT, STRIDE);
+    cr = cairo_create (surface);
 
     cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
-    cairo_set_rgb_color (cr, 1, 1, 1);
+    cairo_set_source_rgb (cr, 1, 1, 1);
     cairo_fill (cr);
 
     draw_splines (cr, WIDTH, HEIGHT);
 
-    write_png_argb32 (image, "splines_tolerance.png", WIDTH, HEIGHT, STRIDE);
+    cairo_surface_write_to_png (surface, "splines_tolerance.png");
 
     cairo_destroy (cr);
 
+    cairo_surface_destroy (surface);
+
     return 0;
 }
 
@@ -84,7 +87,7 @@
     double line_width = .08 * width;
     double gap = width / 6;
 
-    cairo_set_rgb_color (cr, 0, 0, 0);
+    cairo_set_source_rgb (cr, 0, 0, 0);
     cairo_set_line_width (cr, line_width);
 
     cairo_translate (cr, gap, 0);

Index: star_and_ring.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/star_and_ring.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- star_and_ring.c	18 Mar 2005 15:26:53 -0000	1.1
+++ star_and_ring.c	17 May 2005 14:31:43 -0000	1.2
@@ -32,7 +32,7 @@
 #define HEIGHT 600
 #define STRIDE (WIDTH * 4)
 
-char image[STRIDE*HEIGHT];
+unsigned char image[STRIDE*HEIGHT];
 
 static void
 ring_path (cairo_t *cr)
@@ -79,15 +79,13 @@
 static void
 star_path (cairo_t *cr)
 {
-    cairo_matrix_t *matrix;
+    cairo_matrix_t matrix;
 
-    matrix = cairo_matrix_create ();
-    cairo_matrix_set_affine (matrix, 
+    cairo_matrix_init (&matrix, 
 			     0.647919, -0.761710,
 			     0.761710, 0.647919,
 			     -208.7977, 462.0608);
-    cairo_concat_matrix (cr, matrix);
-    cairo_matrix_destroy (matrix);
+    cairo_transform (cr, &matrix);
 
     cairo_move_to (cr, 505.80857, 746.23606);
     cairo_line_to (cr, 335.06870, 555.86488);
@@ -108,8 +106,7 @@
 
     cairo_translate (cr, -90, -205);
     ring_path (cr);
-    cairo_set_rgb_color (cr, 1.0, 0.0, 0.0);
-    cairo_set_alpha (cr, 0.75);
+    cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 0.75);
     cairo_fill (cr);
 
     cairo_restore (cr);
@@ -122,8 +119,7 @@
 
     cairo_translate (cr, -90, -205);
     star_path (cr);
-    cairo_set_rgb_color (cr, 0.0, 0.0, (double) 0xae / 0xff);
-    cairo_set_alpha (cr, 0.55135137);
+    cairo_set_source_rgba (cr, 0.0, 0.0, (double) 0xae / 0xff, 0.55135137);
     cairo_fill (cr);
     
     cairo_restore (cr);
@@ -156,11 +152,9 @@
 int
 main (void)
 {
-    cairo_t *cr;
+    cairo_t *cr, *cr_ros, *cr_sor;
     cairo_surface_t *ring_over_star, *star_over_ring, *result;
 
-    cr = cairo_create ();
-
     result = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32,
 						  WIDTH, HEIGHT, STRIDE);
     ring_over_star = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
@@ -168,32 +162,37 @@
     star_over_ring = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
 						 WIDTH, HEIGHT);
 
-    cairo_save (cr);
+    cr = cairo_create (result);
+
     {
-	cairo_set_target_surface (cr, ring_over_star);
-	clip_to_top_and_bottom (cr, WIDTH, HEIGHT);
-	fill_star (cr);
-	fill_ring (cr);
+	cr_ros = cairo_create (ring_over_star);
+	clip_to_top_and_bottom (cr_ros, WIDTH, HEIGHT);
+	fill_star (cr_ros);
+	fill_ring (cr_ros);
+	cairo_destroy (cr_ros);
     }
-    cairo_restore (cr);
 
-    cairo_save (cr);
     {
-	cairo_set_target_surface (cr, star_over_ring);
-	clip_to_left_and_right (cr, WIDTH, HEIGHT);
-	fill_ring (cr);
-	fill_star (cr);
+	cr_sor = cairo_create (star_over_ring);
+	clip_to_left_and_right (cr_sor, WIDTH, HEIGHT);
+	fill_ring (cr_sor);
+	fill_star (cr_sor);
+	cairo_destroy (cr_sor);
     }
-    cairo_restore (cr);
 
-    cairo_set_target_surface (cr, result);
     cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
-    cairo_show_surface (cr, ring_over_star, WIDTH, HEIGHT);
-    cairo_show_surface (cr, star_over_ring, WIDTH, HEIGHT);
-
-    write_png_argb32 (image, "star_and_ring.png", WIDTH, HEIGHT, STRIDE);
+    cairo_set_source_surface (cr, ring_over_star, 0, 0);
+    cairo_paint (cr);
+    cairo_set_source_surface (cr, star_over_ring, 0, 0);
+    cairo_paint (cr);
 
     cairo_destroy (cr);
 
+    cairo_surface_write_to_png (result, "star_and_ring.png");
+
+    cairo_surface_destroy (result);
+    cairo_surface_destroy (ring_over_star);
+    cairo_surface_destroy (star_over_ring);
+
     return 0;
 }

Index: stars.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/stars.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- stars.c	2 Apr 2005 04:20:39 -0000	1.3
+++ stars.c	17 May 2005 14:31:43 -0000	1.4
@@ -40,28 +40,31 @@
 #define HEIGHT 275
 #define STRIDE (WIDTH * 4)
 
-char image[STRIDE*HEIGHT];
+unsigned char image[STRIDE*HEIGHT];
 
 int
 main (void)
 {
+    cairo_surface_t *surface;
     cairo_t *cr;
 
-    cr = cairo_create ();
+    surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32,
+						   WIDTH, HEIGHT, STRIDE);
 
-    cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32,
-		      WIDTH, HEIGHT, STRIDE);
+    cr = cairo_create (surface);
 
     cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
-    cairo_set_rgb_color (cr, 1, 1, 1);
+    cairo_set_source_rgb (cr, 1, 1, 1);
     cairo_fill (cr);
 
     draw_stars (cr, WIDTH, HEIGHT);
 
-    write_png_argb32 (image, "stars.png", WIDTH, HEIGHT, STRIDE);
+    cairo_surface_write_to_png (surface, "stars.png");
 
     cairo_destroy (cr);
 
+    cairo_surface_destroy (surface);
+
     return 0;
 }
 
@@ -82,7 +85,7 @@
 void
 draw_stars (cairo_t *cr, int width, int height)
 {
-    cairo_set_rgb_color (cr, 0, 0, 0);
+    cairo_set_source_rgb (cr, 0, 0, 0);
 
     cairo_save (cr);
     {

Index: text-rotate.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/text-rotate.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- text-rotate.c	2 Apr 2005 04:20:39 -0000	1.3
+++ text-rotate.c	17 May 2005 14:31:43 -0000	1.4
@@ -36,35 +36,36 @@
 #define HEIGHT 900
 #define STRIDE (WIDTH * 4)
 
-char image[STRIDE*HEIGHT];
+unsigned char image[STRIDE*HEIGHT];
 int
 main (void)
 {
     int i;
+    cairo_surface_t *surface;
     cairo_t *cr;
-    cairo_matrix_t *matrix;
+    cairo_matrix_t matrix;
     double angle;
 
-    cr = cairo_create ();
+    surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32,
+						   WIDTH, HEIGHT, STRIDE);
 
-    cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32,
-			    WIDTH, HEIGHT, STRIDE);
+    cr = cairo_create (surface);
 
-    cairo_set_rgb_color (cr, 0., 0., 0.);
+    cairo_set_source_rgb (cr, 0., 0., 0.);
 
-    cairo_select_font (cr, "serif", 0, 0);
-    cairo_scale_font (cr, 40);
+    cairo_select_font_face (cr, "serif", 0, 0);
+    cairo_set_font_size (cr, 40);
     cairo_translate (cr, 40, 40);
 
 #define NUM_STRINGS 3.0
-    cairo_select_font (cr, "mono", 0, 0);
+    cairo_select_font_face (cr, "mono", 0, 0);
 
-    cairo_scale_font (cr, 12);
+    cairo_set_font_size (cr, 12);
     cairo_show_text (cr, "+CTM rotation");
 
     cairo_save (cr);
-    cairo_select_font (cr, "serif", 0, 0);
-    cairo_scale_font (cr, 40);
+    cairo_select_font_face (cr, "serif", 0, 0);
+    cairo_set_font_size (cr, 40);
     for (i=0; i < NUM_STRINGS; i++) {
 	angle = (double) i * 0.5 * M_PI / (NUM_STRINGS - 1);
 	cairo_save (cr);
@@ -83,16 +84,16 @@
     cairo_show_text (cr, "-font rotation");
 
     cairo_save (cr);
-    cairo_select_font (cr, "serif", 0, 0);
-    cairo_scale_font (cr, 40);
+    cairo_select_font_face (cr, "serif", 0, 0);
+    cairo_set_font_size (cr, 40);
     for (i=0; i < NUM_STRINGS; i++) {
 	angle = (double) i * 0.5 * M_PI / (NUM_STRINGS - 1);
 	cairo_save (cr);
 	cairo_rotate (cr, angle);
-	matrix = cairo_matrix_create ();
-	cairo_matrix_rotate (matrix, - angle);
-	cairo_transform_font (cr, matrix);
-	cairo_matrix_destroy (matrix);
+	cairo_matrix_init_identity (&matrix);
+	cairo_matrix_scale (&matrix, 40, 40);
+	cairo_matrix_rotate (&matrix, - angle);
+	cairo_set_font_matrix (cr, &matrix);
 	cairo_move_to (cr, 100, 0);
 	cairo_show_text (cr, "Text");
 	cairo_restore (cr);
@@ -107,8 +108,8 @@
     cairo_show_text (cr, "-CTM rotation");
 
     cairo_save (cr);
-    cairo_select_font (cr, "serif", 0, 0);
-    cairo_scale_font (cr, 40);
+    cairo_select_font_face (cr, "serif", 0, 0);
+    cairo_set_font_size (cr, 40);
     for (i=0; i < NUM_STRINGS; i++) {
 	angle = (double) i * 0.5 * M_PI / (NUM_STRINGS - 1);
 	cairo_save (cr);
@@ -120,9 +121,11 @@
     }
     cairo_restore (cr);
 
-    write_png_argb32 (image, "text-rotate.png", WIDTH, HEIGHT, STRIDE);
+    cairo_surface_write_to_png (surface, "text-rotate.png");
 
     cairo_destroy (cr);
 
+    cairo_surface_destroy (surface);
+
     return 0;
 }

Index: text.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/text.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- text.c	2 Apr 2005 04:20:39 -0000	1.8
+++ text.c	17 May 2005 14:31:43 -0000	1.9
@@ -41,7 +41,7 @@
 #define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0))
 #define DOUBLE_FROM_16_16(t) ((double)(t) / 65536.0)
 
-char image[STRIDE*HEIGHT];
+unsigned char image[STRIDE*HEIGHT];
 
 static void
 box_text (cairo_t *cr, const char *utf8, double x, double y)
@@ -52,7 +52,7 @@
     cairo_save (cr);
 
     cairo_text_extents (cr, TEXT, &extents);
-    line_width = cairo_current_line_width (cr);
+    line_width = cairo_get_line_width (cr);
     cairo_rectangle (cr,
 		     x + extents.x_bearing - line_width,
 		     y + extents.y_bearing - line_width,
@@ -63,7 +63,7 @@
     cairo_move_to (cr, x, y);
     cairo_show_text (cr, utf8);
     cairo_text_path (cr, utf8);
-    cairo_set_rgb_color (cr, 1, 0, 0);
+    cairo_set_source_rgb (cr, 1, 0, 0);
     cairo_set_line_width (cr, 1.0);
     cairo_stroke (cr);
 
@@ -81,7 +81,7 @@
     cairo_save (cr);
 
     cairo_glyph_extents (cr, glyphs, num_glyphs, &extents);
-    line_width = cairo_current_line_width (cr);
+    line_width = cairo_get_line_width (cr);
     cairo_rectangle (cr,
 		     x + extents.x_bearing - line_width,
 		     y + extents.y_bearing - line_width,
@@ -95,7 +95,7 @@
     }
     cairo_show_glyphs (cr, glyphs, num_glyphs);
     cairo_glyph_path (cr, glyphs, num_glyphs);
-    cairo_set_rgb_color (cr, 1, 0, 0);
+    cairo_set_source_rgb (cr, 1, 0, 0);
     cairo_set_line_width (cr, 1.0);
     cairo_stroke (cr);
     for (i=0; i < num_glyphs; i++) {
@@ -110,6 +110,7 @@
 main (void)
 {
     int i;
+    cairo_surface_t *surface;
     cairo_t *cr;
     cairo_text_extents_t extents;
     cairo_font_extents_t font_extents;
@@ -118,29 +119,30 @@
 #define NUM_GLYPHS 10
     cairo_glyph_t glyphs[NUM_GLYPHS];
 
-    cr = cairo_create ();
+    surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32,
+						   WIDTH, HEIGHT, STRIDE);
 
-    cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32,
-			    WIDTH, HEIGHT, STRIDE);
 
-    cairo_set_rgb_color (cr, 0., 0., 0.);
+    cr = cairo_create (surface);
+
+    cairo_set_source_rgb (cr, 0., 0., 0.);
     cairo_set_line_width (cr, 2.0);
 
     cairo_save (cr);
     cairo_rectangle (cr, 0., 0., WIDTH, HEIGHT);
-    cairo_set_alpha (cr, 0.);
-    cairo_set_operator (cr, CAIRO_OPERATOR_SRC);
+    cairo_set_source_rgba (cr, 0., 0., 0., 0.);
+    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
     cairo_fill (cr);
     cairo_restore (cr);
 
-    cairo_select_font (cr, "sans", 0, 0);
-    cairo_scale_font (cr, 40);
+    cairo_select_font_face (cr, "sans", 0, 0);
+    cairo_set_font_size (cr, 40);
 #define XXX_DEMONSTRATE_EXTENTS_BUGS_WHEN_FONT_IS_TRANSFORMED 0
 #if XXX_DEMONSTRATE_EXTENTS_BUGS_WHEN_FONT_IS_TRANSFORMED
     {
 	cairo_matrix_t *matrix = cairo_matrix_create ();
 	cairo_matrix_scale (matrix, 1.0, -1.0);
-	cairo_transform_font (cr, matrix);
+	cairo_set_font_matrix (cr, matrix);
 	cairo_matrix_destroy (matrix);
     }
 
@@ -148,7 +150,7 @@
     cairo_translate (cr, 0.0, - HEIGHT);
 #endif
 
-    cairo_current_font_extents (cr, &font_extents);
+    cairo_font_extents (cr, &font_extents);
     height = font_extents.height;
 
     dx = 0.0;
@@ -176,10 +178,12 @@
     cairo_translate (cr, 0, 2 * height);
     cairo_save (cr);
     {
-	cairo_matrix_t *matrix = cairo_matrix_create ();
-	cairo_matrix_rotate (matrix, 10 * M_PI / 180.0);
-	cairo_transform_font (cr, matrix);
-	cairo_matrix_destroy (matrix);
+	cairo_matrix_t matrix;
+	cairo_matrix_init_identity (&matrix);
+	cairo_matrix_scale (&matrix, 40, 40);
+	cairo_matrix_rotate (&matrix, 10 * M_PI / 180.0);
+#warning it looks like cairo_set_font_matrix is not currently working
+	cairo_set_font_matrix (cr, &matrix);
     }
     box_text (cr, TEXT, 10, height);
     cairo_restore (cr);
@@ -200,9 +204,11 @@
 	glyphs[i].y += i * 5;
     box_glyphs (cr, glyphs, NUM_GLYPHS, 10, height);
 
-    write_png_argb32 (image, "text.png", WIDTH, HEIGHT, STRIDE);
+    cairo_surface_write_to_png (surface, "text.png");
 
     cairo_destroy (cr);
 
+    cairo_surface_destroy (surface);
+
     return 0;
 }




More information about the cairo-commit mailing list