PDF::Cairo lives!

After a few more epicycles (and a two-week vacation in Japan), I have about 95% compatibility with PDF::API2::Lite, covering pretty much everything I’ve used in my scripts over the years, so that they work with a two-line change. Along the way, I learned just enough about fontconfig to coax it into finding my real Adobe core fonts based on their legacy PostScript names; I’ll need to figure out the substitution crap for any system that only has free equivalents installed, of course, but that’s for when I clean it up and add a test suite before releasing to the world.

As a bonus, my most recent epicycle was calculating the exact values of ascender, descender, and xheight for non-exotic fonts, which is more useful than the font designer’s opinion when you want to precisely position the top edge of a string (as in, say, a calendar; I was able to completely rip out the unreliable hackwork from the PDF::API2::Lite version).

Currently missing: skew transformations (matrix math), elliptical arcs (matrix math), full Cairo path support (new feature), Pango layouts (major new feature), rendering JPG/PNG/GIF/etc (under-documented API calls…), and a PDF::API2 compatibility method for cjkfont (requires messy fc-match tinkering, and I’ve never used it…).

And I just thought of another epicycle! A lot of my grid-based PDF scripts make use of a little box-manipulation library I wrote years ago, that does things like ISO folds, centering, cropping, etc, and recently I started going over the API to clean it up and improve its functionality. Then I realized: I only use this for PDFs, and I’ve already copied the big paper-size library into PDF::Cairo, so why not just make it PDF::Cairo::Box? One-stop shopping, and it will make my calendar generator even cleaner!

5/10 Update

Basic test/install done for the packages; need a lot more test code before I can release. Revised Box module really cleans up the calendar script. Played with Pango just enough to learn that it’s fragile and quirky and expensive to load, but has potential when you need real text layout; couldn’t get vertical text out of it, though, and the feature request for furigana support has been open since 2005.

If I have any working brain cells tonight, I think I’ll work on tests for the matrix transforms to get skews and arcs working correctly. Maybe take a first crack at image methods.


Well, that wasn’t so bad. Got skew transforms to work, and got PNG images to load, scale, and display correctly. I may punt and use ImageMagick’s convert CLI utility to handle other image formats. There is a Perl ImageMagick library, but I’ve never been able to get it to work correctly with a perlbrew-built Perl on a Mac, and just calling convert is easier.

5/12 Update

The last item missing for full PDF::API2::Lite compatibility is the stripped-down version of the textstart/textend functionality that I’ve never used. Adding the full API2 version of this would be more complicated and less useful than integrating Pango layouts, despite the latter’s significant startup time and entertaining quirks (such as Pango’s two completely different integer units, both of which are referred to as “Pango units” in the documentation: 1/1024pt for general positioning, 1/10000em for vertical positioning of glyphs).

As a bonus, because PDF::API2 is mostly pure-Perl, PDF::Cairo is about five times faster, similar to the speedup I got the time I converted one of my scripts to use the abandoned Haru library.

Comments via Isso

Markdown formatting and simple HTML accepted.

Sometimes you have to double-click to enter text in the form (interaction between Isso and Bootstrap?). Tab is more reliable.