[cairo] PDF output: Patterns have wrong vertical offset

Kristof Van Landschoot kristof at coin-c.com
Wed Jul 8 04:25:40 PDT 2009


Hi,

We had a couple of testfiles that showed cut offs in image patterns
when exporting a PDF file. I examined it and fixed what I believe is a
bug in the cairo PDF output.

Basically it comes down to the fact that the matrix outputted in
_cairo_pdf_surface_emit_surface_pattern where we set the TilingType
etc. is offset wrongly when the mediabox of the PDF file is not an
integer number. The surface_extents.height parameter is rounded
upwards by the _cairo_pdf_surface_get_extents to the nearest integer
which here gives a slightly incorrect result. Instead I propose to
just directly use the double that is stored in the height member of
the cairo_pdf_surface_t to calculate the matrix.

I attached a patch against the latest version
(6be6245e24b5685e1170f4fa462e687546c8b7e2) which is my quick solution
to the problem. It might not be the way it should be done but it
probably illustrates my solution better than my explanation does.

Any feedback is appreciated.
Best Regards,
Kristof
-------------- next part --------------
2162a2163,2171
> static cairo_int_status_t
> _cairo_pdf_surface_get_height(void *abstract_surface,
> 							  double *height)
> {
>     cairo_pdf_surface_t *surface = abstract_surface;
> 	*height = surface->height;
> 	return CAIRO_STATUS_SUCCESS;
> }
> 
2189a2199
> 	double surface_height;
2220,2221c2230,2231
<     status = _cairo_surface_get_extents (&surface->base, &surface_extents);
<     if (unlikely (status))
---
>     status = _cairo_pdf_surface_get_height (surface, &surface_height);
>     if (status)
2307c2317
<     cairo_matrix_translate (&pdf_p2d, 0.0, surface_extents.height);
---
>     cairo_matrix_translate (&pdf_p2d, 0.0, surface_height);


More information about the cairo mailing list