[cairo] Paths as paths

Kristian Høgsberg krh at bitplanet.net
Mon Mar 7 22:19:27 PST 2005


Owen Taylor wrote:
> Currently, backends only have access to paths after they are turned into
> trapezoids. This has some very noticeably downsides for the PDF backend:
> the generated output files are huge, resolution dependent, and tend to
> have seams on some PDF viewers.

I haven't seen seems in any PDF viewers since I changed the backend to 
generate one big PDF path for all the trapezoids.  I'm not defending the 
current method, since it's non-optimal for so many other reasons, I just 
haven't seen this problem for a while.

...

> I think for paths this approach is pretty obviously better than what we
> are doing currently. But what about strokes? The same problems above
> apply.

I noticed a couple of things when I tested your patch: If we call 
cairo_arc without a current point we generate invalid paths (see 
attached patch) because we don't generate an initial move_to.  Second, 
snippets.pdf generated with the patch lock up xpdf based viewers when 
they try to render the imagepattern snippet.  I didn't investigate this 
further, but the imagepattern snippet isn't supposed to work yet anyway, 
it just fails in a spectacularly annoying way now.

...

> Index: src/cairoint.h
> ===================================================================
> RCS file: /cvs/cairo/cairo/src/cairoint.h,v
> retrieving revision 1.103
> diff -u -p -r1.103 cairoint.h
> --- src/cairoint.h	4 Mar 2005 17:41:34 -0000	1.103
> +++ src/cairoint.h	5 Mar 2005 19:42:46 -0000
> @@ -648,6 +648,12 @@ typedef struct _cairo_surface_backend {
>  				 unsigned int			height,
>  				 const cairo_glyph_t		*glyphs,
>  				 int				num_glyphs);
> +    cairo_int_status_t
> +    (*fill_path)		(cairo_operator_t	operator,
> +				 cairo_pattern_t	*pattern,
> +				 void			*dst,
> +				 cairo_path_t           *path);
> +  

We need to pass a mask argument as well here, right? (not that the PDF 
backend uses the mask yet).

Other than that, the patch looks good to me.

cheers,
Kristian
-------------- next part --------------
? doc/public/cairo-docs.sgml
? doc/public/tmpl/cairo-image.sgml
? doc/public/tmpl/cairo-win3.sgml
Index: src/cairo_gstate.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_gstate.c,v
retrieving revision 1.91
diff -u -p -r1.91 cairo_gstate.c
--- src/cairo_gstate.c	4 Mar 2005 02:39:06 -0000	1.91
+++ src/cairo_gstate.c	8 Mar 2005 05:58:32 -0000
@@ -1009,9 +1009,14 @@ _cairo_gstate_arc (cairo_gstate_t *gstat
     while (angle2 < angle1)
 	angle2 += 2 * M_PI;
 
-    status = _cairo_gstate_line_to (gstate,
-				    xc + radius * cos (angle1),
-				    yc + radius * sin (angle1));
+    if (_cairo_path_current_point (&gstate->path, NULL) != CAIRO_STATUS_SUCCESS)
+      status = _cairo_gstate_move_to (gstate,
+				      xc + radius * cos (angle1),
+				      yc + radius * sin (angle1));
+    else
+      status = _cairo_gstate_line_to (gstate,
+				      xc + radius * cos (angle1),
+				      yc + radius * sin (angle1));
     if (status)
 	return status;
 
Index: src/cairo_path.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_path.c,v
retrieving revision 1.19
diff -u -p -r1.19 cairo_path.c
--- src/cairo_path.c	22 Feb 2005 19:35:03 -0000	1.19
+++ src/cairo_path.c	8 Mar 2005 05:58:32 -0000
@@ -261,7 +261,8 @@ _cairo_path_current_point (cairo_path_t 
     if (! path->has_current_point)
 	return CAIRO_STATUS_NO_CURRENT_POINT;
 
-    *point = path->current_point;
+    if (point != NULL)
+      *point = path->current_point;
 
     return CAIRO_STATUS_SUCCESS;
 }


More information about the cairo mailing list