[cairo] Not sure how to handle MIME in my go binding

jimmy frasche soapboxcicero at gmail.com
Sat May 10 16:20:27 PDT 2014


> You are creating PDFs. All of these PDFs contain your company's logo in the top
> right corner. The logo is available as a PNG image. Encoding the logo as a PNG
> image results in a much smaller file than other approaches. Thus, it would be
> great to also encode the image in PNG format inside the PDF file.
>
> You load your company's logo into a cairo image surface. Then you attach the raw
> PNG file contents to this surfaces as PNG mime data. Backends which support it
> (e.g. the PDF backend) then *might* use the PNG data instead of the raw image
> surface's contents inside the resulting PDF file and you get a smaller file.
>
> But the backend is not required to do so and thus the image surface content must
> describe the same image as the attached PNG mime data!
>
>> I'm reading this as saying that this is essentially a way of painting
>> an image surface as a surface pattern, specially optimized to avoid
>> decoding the image data, and without the ability to do anything
>> afterwards.
>
> Kinda. But you still have to decode the data, it's just that the resulting files
> could use the mime data.

In the case of the PNG in the PDF, I imagine the "might" comes from one of:

- the pdf version does not support embedding that mime type or

-  the mime is supported but not that particular encoding or format
(like it can't take transparent PNGs, for an example that's completely
made up) or

-  manipulation of some kind to the image, say clipping it, would
require using the decoded data instead of the mime data.

Is that correct?

If so, it sounds like it's only really useful with an ImageSurface
being used as a source pattern unless your only need is to make a pdf
containing just the embedded png.

How does it work for SVG, where you can use a URL? Does it just emit
[image xlink:href="your-url"]? (using [] instead of angle brackets so
html mail clients ignore it) I imagine you'd still need to include the
raw data in that case so it still works if you do any thing to the
image when you paint it into the SVG surface?

I think the docs for set mime data should definitely include the
caveat that you also need to copy the image data into the surface
before calling it. A wiki page with a few examples of how to use it
wouldn't hurt either.


More information about the cairo mailing list