[cairo-commit] cairo/src cairo-gstate-private.h, 1.16, 1.17 cairo-gstate.c, 1.167, 1.168 cairo-surface.c, 1.98, 1.99 cairoint.h, 1.205, 1.206

Keith Packard commit at pdx.freedesktop.org
Wed Aug 24 01:39:58 PDT 2005


Committed by: keithp

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

Modified Files:
	cairo-gstate-private.h cairo-gstate.c cairo-surface.c 
	cairoint.h 
Log Message:
2005-08-24  Keith Packard  <keithp at keithp.com>

	reviewed by: cworth

	* src/cairo-gstate-private.h:
	* src/cairo-gstate.c: (_cairo_gstate_init),
	(_cairo_gstate_apply_device_transform),
	(_cairo_gstate_apply_device_inverse_transform),
	(_cairo_gstate_get_matrix), (_cairo_gstate_set_matrix),
	(_cairo_gstate_identity_matrix), (_cairo_gstate_user_to_backend),
	(_cairo_gstate_backend_to_user):
	* src/cairo-surface.c: (_cairo_surface_init),
	(cairo_surface_set_device_offset):
	* src/cairoint.h:
	Add device_x_scale and device_y_scale to
	surface so that the coordinate system seen
	by the backend can differ from the nominal
	device coordinate space used by the application.
	
	Useful for printer backends where the device
	coordinate space should be in pixels while the
	user visible device space is in points.

	There is no API to set these values; the backends
	using this functionality should do that themselves
	before the first cairo_t is created.


Index: cairo-gstate-private.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-gstate-private.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- cairo-gstate-private.h	9 Aug 2005 01:35:22 -0000	1.16
+++ cairo-gstate-private.h	24 Aug 2005 08:39:56 -0000	1.17
@@ -63,14 +63,14 @@
 
     cairo_clip_t clip;
 
+    cairo_surface_t *target;
+
     cairo_matrix_t ctm;
     cairo_matrix_t ctm_inverse;
     cairo_matrix_t source_ctm_inverse; /* At the time ->source was set */
 
     cairo_pen_t pen_regular;
 
-    cairo_surface_t *target;
-
     cairo_pattern_t *source;
 
     struct _cairo_gstate *next;

Index: cairo-gstate.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-gstate.c,v
retrieving revision 1.167
retrieving revision 1.168
diff -u -d -r1.167 -r1.168
--- cairo-gstate.c	23 Aug 2005 03:43:23 -0000	1.167
+++ cairo-gstate.c	24 Aug 2005 08:39:56 -0000	1.168
@@ -116,13 +116,13 @@
     
     _cairo_clip_init (&gstate->clip, target);
 
+    gstate->target = cairo_surface_reference (target);
+
     _cairo_gstate_identity_matrix (gstate);
-    cairo_matrix_init_identity (&gstate->source_ctm_inverse);
+    gstate->source_ctm_inverse = gstate->ctm_inverse;
 
     _cairo_pen_init_empty (&gstate->pen_regular);
 
-    gstate->target = cairo_surface_reference (target);
-
     gstate->source = _cairo_pattern_create_solid (CAIRO_COLOR_BLACK);
     if (gstate->source->status)
 	return CAIRO_STATUS_NO_MEMORY;
@@ -491,10 +491,37 @@
     return gstate->miter_limit;
 }
 
+static void
+_cairo_gstate_apply_device_transform (cairo_gstate_t    *gstate,
+				      cairo_matrix_t	*matrix)
+{
+    if (gstate->target->device_x_scale != 1.0 ||
+	gstate->target->device_y_scale != 1.0)
+    {
+	cairo_matrix_scale (matrix,
+			    gstate->target->device_x_scale,
+			    gstate->target->device_y_scale);
+    }
+}
+
+static void
+_cairo_gstate_apply_device_inverse_transform (cairo_gstate_t    *gstate,
+					      cairo_matrix_t	*matrix)
+{
+    if (gstate->target->device_x_scale != 1.0 ||
+	gstate->target->device_y_scale != 1.0)
+    {
+	cairo_matrix_scale (matrix,
+			    1/gstate->target->device_x_scale,
+			    1/gstate->target->device_y_scale);
+    }
+}
+
 void
 _cairo_gstate_get_matrix (cairo_gstate_t *gstate, cairo_matrix_t *matrix)
 {
     *matrix = gstate->ctm;
+    _cairo_gstate_apply_device_inverse_transform (gstate, matrix);
 }
 
 cairo_status_t
@@ -580,6 +607,9 @@
     if (status)
 	return status;
 
+    _cairo_gstate_apply_device_transform (gstate, &gstate->ctm);
+    _cairo_gstate_apply_device_inverse_transform (gstate, &gstate->ctm_inverse);
+
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -591,6 +621,9 @@
     cairo_matrix_init_identity (&gstate->ctm);
     cairo_matrix_init_identity (&gstate->ctm_inverse);
 
+    _cairo_gstate_apply_device_transform (gstate, &gstate->ctm);
+    _cairo_gstate_apply_device_inverse_transform (gstate, &gstate->ctm_inverse);
+
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -632,19 +665,15 @@
 _cairo_gstate_user_to_backend (cairo_gstate_t *gstate, double *x, double *y)
 {
     cairo_matrix_transform_point (&gstate->ctm, x, y);
-    if (gstate->target) {
-	*x += gstate->target->device_x_offset;
-	*y += gstate->target->device_y_offset;
-    }
+    *x += gstate->target->device_x_offset;
+    *y += gstate->target->device_y_offset;
 }
 
 void
 _cairo_gstate_backend_to_user (cairo_gstate_t *gstate, double *x, double *y)
 {
-    if (gstate->target) {
-	*x -= gstate->target->device_x_offset;
-	*y -= gstate->target->device_y_offset;
-    }
+    *x -= gstate->target->device_x_offset;
+    *y -= gstate->target->device_y_offset;
     cairo_matrix_transform_point (&gstate->ctm_inverse, x, y);
 }
 

Index: cairo-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-surface.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- cairo-surface.c	23 Aug 2005 21:04:28 -0000	1.98
+++ cairo-surface.c	24 Aug 2005 08:39:56 -0000	1.99
@@ -147,8 +147,10 @@
 
     _cairo_user_data_array_init (&surface->user_data);
 
-    surface->device_x_offset = 0;
-    surface->device_y_offset = 0;
+    surface->device_x_offset = 0.0;
+    surface->device_y_offset = 0.0;
+    surface->device_x_scale = 1.0;
+    surface->device_y_scale = 1.0;
 
     surface->next_clip_serial = 0;
     surface->current_clip_serial = 0;
@@ -542,8 +544,8 @@
 	return;
     }
 
-    surface->device_x_offset = x_offset;
-    surface->device_y_offset = y_offset;
+    surface->device_x_offset = x_offset * surface->device_x_scale;
+    surface->device_y_offset = y_offset * surface->device_y_scale;
 }
 
 /**

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.205
retrieving revision 1.206
diff -u -d -r1.205 -r1.206
--- cairoint.h	23 Aug 2005 20:57:00 -0000	1.205
+++ cairoint.h	24 Aug 2005 08:39:56 -0000	1.206
@@ -852,6 +852,8 @@
 
     double device_x_offset;
     double device_y_offset;
+    double device_x_scale;
+    double device_y_scale;
 
     /*
      * Each time a clip region is modified, it gets the next value in this



More information about the cairo-commit mailing list