[cairo] Welding Cairo with Mac OS X printing

Stuart Parmenter stuartp at gmail.com
Fri Dec 7 12:43:40 PST 2007


Yeah, we use the print manager APIs in Firefox.

There are some annoying things you have to do such as get a new
surface for each page as the CGContextRef isn't good for more than
one.

You end up having to do something like:

// get all the printer info (i don't know this part very well --
should be documented)
PMSessionBeginCGDocumentNoDialog()
for (i = 0; i < npages; i++) {
  PMSessionBeginPageNoDialog()
  PMSessionGetCGGraphicsContext(&cgcontextref)
  cairo_t *cr =
cairo_create(cairo_quartz_surface_create_for_cg_context(cgcontextref,
pagewidth, pageheight));
  // draw page i
  PMSessionEndPageNoDialog()
}
PMSessionEndDocumentNoDialog()

stuart

On Dec 7, 2007 12:11 PM, Baz <brian.ewins at gmail.com> wrote:
> On Dec 7, 2007 7:22 PM, Travis Griggs <tgriggs at cincom.com> wrote:
> > This is somewhat off topic, I apologize, I thought I'd start here,
> > and then go off channel if I could get any response.
> >
> > I was looking at a guy's app the other day that uses our rather old
> > graphics APIs to print stuff on OSX. It got my wondering if I
> > couldn't do some nicer stuff with Cairo. I know Cairo decently well
> > these days. But not OSX printing machinery. Does anyone on list have
> > any idea how hard it would be to open an OSX printer dialog, get the
> > printer, and then squirt Cairo generated graphics at it?
>
> Not really - I don't own a printer (tree murderer!! ;) ). But it
> doesn't look difficult. As usual, you just need to get hold of a
> CGContext, and create your cairo context with that; the API you're
> looking for is PrintManager's PMSessionGetCGGraphicsContext.
> http://developer.apple.com/documentation/GraphicsImaging/Reference/CorePrintRef/Reference/reference.html#//apple_ref/c/func/PMSessionGetCGGraphicsContext
>
> In the apple docs you can find code for writing the printing loop (and
> dealing with print dialogs) here:
> http://developer.apple.com/documentation/Carbon/Conceptual/CPM_Concepts/index.html#//apple_ref/doc/uid/TP30000978
>
> that code uses a QT context, you'll want to plug in the call to
> PMSessionGetCGGraphicsContext where they have
> PMSessionGetGraphicsContext, and do your cairo work in the block
> immediately after that.
>
> I believe this is how firefox works, and that gnome don't do printing
> on OS X yet. This won't do any pagination for you btw, and you'll be
> hitting any limitations of the quartz surface, not the pdf, ps
> surfaces.
>
>
> >
> > TIA
> >
> > --
> > Travis Griggs
> > Objologist
> > "I choose. Therefore, I Am"
> >
> >
> > _______________________________________________
> > cairo mailing list
> > cairo at cairographics.org
> > http://lists.cairographics.org/mailman/listinfo/cairo
> >
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>


More information about the cairo mailing list