Estimated read time: 5 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 fifth post for background.
Motivation¶
The previous post finished with an "almost done" state for overlapping tables: this is a cluster of problems where tables are allowed to overlap, but various other formatting make them not overlap in practice in Word, but they do overlap in Writer. In this post, we'll see what was necessary so an initial set of old documents now render perfectly, which started to work during the past month.
Results so far¶
The feature is enabled by default and the DOCX/DOC/RTF import makes use of it.
On the positive side, core.git repository has has 49 files now which are focusing on correct
handling of floating tables (filename matching floattable-|floating-table-
). 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 fixes this month (right click, open image in new tab for larger size):
The first case is about a document where the bottom of the page had a floating table, where the position (relative to the anchor) was a negative vertical offset. In this case Writer used to move the floating table to the next page, but now matches Word: the space in the previous page is used for the floating table. This fixed overlapping text on the next page.
The next case is about floating tables in footnotes, the anchor needs to have no visible margins to provide the correct layout.
This case was about an unwanted overlap of floating tables. Incorrect handling of the vertical offsets meant that the second floating table was rendered on top of the first one, making the text in the first floating table unreadable. Now we shift down the second floating table, so no overlap happens.
This document had a layout loop on load. The problem was specific to the case when the anchor text of a floating table started with a newline character, which has its own position in the document model, but doesn't really have a width at a layout level, so needs special handling. This is now fixed, the document loads and renders fine.
This document had only 4 pages, but lots of floating tables, carefully positioned to not overlap in Word. You can see how the old Writer rendering result was hard to read and it now looks correct.
Writer used to hide floating tables anchored inside hidden paragraphs, but Word shows them all the time, now we match this behavior.
The next document first had all of its tables in the first page, now fixed.
A remaining problem was that the second table and the footer area could still overlap. This is now fixed: Word sometimes does allow such an overlap, but it depends on the baseline of the anchor position, so in the current case we can detect that such an overlap is not wanted.
The last problem with this document was a poor split of the floating table, the first half row of the second table still went to the first page. Now we correctly detect that such a split is not wanted and simply start the second floating table on the second page, which results in a pretty good rendering of this document.
And that's where we stand. Certainly more work is needed to fix rough edges, but we get there step by step -- the theme is slowly transitioning from overlap problems right after load to unexpected rendering problems during editing.
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 negative vert offset with on page boundary without anch text
- sw floattable: fix lost floating table right before a table from DOC
- tdf#156059 sw floattable: fix lost 0 bottom margin of anchor in ftn from DOCX
- sw floattable: enable AddVerticalFrameOffsets compat flag for DOC
- sw floattable: make sure floattable after floattable gets own anch pos from DOC
- cool#6857 sw floattable: try harder to keep anchor text in the last follow
- sw floattable: fix lost floating table right before a hidden para from DOCX
- tdf#120262 sw floattable: don't wrap text around fly when no content would fit
- tdf#120262 sw floattable, legacy: fix text wrap around fly when no content fits
- tdf#120262 sw floattable, legacy: go outside body only for page frame vert pos
- tdf#120262 sw floattable: no split when none of first row fits the vert space
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).