Tables GSoC Update

Here’s a little update on my GSoC progress. Time really flies and we have less than two weeks left until pencils down!

Some of the things that has happened in KOffice tables land since last time is:

  • Fixed a bug in relative table width loading.
  • Further improved KoTextDebug to work with the new styles for tables, rows, columns and cells.
  • Added support for column width and relative column width. Up until now all columns were hard coded to equal widths.
  • A KoTableAndRowStyleManager has been added for managing column and row styles.
  • Fixed a bug where two subsequent tables were painted on top of each other.
  • Added support for minimum row height.
  • I began to re-factor the table layout to use a list of rectangles that describes the table instead of a simple rectangle, and started thinking about table breaking. Pretty soon though I realized that I was probably in over my head, and passed the torch to Casper, who has been hard at work trying to get the first pieces in the breaking puzzle, hard row breaks, to work. I just got word on IRC that he may just have it working (!).
  • Finally fixed the issue with an empty line above tables. This text block is there by necessity; it’s mandated by Qt Scribe. Me, Thomas and Casper discussed a bit on how to best handle this. And at least for now, we’ve chosen to solve it like Qt does in its own layout engine, which is putting the empty block to the left of the table. We might do some improvements to the user interaction here though.
  • Added three new classes; KoTableFormat and its subclasses KoTableColumnFormat and KoTableRowFormat. These are very much like the QTextFormat classes in Qt in that they’re simple implicitly shared classes that hold a set of properties. They are not used yet, but will be soon.
  • Fixed bug in justify aligned tables when an explicit width is also specified.
  • Fixed up the table layout code to handle nested tables, as it was totally oblivious to them up until now.

In addition to these things there were some other small fixes, and I’ve also worked a bit on the tests, which all needed fixing after Casper’s re-factor. More work to be done on testing though and right now I’m looking at adding some loading tests to the test suite that Girish created.

On Tuesday last week I fell terribly ill, with high fever, and was mostly in bed or on the couch for a good two days. I’m back to full health now though. I think it might have been food poisoning.

The future of the column and row style manager I mentioned above is unsure though. At the moment it’s just a container for pointers to the styles, and the loading code tosses them in there and decorates the QTextTable with a property containing a pointer to the manager. Not really the prettiest of setups, and we need to find a better solution. The format classes I added are a part of this puzzle, but the question is; where do we store these formats?

I’m sure we’ll work it out though, and now I need to get back to coding. Sorry if this post was a little duller than my previous ones, but to cheer you up, here’s a screencast in which I save a set of nested tables in Writer and open them in KWord to edit them a bit :)

Nested Tables from OO.o to KWord
Nested Tables from OO.o to KWord

Direct link (15 MB, Ogg/Theora)

Tables Sprint in Copenhagen

Hello again everybody.

Lots of stuff has happened since my last blog. It’s Monday afternoon when I’m writing this and I’m on the train back from the sprint that Casper Boemann and I had at his place outside Copenhagen this weekend.

Since Casper is now working on tables support as part of his employment with KO GmbH, we both agreed that it would be a good idea to have a meeting to make plans for our cooperation during the rest of my GSoC, but also do get some hacking done.

The weekend has been intense to say the least, and we’ve added support for several essential features of tables, such as:

  • Row and Column Spanning

    Row and Column Spanning

    Cells can span multiple rows or columns. The row height calculations have been updated to handle the case where a cell that spans multiple rows grows vertically from a text insertion; the last row that is spanned into will grow in height along with the spanned cell.

  • Table and Cell Styles

    Thanks to hard work from Casper, we now have KoTableStyle and KoTableCellStyle, which are proper styles for tables and cells, respectively. Work is underway for row and column styles.

  • Loading


    Casper also took the plunge on loading and quite quickly got stuff up and working, and with the commit he did right before I left his apartment, most of the features here should now be loading correctly from ODF.

  • Table Alignment and Margins

    Table Alignment and Margins

    Tables should now support all the alignment options in ODF; right, left, center and margins (justified), and they can have a left, right, top and bottom margin.

  • Table Background

    Table Background

    Tables can have a global background color set.

  • Relative Table Width

    Relative Table Width

    Tables can now have a percentual width that is relative to the page width.

  • Cell Background

    Cell Background

    Individual cells can have a background color set.

  • Cell Borders

    Cell Borders

    Cells can have borders, including double borders with a spacing between them.

  • Cell Padding

    Cell Padding

    Individual cells can have a left, right, top and bottom padding.

During our sprint, Casper focused on loading, styles and drawing, and also sat with me for some pair programming when we implemented spanning, while I worked mostly on the layout part and unit testing of the features.

All in all it’s been a great weekend. Of course there are bugs to be worked out, but the basics of these features are all there and working. Casper is a very friendly host and a great programmer. I have a lot to learn :) He also did all the cooking and made me feel right at home. Thanks Casper!

The weekend ended with a couple of hours of planning, and we made a detailed list of ODF table features that we want for 2.1.

It’s quite pleasing to see that the approach to tables in KOffice that we’ve chosen seems to be holding up, and I’m pretty sure it will work out for all the remaining features that we need to implement, of which proper table breaking across pages is perhaps the most tricky one, from a layout point of view. But that’s for later; right now I’m going home for some resting up, and I think Casper is doing the same back at his place.

Anyway, kids are screaming like crazy here on the train, so I think I’ll end this blog with a little screencast showing off some of the new features, and then put on my headphones and doze off.

So long!

Copenhagen Sprint Features Screencast
Copenhagen Sprint Features Screencast

Direct link (2:40 min, 15.2 MB Ogg/Theora)

On the train to Copenhagen

Hi again,

Right now I’m on the train down to Copenhagen for a little sprint/coordination meeting with Casper. As it turns out, he’ll be working on tables too and therefore we thought it would be good to get together and coordinate a little. And code like crazy of course.

I’ll be going home Monday afternoon, and hopefully there will be something blog worthy coming out of this. *yAwn*. Got up at 5 AM, so a little tired, but no rest for the wicked right? :)

Later, Elvis.

Tables Update – Heights

Hello again,

As you may remember from my last post, I was cheating in my screencast; the table height was hard-coded and the cell heights were not adjusted to content height. What I needed to do was to handle the following case:

Cell Heights Adjustment
Cell Heights Adjustment

I have just commited the beginnings of this in r997173. TableLayout now has an updateCellContentHeight(QTextTableCell&) API, which is called once the content of a cell has been laid out in Layout::nextParag().

There are a lot of rough edges, and my tests of course broke left and right, but it principally works, fingers crossed ;) Here’s a video demonstration:

Cell Heights Calculations
Cell Heights Calculations

Direct link (1:30 min, 7.6 MB Ogg/Theora).

I skipped uploading to Vimeo this time, as it’s so clunky. I don’t think anyone will miss Flash right?

Anyway, my dear mom just appeared and is taking me out to eat, then I need to start fixing/extending those tests, so bye for now!

Tables GSoC Status

Hi all,

I hope everyone had a nice time on Gran Canaria. It seems like it’s been a really successful event from all the posts I’ve read.

I’m not one of the frequent GSoC bloggers here on p.k.o, but as we are in mid-term now I thought I’d make a little summary of my thoughts around the project so far and give a little status report.

Initially my idea was to divide this post into two sections; “The Good” and “The Bad”, with a summary at the end. But then I realized that for almost every bad thing I could think of, I could find a good side to it, and vice versa. There’s always two sides to a coin. So instead I’ve decided to make a table. How appropriate ;)

(The table is styled and probably looks better at my blog page)
GSoC experiences so far
Table layout is hard. There are just so many things to consider, and a lot of side cases to take care of. Just look at Qt Scribe’s implementation. Lord knows I have :) But extremely fun and a very rewarding thing to work on. The feedback is quite immediate, which is very gratifying.
Unit testing is an art. You have to be very careful what you test for and how you go about it. Just writing the tests is not enough, you have to put a lot of thought into it. But it’s an invaluable tool when starting out and trying to focus on a specific aspect of a complex thing such as table layout. By the way, anyone who can recommend a short little book on unit testing? Preferably something as concise and “hands-on” as e.g. Meyers’ Effective C++.
I have probably over-estimated my abilities as a programmer. I tend to try to consider all the consequences of the changes I do at once and look into the future, instead of focusing on the actual problem at hand, and this tend to be a real show stopper for productivity. As my good mentor Thomas put it; perfection is the enemy of productivity. But I’ve learnt a lot about my abilities and limitations, and I feel that I’m improving. I’m confident that by the end of this summer, I will have grown as a programmer.
Git can be confusing. Coming from centralized VCSs like SVN and CVS, wrapping your head around this new-fangled distributed VCS can be quite daunting, especially as the user interface is a veritable swiss army knife of funky names and idioms. A text that really helped me understand how Git works was The Git Parable. And for the more technically inclined I’ve heard good things about Git for Computer Scientists But it is a God-send after all, and I can’t wait until all of KOffice (and KDE) is on Git. Things like cherrypicking, interactive rebasing and extremely easy branching/merging is just too good to say no to. I’d like to make a parallel to when I first learned Vim. No pain no gain right? ;) Recent posts here on the planet, if I understand them correctly, indicates that there are talks about hosting KDE Git repos at Gitorious, which sounds like a good idea to me.
The payment schedule of Summer of Code is kind of unfortunate. At least if you have high fixed expenses every month, as you’ll have to go all through June without any money. This is something to think about if you’re considering participating. I was lucky to be able to loan money for my rent/Internet/electricity/phone bill. But this is definitely understandable. Having monthly payments would mean having monthly evaluations and a lot more work for both mentors and Google staff members. I guess a lot of students in the program live with their parents and don’t have a lot of expenses. But I’m (almost) an old fart as far as students go ;) Just bringing this up, as it can become an extra stress factor.

All in all, I’m having a great GSoC so far, and I think it can only get better.


Now on to some information about my progress. What I’ve been working on is getting some first basic table layout working. The design is quite simple so far, and looks very roughly something like this:

Table Layout Design Overview
Table Layout Design Overview

The Layout class is the innermost class of the text layout engine in KOffice, and is the one responsible for most of the nitty gritty details of text layout. It is declared as an inner class of KoTextDocumentLayout, which has an instance of this class called m_state.

KoTextDocumentLayout in turn is a higher level class that derives from Qt’s abstract document layout class QAbstractTextDocumentLayout. Qt’s own document layout engine, QTextDocumentLayout, which is not shown in the diagram above, derives from this same ABC. I’ve also included KWTextDocumentLayout, which is a specialized KoTextDocumentLayout used in KWord. It adds support for letting text flow around other shapes, among other things.

What this all means is that KOffice’s layout engine, while still working with an underlying QTextDocument, is completely separate from Qt’s. Now, because of poor research on my part in the weeks leading up to the GSoC start, I actually thought I’d be able to leverage at least some of the built-in support for table layout in Qt. But I have only myself to blame for that, and it’s nothing to cry over now. What I do get is QTextTable, which can be considered a blueprint for a table, and my task is to lay out this table according to its properties, which I’ll later have to extend to support ODF features that don’t have a 1:1 equivalent in QTextTable and its associate classes.

I’ve modified Layout to have an instance of the new class TableLayout, which is responsible for doing layout and drawing of tables. It takes a QTextTable and lays it out, storing the layout information, such as table and cell geometries in an associated TableData instance. It actually caches TableData instances per-table internally. TableLayout offers an API to be used from Layout to obtain cell content rectangles to direct the layout engine into, as well as an API for adjusting cell heights based on the cell contents.

It’s a simple design, but one that I think will work out fine for all the requirements that will come later, and I already have ideas on how e.g. cell spanning should be implemented. Things on my TODO are too many to even enumerate, but what I’m working on right this minute is row heights calculations and finding a good way to let the layout process in Layout notify the TableLayout of cell content height changes. After that comes, among other things:

  • Margins/paddings/borders.
  • Variable column widths.
  • Tests, tests and more tests.

Now let’s see, this post has had a table, a diagram and a list. What’s missing? A video of course :) Take 50 seconds and marvel at me pasting a basic table from Firefox into KWord and editing the cell contents:

Direct link (5.7 MB Ogg/Theora).

Actually I’m cheating in the above video, as the table height is hard coded, but don’t tell anyone! ;)

Finally, I’d like to be honest and admit that progress really haven’t been as fast as I thought it would be, but I do feel that I’m on the right track. And even though the road ahead is longer than what I would have wanted, at least it seems pretty straight, all things considered.

Now if you’ll excuse me, I really need to get back to coding!

Bye ’til next time!