Tuesday, September 25, 2007

WPG Import

Recently in Barcelona, I was interested to hear there was some confusion over how the beautiful Word Perfect Graphics import was created. Since it is now shipping in most ooo-build based OO.o 2.3 versions, it'd be great to give full credit for all those who got over the time involved in it's creation and use in various FOSS applications.


At certain point in 2006 I realized that because of lack of time I was neglecting one little useful library that I was also developing, libwpg and I made in my blog a call for new developers hoping that someone will bite the bullet.

Mathias Bauer (from Sun Microsystems) contacted me and proposed me work on this library could become part of OpenOffice.org SoC projects for 2006. After some e-mail exchanged, we agreed on the modalities of the participation: that libwpg will be developed as a standalone library (since it already existed as such) under LGPL because it was meant to be reused by other applications. Another agreement was that the goal was that the output of the Summer of Code will be standalone converter for wpg files to odg file format. This converter was supposed to be licensed under LGPL and its author was supposed to share his copyright with Sun under our beloved JCA terms.

Summer of Code candidate

I was contacted by several students in private and my choice was Ariya Hidayat of Koffice fame. The reason was that I knew his code and was quite sure about him being able to do good work on the library and converter. I worked (in my own free time, btw) together with him during the SoC on separable features, like reverse-engineering the WPG1 palette or implementing OLE2 stream abstraction. And it was really great to collaborate with Ariya who is an extraordinary hacker. What was promissed, that was done. Ariya's project got accepted for the Google summer of code, he signed the JCA, developed the library and added into it WPG2 support. In the same time, he developed a command-line tool called wpd2odg in a separate module. When the GSoC came to the end, the conditions for a successful accomplishment of the project were satisfied, the student got USD 4500 reward, Team OpenOffice.org e.V. got USD 500 and some Google swag like t-shirts and (paper) notebooks changed hands too. The "contract" was fullfilled and everybody was happy in the best of the worlds.

During the work on his Summer of Code, Ariya did an extensive blogging action, and one of Inkscape developers used a private copy of not yet released libwpg as a base for their WPG import.

After the Summer of Code

During the nights of the OpenOffice.org conference in Lyon, instead of sleeping, your servant was trying to implement a WPG import plugin as an add-on component for OpenOffice.org, one of those beasts that one builds using the SDK and that one installs using the Extension manager. It became clear that one had to refactor the wpg2odg command-line tool from scratch so that it generates Sax messages instead of a string in ODG file-format. At the end of conference, there was a refactored version of the wpg2odg tool and a non-working wpg import filter plugin for OpenOffice.org. Your servant's little brain managed to debug the plugin and have it detect correctly the WPG files and actually show some images only at the begining of October 2006.

Immediately, an OpenOffice.org integration was intented. It means, your servant tried to incorporate this plugin into the OpenOffice.org build-system as a new module. Nevertheless, since the implementation met some problems of locking when trying to imbue a locale into a C++ std::ostingstream, and your servant was pretty busy looking for a job that would help him feed his family, the work stopped there.

In the meantime, Dom Lachowicz of AbiWord fame modified the libwpg library adding into its API an SVG generating class so that it could be better reused by SVG supporting applications. Later, Marc "uwog" Maurer, implemented, using the libwpg SVG generation class, an AbiWord plugin enabling use of WPG cliparts in AbiWord files.

Hired in March 2007 by a nice company to work on OpenOffice.org, your servant requested permission to do some work on WPD and WPG filters in company time. The permission was granted and the whole odg generation framework used in the previous plugin rewritten to avoid having to use the problematic imbue on the stream (or the stream at all). The result is a patch that landed into ooo-build on 7th of May 2007. Since then, it underwent many changes due to the sharp eyes of Rene Engelhard and also due to an extensive QA by Sum1 whose favourite sport of trying to crash and tear down anything I produce is a great way to assure that my software is having a good quality inspite of the limited brain activity that TrainedMonkey is capable of.

This Summer, Ariya worked again on the libwpg library and added conversion of WPG bitmaps embedded in WPG files. During the Novell Hackweek, your servant wrote a BMP generator to be able to pass these bitmaps to OpenOffice.org and also added handling of embedded binary objects in alien file-formats (wmf, png, eps, ...). Again, thanks to AbiWord's Sum1, we were able to add handling of bitmaps in almost all supported colour-depths (indexed and direct). The result of this work is to be found in any ooo-build based OpenOffice.org 2.3 version.

Who did what

Libwpg library was written by Marc Oude Kotte, Marc Maurer, Fridrich Strba, and Ariya Hidayat. Some of the copyrights are owned by Novell because your servant was working on this library in his company time too. Some build patches were submitted by Robert Staudinger of AbiWord fame. The library is released under the terms of LGPL with some parts being licensed under BSD license.

Wpg2odg (command-line tool and the OpenOffice.org WPG import plugin extension) was written by Ariya Hidayat and Fridrich Strba. Sun Microsystem is joint copyright holder of some parts of Ariya's code and Novell is owning copyrights of some code contributed by your servant. This tool/plugin is released under the terms of LGPL with some parts being licensed under BSD license. One can use it as an OpenOffice.org extension, provided that one has libwpg library installed on the system. As a matter of fact, it runs even on some non-free operating systems with some non-free office suites.

The integrated WPG import filter in ooo-build is licensed under the terms of LGPL and copyright holders are Fridrich Strba with Novell for a huge majority of the code, Ariya Hidayat jointly with Sun Microsystems (for certain parts of the code). The patches from the above-mentioned links are free software and can be used by anyone under the terms of LGPL.

I would like to thank all those who contributed to making wpg import a reality on the free software desktop. And for those who are interested, libwpd 0.9.0 (whenever its release happens), will use libwpg for converting images embedded in WordPerfect documents.