Thursday, June 26, 2008

Getting started with KWord Development

About 2 months ago, I started working on KWord ODF support. Getting productive working on KWord is no mean task - apart from the mandatory C++/Qt knowledge, one need to know Scribe, KDE, KOffice libs and KWord. I knew only C++/Qt and basic Scribe.

Thankfully, to add small ODF features to KWord, one can conveniently ignore most of the code base and concentrate on 4-5 files. Which is what I have been doing - committing like crazy to 4-5 files :-) Of course, I have never been at ease with this, I usually don't develop this way but I wanted to have something up and running asap. Now that we (Roop and I) have most of the (supported) ODF test automated (63 in all), I took a 1 week break to read and understand the KWord/KOffice code.

If writing a word processor is not complex enough, KOffice/KWord code is extremely complex thanks to all the code sharing between the koffice applications, libraries, plugins/flake, kparts. So, I thought I should do something on my part to make KWord more approachable to a newbie. The result is:

http://wiki.koffice.org/index.php?title=KWord/Tutorials/LoadingOdf

It's a code walk through/very detailed introduction to how loading of ODF works in KWord. I have deliberately opted for simplicity over correctness in many places. Some information there might be outright wrong, in which case, please edit the document and fix it (hey, I am new to this stuff too). Also, this probably belongs in techbase.

Writing this document has made me realize that writing code is so much simpler than understanding existing code :-)

Anyhoo, Comments/Suggestions?

P.S: I am in the process of writing the SavingOdf document.

Saturday, June 7, 2008

Drop caps

Last week saw the introduction of a brand new feature in KWord: crap drops. Er, I mean, drop caps. You can specify how many lines it should span, how many characters to drop, and even the extent of horizontal gap between the dropped chars and the rest of the paragraph (all only through the odf file, for now). But if if you ask me, I just like the plain old three-line single character drop char (thanks, Thomas, for the screenshot).

dropcaps screeny

Compared to Word 2007 and OpenOffice 2.3, it works pretty much the same usual way in, er, usual circumstances. But in subnormal scenarios, like for example, when the paragraph doesn't have as many lines as how many lines the drop cap spans, or in the case where the paragraph has a mix of quirkily extreme font sizes, all three word processors behave differently, and somehow, I can't point to any of them and say that's outright wrong. So, if you have any inputs on how KWord's drop caps behaves or should behave in certain situations, please leave a comment or mail me.

Now for the how-stuff-works part. What I've done is, create a separate new line for the set of dropped characters (setNumColumns), and increase their font size on the layout by the number of vertical lines they should span (setAdditionalFormats). Then it's only a matter of shifting out a few subsequent lines horizontally without changing their vertical positioning (setPosition) and reducing their width to accommodate the dropped characters abreast of these lines. That, in brief, is about it. Mostly.
Sample odts: dropCapsLines.odt, dropCapsLength.odt, dropCapsDistance.odt