[cairo] Clipping on PDF surfaces
funkycoder at gmail.com
Sat Feb 6 10:43:50 PST 2010
I wrote a small program to emulate psposter's behaviour for PDF (split
up a page into several smaller ones), using poppler and cairo.
It works as expected, but the output PDF is a multiple of the input
file's size (the full size of the input for every output file). The
problem lies in the clipping behaviour: cairo seems to write the clip
path to the PDF, and then render everything to be clipped, so that the
actual clipping is done by the PDF renderer. i.e.: when removing the
clip-path from the output PDF, all the unnecessary paths that were
supposed to disappear, are still there.
The code I'm using is:
cairo_rectangle( cr, ... );
cairo_clip( cr );
CairoOutputDev *out = new CairoOutputDev();
out->startDoc( pdf->getXRef(), pdf->getCatalog() );
out->setCairo( cr );
pdf->displayPageSlice( out, page, ... );
Poppler itself offers a "crop"-parameter, too, but it seems to just set
the cairo clip rectangle, as I do manually anyway.
I would like cairo to check, if the bounding rectangle of the path to be
drawn intersects with the bounding rectangle of the clip path -- and
only draw the path if there's a possibility it might be visible.
This should not be too complicated, the actual clipping of the geometry
can still be done by the PDF renderer. It would reduce the size of my
outpout files drastically though.
Or is there already a function like this (that would not require to
write a custom "proxy" surface or modify poppler)?
(Not using the latest cairo, so if this behaviour has changed, I'm sorry)
More information about the cairo