Odysseus supports printing a physical copy of your webpages using ctrl+p, though I can’t say I have used it. I’ll describe how this works this morning.
This menu option wraps a WebKitPrintOperation, which in turn wraps WebPageProxy.drawPagesForPrinting() with a GtkPrintUnixDialog (which I may describe tonight or tomorrow). The .drawPagesForPrinting() method call is then sent into the sandbox to be performed by a PrintContext object.
The WebPage will mark itself as immutable, before the context “begins” by computing the new viewport size, and passing that on to the Frame which’ll then flag itself for printing and recompute it’s layout. This uses the same codepath as usual, but with a few more conditions enabled.
Next the WebPage calls PrintContext.computePageRects() to compute the border for each physical page it’s laid out.
Finally WebPage constructs a WebPrintOperationGtk, which in turn wraps the PrintContext.spoolPage() method with a GtkPrintJob and plenty of Cairo Graphics operations.
.spoolPage() in turn wraps a direct call to the normal page rendering routines.
As it turns out there’s plenty of code in the GtkPrintUnixDialog, but it’s all quite straightforward.
It asks multiple GtkPrintBackend’s for GtkPrinter’s, and builds a UI around that model. With much of the effort going into populating/updating a GtkTreeView listing all these printers and custom-rendering an illustration of the page layout.
Once a printer has been selected with some page settings, you can use GtkPrintJob to actually initiate the printer. Or rather you should use GtkPrintOperation to call both of these (akin to GtkFileChooserDialogNative), but WebKitGTK doesn’t.
This’ll enqueue itself on a GtkPrinter object, which in turn dispatches it’s methods to the appropriate GtkPrinterBackend. These backends are loaded by some dynamically-loaded modules.
These objects do little more than store the data.
The backends bundled with GTK are:
- Google Cloud Print - a centralized webservice with it’s own HTTP/JSON API
- CUPS - a federated webservice running on your computers and (ideally) wireless printers adhearing to the IETF IPP standard.
- LPR drivers
From what I recall CUPS is a fairly straightforward serverside webapp written in C which queues up print jobs until they’re ready. And with that printers have no excuse for being so hard to setup.