We’d need an interface. You might subclass the LowLevelGraphicsRenderer to a PrintingRenderer, which is further specialized to a PDFRenderer and possibly real printing renderers to be added later.
Another possible design is to have Printer and/or PrintJob objects which are factories for renderers that implement the LowLevelGraphicsRenderer interface without further public methods.
I can’t judge what’s best here, it depends on what suits your philosophy.
Whichever design wins, there should be methods for controlling these aspects of printing, and possibly more:
[list]paper size[/]orientation[/]resolution[/]quality[/]name[/]perhaps further options such as duplex.[/][/list]
Paper size can be given in inches or metric, or using enumeration values for standard paper sizes A4, letter, legal… I think you might want to dedicate a small class to specifying paper sizes so these conventions could be dealt with without complicating the interface of the PrintingContext. LibHaru defines an enumeration of standard paper sizes, and it might be wise to adopt these values.
Orientation is Portrait/Landscape and should be settable on page basis - it’s not uncommon for PDF documents to mix Portrait and Landscape pages in the same document. (Just imagine a book about landscape paintings - most of the book would be text pages in portrait orientation, but some pages would have a landscape painting so you would need to turn the book over to see it. In a PDF version, these pages would be marked as Landscape and appear as such so you don’t have to flip your head or monitor.) There are possible extensions of the Orientation, and some printer drivers allow flipping or mirroring but this can be emulated by coordinate transformations and isn’t necessary in the basic interface.
Resolution is obviously a dpi value, I don’t think we’ve gone metric yet here.
It’s possible that you’d want to work with multiple dpi values for various aspects of the printing process. Some DTP apps (Pagemaker, for one) let you specify a target resolution and calculate the text flow using that resolution, so the line breaks don’t change when you switch from your proofreading printer to the final high-res printing. For Juce PDF export, some features such as alpha blends and gradients might need to be emulated in the renderer and output as images, and it’s possible that you’d want to control the resolution of these images to avoid bloat.
For offset printer jobs, you might have to take control of the rasterizing - but I think we should leave that out of here. We’re talking general purpose printing, not print shop jobs.
Quality might control compression of images and perhaps switch on or off the emulation of alpha blends and gradients. For real printers, it might control ink/toner savings.
Name is for naming print jobs. I think the PDF files have embedded print job names, not sure though.
LibHaru deals with many intricacies of the PDF format and is IMO a worthwhile addition, at least to get started. Once we get the thing to work, there is still the possibility of factoring out LibHaru later.
Don’t worry about licensing, see http://libharu.org/wiki/FAQ#Licensing, as far as I recall, you’ve already included zlib and libpng in the source tree.
There are some things that will need some fiddling:
LibHaru seems to have its own Stream implementation and I don’t quite know how to connect this to a Juce stream. For my 2009 efforts, I let LibHaru write the whole thing to a stream of its own which was then rewound and copied to a Juce stream through a buffer. No big deal but direct streaming would be more elegant. I guess I could sort this out by digging into the LibHaru sources.
I don’t quite understand how to transfer fonts and images. I think PDF supports PNG or Jpeg but I haven’t sorted out the details. Maybe the renderer should do PNG-compression of images. Exploiting the Jpeg feature would probably require that they somehow be passed through the renderer and I don’t think that’s compatible with how Juce rendering works. But I suppose I could figure out a usable (if not necessary optimal) image transfer. With fonts, I am at loss. Since PDF is an Adobe thing, I assume it uses Postscript font technology but I don’t understand how to connect to Juce font rendering, and I think you would have to do this part.
Text encoding might need some work. Ideally, we’d just transmit utf-8 but I’m afraid PDF predates the utf thing and the encoding is a bit messy, and I don’t think LibHaru takes care of this - but other open-source PDF-generating apps do, so it’s basically a matter of deciphering and copying their encoding schemes. (If all else fails, I’ll grep the OpenOffice sources for PDF export.)
Then, there’s the issue of emulating alpha/gradient stuff - perhaps by using the software renderer to generate images. This might end getting parked on a to-do list. I’d find PDF generation quite useful even without gradients and alphas, and printing applications that need these still have the option of emulating them. Though this isn’t ideal, it’s better than not having PDF.
Enough for now… I hope you will take the time to pin out the interfaces.