My blog has been moved to ariya.ofilabs.com.
Showing posts with label wpg. Show all posts
Showing posts with label wpg. Show all posts

Friday, February 15, 2008

Karbon and WPG

After Inkscape, OpenOffice.org (Novell edition, ooo-build), and Abiword, Karbon in the next KOffice 2.x joins the array of open-source software which is, by using libwpg, able to import clip-arts in WordPerfect Graphics (WPG) formats. Since any Karbon drawings can be embedded in a document, of course this means you can attach and insert WPG clip-arts in a text document, a spreadsheet, or a presentation.

(There is still a rendering problem in Karbon as seen in the comparison screenshot. Hopefully will be fixed as it is approaching the release).

Monday, May 21, 2007

digest the curves, honor the pixels

Continuing my last year's GSOC, finally I managed to implement support for importing embedded raster images in libwpg. As with other graphics formats such as SVG, PDF, and ODG, WPG allows pixmaps or images to be combined with the vector graphics. It was a bit difficult because raster images are typically compressed using RLE (run-length encoding) and it was not too trivial to decode it. And I still do not code all possible depth/format yet. But finally, here is the mandatory click-to-enlarge screenshot:

WPG in Corel PresentationsWPG shown in Perfectspot

Left is the original WPG which I made in Corel Presentations by placing this beautiful windmill in Bremen together with a windmill picture from the clip art. Right is the WPG file opened and showed in Perfectspot (the all-around WPG viewer and converter).

Note that I'm waiting for Qt 4.3 before making a first stable release of Perfectspot (and also libwpg, provided that all image loading support is good enough). The reason is because it needs ObjectBoundingMode for QGradient which really simplifies the code. That's why, in the above screenshot, the gradient is not yet properly rendered in Perfectspot.

In related story, thanks to our very own Master Fridrich, libwpg-based WPG importer is going into ooo-build. So at least the next version of Novell's OpenOffice.org will be able handle those WPG files.

Wednesday, August 16, 2006

Stress testing

Recently I got WordPerfect 7 suite from ebay (which apparently can only be installed in Windows 95, but I don't really bother to install it) which comes with over 5000 clip-arts in WordPerfect Graphics (WPG) format. The total size is over 200 MB. This is a ideal test for libwpg and its tools (wpg2svg and wpg2odg). So far, the conversion tools do not crash handling all of them. I let it run also under Valgrind, and it is still running as I write this...

BTW, thanks to klik technology, the easiest way to check libwpg-based WPG support in Inkscape (what I wrote before) is by klik://inkscape-latest. Details can be found in http://inkscape-latest.klik.atekon.de. A very convenient way to check those old WPG collections.

Meanwhile wpg2odg starts to reach the same support level as wpg2svg, except where some complex gradients which can't be handled properly in OpenDocument Graphics format. It does not matter, as such uses of gradients are very rare anyway (from what I observed on those clip-art files).

Compare what OpenOffice.org shows below against what Inkscape renders (ignore the different proportion as I resized the whole picture in OpenOffice.org already). I really hope that future version of OpenOffice.org supports anti-aliased painting.

Back to those 5000 clip-arts. Now I have thousands of SVG and ODG files as well as a very long Valgrind log to analyze...

Tuesday, August 01, 2006

Inkscape WPG

Ted Gould implements libwpg-based WPG extension for Inkscape. So it's likely that the next 0.45 release can open WPG files directly. Very cool.

Monday, July 31, 2006

wpg2odg, now with colors

As I wrote before, finally I manage to correctly handle the stroke and fill in wpg2odg. The result can be witnessed in the following screenshot:

The two landscape pictures opened inside OpenOffice.org are in OpenDocument Graphics (ODG) format, converted from the corresponding WPGs (which are shown in Corel Presentation on the left side).

There are still bugs on some corner cases. When I clean this up, then I'll commit everything so that it's ready for public testing.

Friday, July 28, 2006

wpg2odg, wpg viewer, vs microsoft

I hope I don't bore the readers with another Whiskey-Papa-Golf goodies.

So far, at least I make some steady progress with the wpg2odg. Yes, this is a command-line tool which will convert WordPerfect Graphics into OpenDocument Graphics. From perfection to openness, so to speak. The corresponding UNO service (for seamless import from within OpenOffice.org) is planned, but I can't say when I could finish it.

As style handling in ODG is more complicated than SVG, my work with respect to stroke and fill properties of the objects isn't very fast. However, at least the outlines/paths are already imported properly. Shown in the screenshot below is OpenOffice.org opening eiffel.odg, which is the result of running "wpg2odg eiffel.wpg eiffel.odg". Compare it to the rendering in Corel Presentation and Inkscape as in my previous blog entry. So, it's like Eiffel in wireframe mode.

Of course, it's rather boring. But given couple of more days, I hope all the wonderful colors will be there.

Since libwpg is designed to be portable, I checked its status in non-Linux environment. So far I have tried to compile it on Win32 (not necessarily as dynamic library, lack of knowledge from my side) and it works well. At least with Microsoft, Borland, and GCC (Mingw) compilers. I am going to give it a try with Digital Mars and OpenWatcom later on, but I don't foresee any serious problem with the code.

I used the chance also to verify Perfectspot, another toy of mine which uses libwpg to show WPG files. So basically it's a stand-alone WPG viewer. I'll perhaps release it when it's fully polished, not sure yet whether there is a demand for such tool. Perfectspot is Qt4-based and using Arthur to render the graphics onto the screen. Screenshot can be seen below. The beautiful Earth is drawn by Marcelo Staudt (available in from Open Clip Art library). I just imported his SVG file into Corel Presentation X3 and then save it as WPG. Perfectspot opens and displays the WPG file just fine. Note how smooth is Perfectspot's rendering due to the antialiasing feature in Qt4, compared to that of Presentation's.

Since this blog got anothers hits from someone at microsoft.com with respect to WPG stuff, I decided to find out how good is the support for WPG in Microsoft Office. I inserted my favorite windmill picture (see the entry on gradient support) in PowerPoint 2002 and this is what I got:

Seems that the importer and/or PowerPoint has problem with compound polygons or grouped objects. Look at the blade in the middle (which consists of some sub paths), it should be transparent just like the other blades. Compare it to what our wonderful Karbon14 renders:

Also notice the lack of antialiasing in PowerPoint. Strangely enough, this is only for imported pictures. When I clicked and converted the inserted picture into Office drawing, then it was smoothly painted.

Alas, I saw another problem with the gradients. Instead of creating polygon with gradient fill, the import filter of PowerPoint splits the polygon into smaller polygon and fills it with solid color, as can be seen below (I select couple of those polygons to show that they are many many small objects indeed). You can quickly spot it if your eyes have native Sobel filter :-)

Is it only the case with Microsoft Office 2002? To verify it, I gave Office 2007 Beta a try. Despite its brand new user interface, it is just the same case: one blade is not transparent and gradient is converted to color bands:

Conclusion: when I am finally finished with all this endeavour, it is likely that applications like OpenOffice.org, Karbon14, and Inkscape can handle WPG files better than Microsoft Office. Or should we ask Microsoft to just use libwpg?

Tuesday, July 25, 2006

Eiffel in perfection

After few failed attempts, finally I managed to implement full support of the so called compound polygon for libwpg (see also the previous progress). This is WordPerfect Graphics' term for "grouped objects". Without proper compound polygon support, often some objects are shifted, i.e. not placed in correct position due to the wrong transformation.

As always, the obligatory click-to-enlarge screenshot follows. And as usual, Corel Presentation is on the left side, opening a picture from the clip-art. On the right side, Inkscape (before I showed only Karbon14) is showing the converted SVG.

Coming soon: from WPG to ODG. Yes, that's OpenDocument Graphics...

Sunday, July 09, 2006

Beauty is in the smoothness of the colors

In the recent days (see also the last progress), I have implemented support for two important things for libwpg: object transformation and gradient.

Object transformation is necessary to have rotated or scaled objects. And most important is for translated objects. In Corel Presentations, when you copy an object and move the copy, the two still shares the same data but have different transformation matrix. Thus, in order to have all objects in proper location, transformation support is necessary.

Another interesting bit is gradient fill. This presents some challenge as the documentation does not say anything except the data structure, and the gradient concept in WPG does not actually fit into SVG model. After wasting many sheets of paper and scribbling lots of (mostly wrong) equations, I found the solution which may match WPG's gradient with SVG. So far it works with linear gradient.

In the screenshot below (click for larger version), you can see the perfect conversion of the gradients. Left side: WordPerfect Office (inside emulator) shows windmill.wpg. Right side: Karbon14 opens windmill.svg, which is windmill.wpg converted to SVG using libwpg's wpg2svg.

Note 1: there are still rendering problem as I have not yet coded proper evenodd fill rule with grouped polygons.

Note 2: Karbon here is just for illustration purpose. Inkscape (or other vector drawing programs which support SVG) works also flawlessly.

Thursday, July 06, 2006

Microsoft and WordPerfect

Microsoft trying to improve support for WordPerfect graphics? (just like what I'm doing now for libwpg):

Referring Link: http://www.google.com/search?hl=en&lr=&q=sample wpg files

Looking at that log, at least their Google search had landed in this blog :-)

Saturday, June 10, 2006

Curvey landscape

Decrypting Bezier curve in WordPerfect Graphics (WPG), for the libwpg project, turned out to be not so easy. First of all, the documentation is rather very brief. The curve is specified in some triplets, where each triplet consist of initial control point, anchor point and terminal control point. This hardly tells anything useful at all. In fact, first I thought this is about quadratic Bezier curve, which was of course wrong, as it is cubic Bezier instead.

The trick was finally quite simple, I should have though about it before. I just need to match each of those three points with the actual nodes and control points, this I got from within Corel Presentation by checking the cursor position when hovering over the corresponding points.

After knowing the meaning of the triplet points, it is quite easy to adjust the WPG-to-SVG conversion tool. As the proof, shown here the screenshot of two wonderful landscape drawings. On the left side is the WPGs inside WordPerfect Office, on the right side is the converted SVGs shown in Karbon. Quite a perfect conversion so far.

Tuesday, June 06, 2006

Emulator for filter development

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.