[cairo] PDF surface questions
ajohnson at redneon.com
Thu Jun 23 03:31:22 PDT 2011
On 23/06/11 08:56, cu wrote:
> I've been experimenting with writing PDF surfaces. Some of the
> operations use image surface sources to draw into specific areas of PDF
> (think "sprites"/icons placed in PDF image). There are two issues I've
> found with that:
> 1. It appears that even when using the same surface or pattern as
> source, PDF file ends up with as many image copies of source as there
> are icons it was used for. Big waste of space.
The cairo 1.10 PDF backend will embed only one copy of the pattern
source if you reuse the same surface or pattern.
When cairo 1.12 is released it will be possible to ensure the same
surface is embedded only once even if the surface or pattern is
recreated. This will be achieved using a new mime type,
CAIRO_MIME_TYPE_UNIQUE_ID, that allows the application to specify a
unique identifier for each surface. This could be a file name, hash, or
anything the application wants to use to uniquely identify the surface.
Surfaces with the same unique id will be embedded only once.
> 2. It appears that even if a small area of source is used (i.e. one icon
> from a large icon set stored as a single surface) drawn into a small
> rectangle, resulting PDF contains the complete image with a full icon set.
> I wonder if it would be possible to avoid at least one of these cases -
> i.e. if each icon must be stored as a separate image, than could it be
> stored as an image of exact size as required to fill the area (I
> understand that I could do this by creating individual images instead of
> a single large source, but that's not acceptable for the rest of product
> architecture) or, alternatively, keep a single copy of an image used
> multiple times in PDF?
The PDF backend can not extract the portion of the image used. You can
- Each time you need to paint an icon, create an image surface the
size of the icon, paint the icon from your source icon set, then use
the single icon image surface as the source for the PDF surface.
- Use the entire image as the source using one of the methods
described above to ensure the image is embedded only once.
> I am using Cairo 1.9.8
I'm not sure if 1.9.8 correctly implements the reuse of the same
source. Try it with 1.10.2.
> Thanks all,
> cairo mailing list
> cairo at cairographics.org
More information about the cairo