My hacking portfolio so far involves developing over a half dozen conversion filters for KOffice. It’s quite obvious that filter coding is not always fun. Sometimes the file format documentation does not exists at all, often it is also wrong. To certain point, it would bring you to reverse-engineering and trial-and-error steps.
The easiest way is of course to have an application that creates the document natively. If you have any doubt, you can always use it to create or modify the file in question. The problem is most of time these wonderful applications run only under non-Unix OS. Here where emulator solves the problem.
What I used nowadays is QEMU. I’m sure you can as well use VMWare, especially since they now have the free VMWare Player, but when I started some time ago the Player did not surface yet. Pre-QEMU, I had to go through the difficulties of using Wine.
My latest endeavor is libwpg, a library which reads WPG (WordPerfect Graphics). It’s a vector graphics format (think SVG). WPG files can be created natively using Corel WordPerfect Office (more precisely, with its Presentation application). Here are the steps that I do, assuming I have QEMU installed and ready to use.
First, create a disk image to be use as the “virtual disk”. Something like this:
qemu-img create -f qcow vdisk.qcow 500M
and I’d have a half GB of virtual disk. Do not worry that it would consume all the precious disk space. Using the qcow format, the disk grows automatically when necessary. In fact, right after creating it, the size is only 2 KB. Later on when something is installed there, then it will grow itself.
Now since WordPerfect Office needs a Microsoft Windows, we need to install it on that fresh disk. The trick here is to choose an older version of WordPerfect Office (because WPG format is fairly backward and forward compatible) and an ancient version of Microsoft Windows. Both cost quite cheap on ebay. For example, I settled with Windows NT 4.0 SP6 and WordPerfect Office 10 as the guest operating-system and guest application. Bonus, that half GB will be more enough for these two.
So inserts the install CD and run:
qemu -hda vdisk.qcow -cdrom /dev/cdrom -boot d
that will boot our virtual machine from the CD-ROM, thus allowing the installation of the guest operating system. When finished, continue with the guest application. Even without the accelerator module kqemu, everything should run pretty fast on a quite modern machine.
So now that I have WordPerfect Office running on that poor little virtual machine, the next step is to create, open and modify WPG files. The big problem is of course that I have to be able to access it also from my libwpg environment. QEMU’s virtual FAT feature nicely solves that. For example, by running it like this:
qemu -hda vdisk.qcow -fda fat:floppy:rw:/home/ariya/vfloppy
then inside the virtualized machine, I’d have access to directory /home/ariya/vfloppy (on the host machine) as if it is a floppy disk (of the guest machine). Beautiful, isn’t it?
In old version of QEMU, I have to use the network by either setting up SMB or some file server. This often did not work smoothly. But the above virtual FAT is both painless and flawless.
The obligatory screenshot below – as usual, click to enlarge – shows a simple WPG file opened in Corel WordPerfect Office (its native application) running inside QEMU’ed machine and an SVG file converted from that WPG file opened in Karbon:
Now back to coding.