Slide 1

Slide 1 text

Continuous endnotes in Writer Miklos Vajna Software Engineer [email protected] 2024-10-11

Slide 2

Slide 2 text

2/18 About Miklos ● From Hungary ● More details: https://www.collaboraonline.com/about-us/ ● Google Summer of Code 2010 / 2011 ● Rewrite of the Writer RTF import/export ● Then a full-time LibreOffice developer for SUSE ● Now a contractor at Collabora

Slide 3

Slide 3 text

3/18 Continuous endnotes in Writer Results so far

Slide 4

Slide 4 text

4/18 Visual diff: before fixing

Slide 5

Slide 5 text

5/18 Visual diff: after fixing

Slide 6

Slide 6 text

6/18 Previous approach ● Implemented in 2019 ● Tries to map endnotes to footnotes on the last page ● Grows from the bottom up, now from to the top to bottom after content ● Native Writer behavior: separate endnote page ● Collapses with large amount of endnotes ● Especially if those are of multiple pages

Slide 7

Slide 7 text

7/18 The new approach ● Introduce a special endnotes section ● No backing section node, only exists at a layout level ● At the end of the document ● No actual content in the section’s body, just hosts a foot/endnote container ● Can flow across pages, can handle many notes

Slide 8

Slide 8 text

8/18 Switch to a section-based layout ● Works for simple cases, but the compat flag (to render Word-style endnotes, not Writer-style ones) is just used by DOC files, only in case they have 1 or 2 endnotes ● Reverts the changes of the old approach ● Creates the layout-level section for endnotes on demand ● Handles moving the endnote to a previous or next page

Slide 9

Slide 9 text

9/18 Enable for all DOC files ● See what ‘make check’ finds ● What crashtesting has to say ● Found problem: trouble if there is a section at the document end already ● We tried to insert the section for the endnotes inside that last section from model, fixed

Slide 10

Slide 10 text

10/18 Enable for DOCX files ● Didn’t find more issues instantly ● Still had to fix: ● Endnote container’s top margin ● Endnote separator position ● Endnote separator length ● DOCX has a per-doc flag to collect endnotes at section end ● Import / export of this ● Endnote continuation separator length ● Writer UI: conditionally hide widgets which won’t work for DOCX

Slide 11

Slide 11 text

11/18 How is this implemented?

Slide 12

Slide 12 text

12/18 Document model ● sw::DocumentSettingManager stores compat flags ● DocumentSettingId::CONTINUOUS_ENDNOTES is the relevant flag here ● If true, then layout endnotes like Word does ● Otherwise compatible with existing ODF documents

Slide 13

Slide 13 text

13/18 UNO API ● The Writer’s document’s factory can create an instance of the com.sun.star.document.Settings service ● Implements beans::XPropertySet ● Can set the ContinuousEndnotes property there to true to have the Word behavior

Slide 14

Slide 14 text

14/18 Layout ● The most interesting part ● SwFootnoteBossFrame::AppendFootnote() is where the foot/endnote frames are created ● A note can go to the end of the current section, to a note page, and now can go to the special new endnote section at the end of the document ● The endnote section is created on demand ● Moving to the next page works out of the box ● Moving to the previous page needs explicit handling in SwFlowFrame::MoveBwd() ● Similar to moving sections to the previous page is handled in SwFrame::GetPrevSctLeaf()

Slide 15

Slide 15 text

15/18 Filters ● Remove the restriction to only have continuous endnotes for 1 or 2 endnotes from DOC, have it for all DOC ● Also enable it for DOCX ● DOCX describes the position of the endnotes in a document ● At document end vs at section end ● Existing ODF documents stay unchanged

Slide 16

Slide 16 text

16/18 Tests ● Search for stress-test documents in bugzilla ● The old approach was reverted for DOCX in the past ● It was also restricted to 1-2 endnotes for DOC in the past ● Various provided documents to show the old layout was poor ● Largest document is 72 endotes, over several pages at the document end ● Automated testing: ● CppunitTest_sw_core_layout for the actual layout ● CppunitTest_sw_writerfilter_dmapper for the DOCX import ● CppunitTest_sw_filter_ww8 for the DOCX export ● bin/diff-pdf-page.py for the visual diff, based on Laszlo’s idea

Slide 17

Slide 17 text

17/18 UI: hide not needed widgets for DOCX

Slide 18

Slide 18 text

18/18 Summary ● Section-based endnotes are a new way to layout endnotes at the end of the document, as opposed to layout on a separate endnote page ● Compatible with Word ● Scales properly: ● Many endnotes ● Many footnotes ● Available for everyone using LibreOffice Technology: LibreOffice desktop, Collabora Online, etc.