LibreOffice Master Document Fixes

Earlier this year, allotropia software GmbH was awarded a tender to fix a number of problems around the master document feature (Tender to implement master document fixes (#202106-02)) by The Document Foundation (TDF).

We have finished implementing the necessary changes, and all fixes will be available for testing in LibreOffice 7.2.2.

Using master documents is a somewhat hidden, but extremely useful feature of LibreOffice Writer, when producing longer documents (like books, or the help guides the LibreOffice documentation team is maintaining). With it, users can split a larger document into a number of smaller pieces, to work on independently. If this feature sounds interesting to you, the excellent Writer Guide has a chapter about it.

We’ve worked on the following bug reports:

Bug 103612 – Table of Contents never shown in Master Document

It turned out that the problem here was that one of the confusingly many flags that determine whether a document section is hidden was copied erroneously to a different one of these flags when copying a child section of a hidden parent section. We have removed the offending line of code, improved the in-line documentation of these flags in the class declaration, found 2 more places in the code that appeared to check the wrong hidden flag, and added a unit test (so any further changes in this area cannot break this feature again):

Bug 128106 – creating a master document from .odt breaks cross-reference links

Here the problem was that the function that splits the source document into multiple chapter document forgot to copy bookmarks out of the source document. So we took an ambitious approach and changed the function to call CopyWithFlyInFly() instead, which is the same function that is used during copying to the clipboard – and that one happens to copy bookmarks as well, among other things. We also added a unit test:

This fixed retaining references to ordinary bookmarks, but then it turned out that the selection from which the chapter documents are copied hits a corner case in the bookmark copying code for the heading cross-reference bookmarks. This is because their position is exactly at the start of the selection, so they were not copied. So we figured out how to handle this tricky corner case so that the cross-reference bookmarks are copied:

Bug 128106 before: screenshot with broken references
Bug 128106 fixed: screenshot with working references

Bug 142129 – Exported PDF of master document with hidden sections is broken

Unfortunately we were unable to reproduce this bug anymore. Fortunately it turned out that another developer had meanwhile already fixed it (thanks, Sweetshark). We resigned ourselves to at least adding a non-trivial unit test for the bug, which uses VCL’s PDF import features to read the outline of the exported PDF file:

We would like to thank The Document Foundation, and their countless donors, for funding these improvements to LibreOffice!

2 thoughts on “LibreOffice Master Document Fixes

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: