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

Uli Schlachter psychon at znc.in
Sat May 10 14:28:18 PDT 2014


Hi,

On 10.05.2014 23:13, jimmy frasche wrote:
> I think I want to add MIME support to my binding but I'm not entirely
> sure what it's purpose or function is and completely unsure what the
> use-cases for it are.

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.

For this you use mime data.

> The docs for cairo_surface_set_mime_data say,
> 
> "The attached image (or filename) data can later be used by backends
> which support it […] to emit this data instead of making a snapshot of
> the surface.
> 
> "Caution: the associated MIME data will be discarded if you draw on
> the surface afterwards. Use this function with care."

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.

> Can you, say, use this to embed an image in a PS surface by creating
> two PS surfaces, attaching the mime data to one to use as a surface
> pattern on the other, which you can then use as you normally would?
> (Do they both have to be PS surfaces?)
>
> I also see talk of a mime surface, searching the mailing list
> archives, but the only references in the source I see are:
> 
> $ find -name "*.[ch]" | xargs grep -in mime_surface
> ./src/cairo.c:220: *  writing (such as #cairo_mime_surface_t) then a
> ./test/mime-surface-api.c:146:CAIRO_TEST (mime_surface_api,
> 
> Was this never implemented or did it just become the present mime data api?
> 
> If so, the documentation for cairo_create's return should be amended.

I don't know, sorry. That was before my cairo time.

> I'd like to expose this functionality idiomatically and clearly
> documented, so any help increasing my undersanding would be
> appreciated.
> 
> If this conversation leads to any way to clarify the current
> documentation I'm more than happy to put together patches for the API
> docs.

Thanks!

Cheers,
Uli
-- 
Happiness can't be found -- it finds you.
 - Majic


More information about the cairo mailing list