Bug 153964 - FILEOPEN DOCX COMPAT15: paragraph top margin should only apply once - affecting page/col breaks
Summary: FILEOPEN DOCX COMPAT15: paragraph top margin should only apply once - affecti...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Justin L
URL:
Whiteboard:
Keywords: filter:doc, filter:docx
: 134257 (view as bug list)
Depends on:
Blocks: DOCX-compatibilityMode-15
  Show dependency treegraph
 
Reported: 2023-03-04 17:50 UTC by Justin L
Modified: 2024-01-31 21:26 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
columnMargin_combined.pdf: output from Word 2019 and LO master (102.73 KB, application/pdf)
2023-03-04 17:50 UTC, Justin L
Details
columnMargin15.docx: from Word 2019 looks very different when opened by Word 2010. (21.12 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2023-03-04 17:52 UTC, Justin L
Details
TopMarginNotAppliedTest15.docx: a nasty unit test, trying to cover all 4 cases (14.01 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2023-03-07 15:26 UTC, Justin L
Details
sectionStart.odt: demonstrating a fundamental LO difference for start of section. (24.86 KB, application/vnd.oasis.opendocument.text)
2023-03-07 17:42 UTC, Justin L
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Justin L 2023-03-04 17:50:55 UTC
Created attachment 185748 [details]
columnMargin_combined.pdf: output from Word 2019 and LO master

The heart of the problem appears to be this: a <w:br> can occur either between some character runs, or at the very beginning. In LO, we split this into a "new paragraph" and thus the top margin applies to both parts.

There are several problems all related to this one concept. And that is because even in MS Word it acts rather strangely. For example, while working in compatibility mode, the margin of the new column might change when I hit the save button (using Word 2019).

In Compat15 mode, this is never appropriate - the part after the break must have a zero top margin.

In Compat14 mode the top margin should apply only if the break was the first (visible) run in the paragraph (complicated by the fact that anchored shapes before the break are not considered visible character runs for example).

In LO we have a few things to fix then:
-in compat14 mode with break as first run: we seem to be doubling up the top margin after the page break. Regression in LO 6.0 by me with the unlikely sounding commit afc96d263959d10e457b54a574f0829d20e99df4
    tdf#112352 ooxmlimport: ALWAYS treat 1st nextpage w/cols as cont
[There is also the problem where the following section OUGHT to intrude into this section's space, but I submit that we should not try to do that any more, since anything less than compat15 is effectively obsolete, and looks like an MS bug which is not worth emulating.)

-in all compat modes, when the break is not the first run, then do not apply the top margin to the portion after the break.

-in compat15 mode, when the break is the first run, then do not apply the top margin at all, neither before nor after the break.

-and a bonus related problem: the (blue) paragraph background colour isn't applying to both split paragraphs (neither the empty first paragraph, nor the second split paragraph. Not bibisectable, but in 4.3 the split column break started working.)

It is probably worth noting here the significant distinction between a section page break and a regular page break. By definition, the section page break is a paragraph property - and thus the following paragraph always applies it's margin spacing. The same applies to a section column break. On the other hand, a regular column/page break always splits a paragraph in two, with compat14 causing a dilemma about whether to apply the spacing before or after the break.
Comment 1 Justin L 2023-03-04 17:52:13 UTC
Created attachment 185749 [details]
columnMargin15.docx: from Word 2019 looks very different when opened by Word 2010.
Comment 2 Aron Budea 2023-03-05 04:22:19 UTC
Confirmed in LO 7.6.0.0.alpha0+ (4e6ab75c1a907398d24768d19cf097a4892d374c) / Ubuntu.
Comment 3 Justin L 2023-03-07 15:26:05 UTC
Created attachment 185821 [details]
TopMarginNotAppliedTest15.docx: a nasty unit test, trying to cover all 4 cases
Comment 4 Justin L 2023-03-07 17:42:13 UTC
Created attachment 185823 [details]
sectionStart.odt: demonstrating a fundamental LO difference for start of section.

In the previous examples, we can see that the "top" of the column seems to match the starting column. For DOCX/RTF, that started in LO 4.2 with DOCX import: fix default section break type inside multiple columns. The reason is that columns are being added to a section instead of a page.

As the document attached here shows, LO doesn't consider the section to "start" until AFTER the top margin, whereas MS logically starts the section immediately. (Already true in LO 3.6).
Comment 5 Commit Notification 2023-03-08 12:26:41 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/96a502b3756a1c100b40235f50ef2122d5b543f9

tdf#153964 writerfilter compat15: top margin after break split

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 Commit Notification 2023-03-09 00:34:13 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/80e8763036f36afd482a06fbf0f3ffe1ebbe2b46

tdf#153964 writerfilter: column break split should inherit most properties

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 7 Justin L 2023-03-09 01:10:24 UTC
(In reply to Justin L from comment #0)
> In LO we have a few things to fix then:
> -in compat14 mode with break as first run: we seem to be doubling up the top
> margin after the page break.
Same as comment 4: a major difference between LO and MS Word. I didn't attempt to create a compat flag/layout handling for this. Since this was the main observation, I'll leave the bug report open to deal with this "the section starts after the first paragraph's top margin" problem that affects both compat14 and compat15.

> -in all compat modes, when the break is not the first run, then do not apply
> the top margin to the portion after the break.
Fixed.
 
> -in compat15 mode, when the break is the first run, then do not apply the
> top margin at all, neither before nor after the break.
-fixed

> -and a bonus related problem: the (blue) paragraph background colour isn't
> applying to both split paragraphs (neither the empty first paragraph, nor
> the second split paragraph.
Fixed. We don't create every empty paragraph, so we miss a few coloured areas, but that isn't a big deal.
Comment 8 Justin L 2023-03-09 01:33:57 UTC
Actually, let me close it since the description is all over the place. I'll open a new ticket to deal specifically with the section difference. bug 154082
Comment 9 Gabor Kelemen (allotropia) 2023-03-24 12:19:14 UTC
*** Bug 134257 has been marked as a duplicate of this bug. ***