Montag, 24. August 2009

GSOC [KFormula shape] Wrap up

So I should have blogged already a week ago, but Internet connection in Jerusalem (I am doing a Hebrew language course here right now and will continue to study math for one semester beginning in October) is not completely satisfying.

So GSOC is over and here is what I have done:

I worked on the formula (or equation) editor of KOffice. KOffice is based on the flake framework, where every content element type is implemented as a plugin, the flake shape, with one or more associated tools. For mathematical equations the formula shape (and the formula tool) are used and this is what I worked on. With the move from KOffice 1.x to KOffice 2 an almost complete rewrite of the formula shape started. When I started there was already a lot of loading, saving and rendering code and the basic outlines of the tool, but almost no navigation and editing logic.

What has been achieved:

  • mouse and keyboard navigation including selection support
    • this is much more complicate for equations compared to e.g. plain text, because in equation you have a two dimensional layouted tree of nested subexpressions where it is sometimes hard to find out the element, that the user wants to navigate to
    • this was implemented for basically every MathML element that we can load
  • insertion from the keyboard
    • at the moment, when the cursor is in a token element, e.g. a number, that next symbol inserted is always added to the current token. This allows the greatest flexibility and is necessary, as MathML allows numbers like "two", but is a little uncomfortable, because the user has to decide, when to start a new token
  • insertion of symbols and MathML templates
    • you can insert all kind of mathematical symbols (they are just inserted as unicode letters)
    • you can insert MathML templates (fractions,...) , complete with wrapping of the current selected elements
  • Undo/Redo (see the previous post about why this is difficult)
  • loading and saving of MathML files (this was already implemented before but had some bugs that prevented it from working)

What still has to be done:
  • allow the changing of attributes of MathML elements, there is already a command for this, this mainly needs a GUI
  • remove unnecessary redraws (only elements that really changed should be updated)
  • finish rendering support for all MathML elements
  • implement a fast input mode, which starts a new token when e.g. a number is inserted and the cursor is in a identifier element
  • implement copy and paste (almost finished)
  • various bug fixes (some rendering bugs are easy to spot in the screencast below)
  • all kind of goodies: latex like input, ...
How to try it out:
I GSOC work is in KOffice svn trunk, so you just have to get a recent checkout
(see http://wiki.koffice.org/index.php?title=Building/Building_KOffice)
and ensure to enable the FormulaShape by adding formulashape to
the FlakePlugins setting in ~/.kde4/share/config/kwordrc (or ~/.kde/share/config/kwordrc or whatever your distro uses).

Some last words:
GSOC has been a really great experience, I learnd a lot about C++/QT/KDE Programming and the KOffice codebase is a real pleasure to work with (of cause it has some rough edges sometimes too). So thanks a lot to my great mentor Alfredo Beaumont and to the whole KOffice team. Of cause I will continue hacking on the formula shape and maybe other parts of KOffice.

In other news since a month ago I am engaged to the most beautiful and brilliant girl that ever set his feet on this planet and therefore I am maybe the first student to use his GSOC money mainly for his wedding :)

And here comes a screencast of the formula shape in KWord from trunk in all its glory:



video

Sonntag, 2. August 2009

GSOC [KFormula shape] update

Wow almost 2 months went by without me blogging. So it is urgent time for a status update of my GSOC work. In contrast to blogging I luckily didn't stop coding. So what has been done:
  • working keyboard and mouse navigation
  • inserting stuff from the keyboard
  • inserting symbols and templates from the docker
  • Undo and Redo
Especially implementing the Undo mechanism took me a while and some sleepless nights, because there is a strict separation of the flake part (which is responsible for embedding the formula shape in KOffice and event handling) and the back end part, which will hopefully become a independent MathML library one day (well it actually is code wise right now, but the kformula shape is the only user atm). Since the editing is done in the back end, we need some way to inform the shape and the tool, that its content has changed, we can't rely on the tool being still around when doing undo, ...

I solved this by letting each editing command return an QUndoCommand which is then passed to the tool in KOffice which wraps it in another QUndoCommand that is responsible for calling the first one and then calling update on the shape and tool. Works quite well.

Next things on my list include some refactoring of the movement code and finishing it for the missing elements. Changing some internals that make inserting and removing stuff a lot easier and finally maybe copy and paste.

So the KFormula shape is now able to create this formula.