Estimated read time: 6 minutes
Writer now has continued steps to handle tables that are both floating and span over multiple pages.
This work is primarily for Collabora Online, but is useful on the desktop as well. See the second post for background.
Motivation¶
The previous post finished with cursor traversal: if a floating table is on both page 1 and page 2, then you expect Writer to be able to move between the rows of the table, even if those are not on the same page. In this post, we'll see what else started to work during the past month.
Results so far¶
The feature is enabled by default and now the DOCX/DOC/RTF import makes use of it if. This allows stress-testing the layout code with complex user documents, hopefully with the found breakage fixed before it would be released in a stable version.
On the positive side, core.git repository has has 19 files now which are focusing on correct handling of floating tables. Also, there are additional tests that quickly build a specific multi-page floating table in the memory and do some operation on it, e.g. delete the last row and assert what happens.
Here are some screenshots from the effort so far:
The first case is about editing: if a floating table had a first, middle and last page, then deleting the last row of a table lead to incorrect layout, which is now fixed.
An odd problem is that the vertical position of tables on non-first pages is generated by the layout, which means that normal drag&move to position them won't work, leading to annoying jumps. This is now fixed by selecting the first (master) fly frame on click, and you can always reposition that table (even vertically.)
Once DOCX import/export was there, the next step is binary DOC import, which gives us access to a larger corpus of test documents, to stress-test the layout code. This shows how the binary DOC import looked before the work.
And this one shows how it works now.
DOC import is not enough, e.g. Collabora Online will save your documents automatically, so we really want to export everything that is possible to import. Here is how good DOC export looks like in Word.
At this point the first crashtest results arrived (we try to import about 280 thousand documents and see what crashes). The first problem was floating tables in footers. Well, we should not try to split such tables (even if they don't fit): adding one more page does not give us more footer space.
Similar to the DOC filter, RTF can express floating tables. Here is how we did a bad rendering of an RTF document before.
And here is how we import it currently. The RTF control words are quite close to the binary DOC markup semantically, just the syntax is different.
The RTF export side was also missing, as visible in Word, before the work.
And this is how the good RTF export result looks like in Word.
Another crashtest find was that sometimes we map Word's continuous section breaks to Writer sections, so we can't assume that tables are anchored directly in body frames. This is now fixed.
A related problem was that non-floating tables have a trick, that we call the TableRowKeep mode. If this is on (which is the default for documents imported form Word), a table row will stick to the next table row (we try to keep them on the same page) if the first cell's first paragraph in that row has the "keep with next" paragraph property specified. It turns out, this should be ignored when the table is floating.
A next problem was that some page breaks simply disappeared. It turns out that we need to transfer the "break before" property from the table to the table anchor (paragraph) to get the desired layout, since page breaks are generally ignored inside text frames.
All combinations of nesting with floating tables is not yet handled, but at least we should not crash when the user tries to do that. Here is 3 tables, nested in each other, the second table is marked to be floating.
The last fixed problem is when a floating table is immediately followed by an other, non-floating table. Given that we try to anchor the floating table in the next paragraph, the layout could not handle this previously, but now we ensure that each floating table is followed by a paragraph.
And that's where we stand. Hope to address all problems reported by crashtesting soon. Once that happens, it may be possible to switch from bugfixing mode to feature mode again, e.g. better handling of overlapping or nested tables could be done.
How is this implemented?¶
If you would like to know a bit more about how this works, continue reading... :-)
As usual, the high-level problem was addressed by a series of small changes:
- sw floattable: fix removal of empty master flys on master table removal
- sw floattable: fix removal of last follow fly with a start/middle one
- tdf#61594 sw floattable: import floating tables as split flys by default
- sw floattable: remove no longer needed DOCX import heuristics
- sw floattable: don't try to set left margin as cell property
- sw floattable: restrict selection of follow flys
- sw floattable: limit the unfloat button to legacy ODF files
- sw floattable: unconditionally map DOC table pos props to SwFormatFlySplit
- sw floattable, layout: don't split inside headers/footers
- sw floattable: fix CppunitTest_sw_ww8export's testTdf112346
- sw floattable: fix CppunitTest_sw_ww8export2's testTdf80635_marginLeft
- sw floattable: fix CppunitTest_sw_ww8export2's testTdf80635_marginRTL
- sw floattable: fix CppunitTest_sw_ww8export2's testTdf80635_pageLeft
- sw floattable: fix CppunitTest_sw_ww8export2's testTdf80635_pageRightRTL
- sw floattable: import floating tables from DOC as split flys by default
- sw floattable: remove no longer needed DOC import heuristics
- sw floattable, crashtesting: fix PDF export of forum-mso-de-117064.docx
- sw floattable: remove no longer needed ImportFloatingTableAsSplitFly setting
- sw floattable, crashtesting: fix PDF export of fdo80989-1.docx
- sw floattable, crashtesting: fix PDF export of fdo72790-1.docx, part 1
- sw floattable, crashtesting: fix PDF export of fdo72790-1.docx, part 2
- sw floattable, crashtesting: fix PDF export of fdo72790-1.docx, part 3
- sw floattable: DOCX import: m_bConvertedTable is now unused
- sw floattable, crashtesting: fix PDF export of fdo72790-1.docx, part 4
- sw floattable, crashtesting: fix PDF export of tdf114111-3.docx
Want to start using this?¶
You can get a snapshot / demo of Collabora Office 23.05 and try it out yourself right now: try the unstable snapshot. Collabora intends to continue supporting and contributing to LibreOffice, the code is merged so we expect all of this work will be available in TDF's next release too (7.6).