[cairo] Embedding EPS files

Adrian Johnson ajohnson at redneon.com
Mon Nov 8 10:48:23 UTC 2021


On 8/11/21 19:53, Han-Wen Nienhuys wrote:
> Hi there,
>
> I'm trying to embed an EPS file into Cairo's PS output. I've
> scoured the internet in vain for an example of how to do
> this, and it looks like this feature is untested (at least,
> the test/ directory does not reference CAIRO_MIME_TYPE_EPS.)

I've attached a patch with the changes required to get your code to work.

The problem is with your use of cairo_surface_set_mime_data(). This
function does not copy the mime data you supply so when your strings go
out of scope the data is lost. As Cairo does not use the data until
cairo_show_page() or cairo_surface_finish() is called, you need to
either ensure the mime data exists until after the PS surface is
destroyed or provide a copy along with the destroy function.

I also changed the surface used to paint the EPS to an image surface.
The idea is that an image surface with attached EPS data can be painted
to any surface but only when the target is PS will the EPS data be used.
I did plan on implementing EPS screen preview by embedding the image
data in DSC comments but have not yet implemented this.

The size of the image does not matter. You could use 1x1 if it contains
no image data. You will want to translate and scale the painted image
since in the PS output, the EPS content inside the bbox is scaled and
translated to the size and position of the painted image.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eps.diff
Type: text/x-patch
Size: 1674 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20211108/aa5f932f/attachment.bin>


More information about the cairo mailing list