Wednesday, 13 April 2011

DjView4 plug-in in Mac OS X Firefox? Only under X11.

It was easy to find open tools to make decent-quality e-books from my scans of a classic text. Scan Tailor and djvubind are a killer combination for producing an e-book with positional, searchable OCR in no time. The URI and the web browser are central to what I'm doing at the moment, and DjVu is no use unless a single click on a URI will render it directly in the browser, jumping straight to the fragment of interest.

I'm deeply invested in Firefox and OS X and while the LizardTech plug-in lives on at Celartem and works on Firefox 3.6.x, it's closed-source, its toolbar buttons don't work and I'm not sure it'll survive for long. DjView 4 includes an open NPAPI plug-in which works on Linux but isn't available for OS X, so I thought I'd have a go at getting the DjView 4 plug-in working on OS X in case it was something trivial. It wasn't, and I thought I'd document why in case anyone else wasted their time wondering/speculating before (or after) the resulting patch gets accepted.

My first misdirected effort was to simply build the DjView 4.7 tree outside MacPorts and copy the resulting into the ~/Library/Internet Plug-Ins/ directory, hoping simple shared objects still worked like the good ol' Linux days. They don't; on OS X, plug-ins must be "loadable bundles" (well, technically a "loadable module" bundle within a loadable bundle, which also happens to be a package — and let's not even get started on flat packages).

My second misdirected effort was to simply copy the built into an existing plug-in bundle (updating CFBundleExecutable). The plug-in ceased to appear in about:plugins. I guess if Firefox cared to check, the stuff returned by NP_GetValue() would be inconsistent with the Info.plist, but that seemed unlikely.

My third effort was to build the plug-in as a bundle, using the OS X template plug-in from the new NPAPI SDK. After altering the HEADER_SEARCH_PATHS to include config.h, the MacPorts glib headers and the NPAPI headers and fixing a bunch of trivial compile errors, I hit a wall at:

DjVuPlugin.c: In function 'NPP_SetWindow':
DjVuPlugin.c:2484: error: 'NPWindow' has no member named 'ws_info'

NPWindow only has ws_info if you're compiling for Mozilla on non-OSX UNIX. Reading a little more closely, it turns out the plug-in runs DjView in a separate process, relying on Firefox support for either Xt or XEmbed to render the document, neither of which are supported on the normal Cocoa-based Firefox most OS X users use. (While it's possible to run X11-based Firefox on OS X and probably possible to build an Qt-on-X11 variant of DjView that would support the -netscape flag, it's not worth it.)

So we're stuck with Celartem's plug-in for now.