Processing Bug Fixes: SVG, PDF Problems Solved

Import and export is, of course, a huge workflow factor for anyone, especially anyone from a graphic design background. Some of my students at MassArt have been kicking the tires on Processing’s SVG and PDF libraries and running into hitches. There’s nothing more frustrating than getting an obscure error message when you think you’re doing things right. Happily, we’ve got some solutions.

Of course, it’d be great to hear from others with similar issues.

The following libraries might also be of use:
http://www.texone.org/prosvg/
http://processing.unlekker.net/SimplePostscript/index.html

PDF

Several students had problems with font embedding using the built-in library. Symptoms: strange, blocky letters. The issues seem to occur on Mac OS X (all the students in this case I believe were on Mac exclusively.) The reference documentation for the PDF library offers this clue:

Starting in release 0120, text is no longer treated as shape data by default, meaning that the font will need to be installed to view the PDF that’s created. The upside is that the PDF will render better (particularly in light of the Mac OS X bug noted here). To force text to be treated as shape data, use textMode(SHAPE), immediately after size(). See the developer reference for textMode() inside PGraphicsPDF for more specifics.

But so far, forcing SHAPE hasn’t been very helpful.

Colin Owens has this tip instead:

Placing:

hint(ENABLE_NATIVE_FONTS);

before text();

does the trick.

This needs to happen before all your other font/text code. (I believe setup() is optional.)

I also suggested, for those on the Mac, at least, that people get fonts working on Mac and try re-saving in Preview.app for cross-platform / cross-machine compatibility as needed. (The same would be true with Acrobat or any PDF builder on any platform, just in case the library is misbehaving.)

Oddly, people are still having issues in which the first couple of characters are garbled, so they’ve taken to hiding the first two characters used. Bizarre.

SVG

Mahesh Gudapakkam was having some problems with the SVG graphics format, even following examples from Ben Fry. Nicely enough, he solved it himself.

Basically, the issue was tag information being handled in a way other than he intended, thus triggering an array out of bounds error.