This page contains notes on the PCL renderer.
Determining the implementation approach
It's probably best to implement PCL 5 (and possibly PCL 5c for color output) which covers printers since the HP LaserJet III back in 1990. Support for that should be widely available. A big plus is TrueType support which makes it possible to efficiently paint large amounts of text with different font sizes and without having to construct bitmap fonts.
PCL itself seems to be relatively unexpressive. You basically have three kinds of paint operators:
- Bitmap images
For more sophisticated operations you can switch to HP GL/2 but even that language doesn't come near the expressiveness of PostScript. For example, you can only rotate in 90 degree steps, even in HP GL/2. That means that at least for a Graphics2D implementation all the coordinate system calculations will have to be done in Java. On the positive side, there are operators in HP GL/2 for complex shapes and text painting in arbitrary directions (rotation).
There are two basic approaches for an implementation of the Renderer:
- Use PCL text operators for FO text and PCL bitmap operators for bitmap graphics. Leaders, borders etc. are painted using HP GL/2.
- Use the Java2DRenderer to implement the FO part. A Graphics2D implementation will be necessary anyway to handle SVG (if no bitmap should be produced). This will mean that PCL is only used to set up a page and basically all painting would be done in GL/2 (except bitmap images for which only PCL provides operators).
The second approach is probably easier to implement but would make it necessary to bring the Java2DRenderer to the same quality as PDF and PS which should be done anyway at some point. At this point it's difficult to say whether there is any downside to this approach. The documentation doesn't give any hints that using GL/2 for text painting is any less efficient than text painting in PCL.
A possible approach could be to start with the second approach above and then decide whether to add special handling of FO text in the renderer (by overriding some methods implemented by Java2DRenderer).
Limitations making a full, native implementation difficult
- All graphics have to be pre-rotated, pre-scaled and pre-translated. Only basic coordinate system setup for HP GL/2 image windows.
- Clipping only in HP GL/2 and only for unrotated rectangular areas.
- Pen styles quite different from Java2D, PDF and PS. Dash arrays are problematic.
- Java2D's dithering capabilities are limited. JAI enables high-quality dithering.
- In PCL5, only black is available as pen color. Only PCL5c supports pen colors.
- No control over bitmap transparency. Raster graphics are always transparent/additive.
The limitations usually mean a quality reduction which can be avoided by rendering borders and all graphics to bitmaps.
What others did
The PCL renderer from FOP 0.20.5 only uses PCL commands, default fonts and does not support SVG. In FOP Trunk we now support different reference-orientations which starts to make the renderer more complicated. Full PCL support will require some level of SVG support, too.
A Windows printer driver for the HP LaserJet 4 may output most text as bitmap images. That probably depends on the font download setting, but it shows that it is quite feasible to paint text as bitmaps, too. However, this is probably relatively inefficient because it uses a lot of processing power in the JVM and makes the print files quite large.
Here are some PCL tools I've tried. If anyone knows of any additional (free) ones, please add them here.
Very good and free tool for working with PCL. Ships with a Windows binary for GhostPCL. Has a PCL decoder.
GhostPCL is generally quite good for converting PCL files but there are little issues like unsupported line caps and it produces huge, slow-displaying PostScript files from the PCL files.
PCL2PDF from Visual Software
Evaluation version with a stamp on each page. I tried the Windows command-line version. Small PDFs, but quality is bad.