[Commit] cairo-demo/X11 cairo-knockout.c,1.3,1.4
Carl Worth
commit at keithp.com
Mon Sep 29 09:17:02 PDT 2003
Committed by: cworth
Update of /local/src/CVS/cairo-demo/X11
In directory home.keithp.com:/tmp/cvs-serv7168
Modified Files:
cairo-knockout.c
Log Message:
Use cairo_arc in oval_path
Index: cairo-knockout.c
===================================================================
RCS file: /local/src/CVS/cairo-demo/X11/cairo-knockout.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cairo-knockout.c 29 Sep 2003 15:01:03 -0000 1.3
+++ cairo-knockout.c 29 Sep 2003 15:17:00 -0000 1.4
@@ -9,50 +9,37 @@
* v0.2 1 December 2002 - typo fixes from Keith Packard
* v0.3 17 April 2003 - Tracking changes in Xr, (Removal of Xr{Push,Pop}Group)
* v0.4 29 September 2003 - Use cairo_rectangle rather than private rect_path
+ * Use cairo_arc for oval_path
*/
#include <X11/Xlib.h>
#include <cairo.h>
#include <math.h>
#include <stdio.h>
-/* Create a path that is roughly a circular oval with
- * radii xr, yr at xc, yc. We only use 4 bezier's
- * but the deviation is already pretty darn small.
- * (max of about 0.02%)
+/* Create a path that is a circular oval with radii xr, yr at xc,
+ * yc. Since we use cairo_arc here it will provide as many splines as
+ * necessary to be extremely accurate.
*/
static void
oval_path (cairo_t *r,
double xc, double yc,
double xr, double yr)
{
- int i;
-
- cairo_new_path (r);
- cairo_move_to (r, xc + xr, yc);
+ cairo_matrix_t *matrix;
-#define TANGENT_MULT (1.65591 / 3.)
-
- for (i = 0; i < 4; i++)
- {
- double angle1 = ((i + 0) / 2.) * M_PI;
- double angle2 = ((i + 1) / 2.) * M_PI;
+ matrix = cairo_matrix_create ();
+ cairo_current_matrix (r, matrix);
- double x0 = xc + xr * cos (angle1);
- double y0 = yc - yr * sin (angle1);
+ cairo_translate (r, xc, yc);
+ cairo_scale (r, 1.0, yr / xr);
+ cairo_move_to (r, 0.0, 0.0);
+ cairo_arc (r,
+ 0, 0,
+ xr,
+ 0, 2 * M_PI);
- double x1 = x0 - xr * sin (angle1) * TANGENT_MULT;
- double y1 = y0 - yr * cos (angle1) * TANGENT_MULT;
-
- double x3 = xc + xr * cos (angle2);
- double y3 = yc - yr * sin (angle2);
-
- double x2 = x3 + xr * sin (angle2) * TANGENT_MULT;
- double y2 = y3 + yr * cos (angle2) * TANGENT_MULT;
-
- cairo_curve_to (r, x1, y1, x2, y2, x3, y3);
- }
-
- cairo_close_path (r);
+ cairo_set_matrix (r, matrix);
+ cairo_matrix_destroy (matrix);
}
/* Fill the given area with checks in the standard style
@@ -251,7 +238,7 @@
/* It would be nice to be able to set 'region' as
* clip for our drawing, then only copy that portion
- * of our drawing, but Xr doesn't expose the clipping
+ * of our drawing, but Cairo doesn't expose the clipping
* features of Xrender. So, we redraw the entire
* bounding rectangle, even if the area is, e.g., L shaped,
* as frequently happens for exposes.x
More information about the Commit
mailing list