Bug 133507 - contextual spacing wrong between normal text and section
Summary: contextual spacing wrong between normal text and section
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:24.2.0
Keywords:
Depends on:
Blocks: Paragraph-Spacing
  Show dependency treegraph
 
Reported: 2020-05-29 22:43 UTC by Regina Henschel
Modified: 2023-08-13 14:14 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Example with contextual spacing (16.39 KB, application/vnd.oasis.opendocument.text)
2020-05-29 22:43 UTC, Regina Henschel
Details
section 13extended DOCX_mso2010.pdf (25.25 KB, application/pdf)
2023-06-13 14:43 UTC, Justin L
Details
Lync-Demo-Guide_publish-june-2012-_ENB.docx: triggered my hunt assert (58.54 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2023-06-21 21:20 UTC, Justin L
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Regina Henschel 2020-05-29 22:43:24 UTC
Created attachment 161412 [details]
Example with contextual spacing

Open attached document. It has a paragraph style "contextualspacing" with Spacing Above paragraph =1cm, Spacing Below paragraph =1cm, and option "Don't add space between paragraphs of the same style. All paragraph have got this style applied.
The third the forth paragraphs are inside a section.

The spec has:
"The space between the paragraphs is zero, if all of the following conditions hold:
...
 The paragraphs belong to the same content area.
...
"

So I expect, that there is a 1cm spacing between the forth and fifth paragraph, because the forth paragraph is inside the section and the fifth paragraph is outside the section and thus they do not have the "same content area".

I see the problem already in versions before LO 7, where this feature is written as loext:contextual-spacing. Therefore I guess it is an implementation error. But for LibreOffice 7.0 where it is the 'official' attribute style:contextual-spacing in ODF 1.3, it should be implemented correctly.

Tested with Version: 7.0.0.0.alpha1+ (x64)
Build ID: 0a7341c26741f16835c9062c309e7d3a7fca8209
CPU threads: 8; OS: Windows 10.0 Build 18362; UI render: default; VCL: win
Locale: de-DE (en_US); UI: en-US
Calc: CL

and Version: 6.4.5.0.0+ (x64)
Build ID: 70a2071ce91b71326659e645dd97996262ea309a
CPU threads: 8; OS: Windows 10.0 Build 18362; UI render: default; VCL: win; 
Locale: de-DE (en_US); UI-Language: en-US
Calc: CL
Comment 1 Dieter 2020-06-03 07:15:32 UTC
I confirm it with

Version: 7.0.0.0.beta1 (x64)
Build ID: 94f789cbb33335b4a511c319542c7bdc31ff3b3c
CPU threads: 4; OS: Windows 10.0 Build 18363; UI render: Skia/Raster; VCL: win
Locale: de-DE (de_DE); UI: en-GB
Calc: CL
Comment 2 QA Administrators 2022-06-04 03:32:48 UTC Comment hidden (obsolete)
Comment 3 Regina Henschel 2022-06-04 12:39:22 UTC
The error still exists in Version: 7.4.0.0.alpha0+ (x64) / LibreOffice Community
Build ID: 172e208e6b0674f42c301c5ee5e280e9138ba1b4
CPU threads: 8; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL
Comment 4 Justin L 2023-06-13 14:43:29 UTC
Created attachment 187888 [details]
section 13extended DOCX_mso2010.pdf

MSO is also somewhat wishy-washy when it comes to "end of the content area". For headers and footers, the spacing is added, but not for start/end of document. For Table cells, the spacing is not added.

In this particular case, the DOCX version looks like what Regina is expecting.
Comment 5 Justin L 2023-06-13 15:35:19 UTC
contextual spacing was added to LO in LO 3.6. (3.5.7 showed a 1cm gap in between all of these paragraphs.)

(In reply to Regina Henschel from comment #0)
> So I expect, that there is a 1cm spacing between the forth and fifth
> paragraph, because the forth paragraph is inside the section and the fifth
> paragraph is outside the section
Yes, I would have expected spacing there also. As seen in the example, it DOES work between "real" sections, but not when transitioning for an explicit section to the main text body.

Unfortunately, for DOCX, MSO 2010 actually applies both the bottom AND top spacing (so 2cm) instead of just a combined 1cm. (Also, in DOCX, everything is a "real" section, except perhaps for the first section).
Comment 6 Justin L 2023-06-14 14:35:41 UTC
A simple patch to correct the problem is at https://gerrit.libreoffice.org/c/core/+/153033.

The question is whether to just fix the implementation problem, or to create a compat flag to handle any possible documents created since 3.6.


The full spec is:
20.255 style:contextual-spacing
The fo:margin-bottom attribute of a paragraph and the fo:margin-top attribute of the next paragraph are ignored, so that the space between the paragraphs is zero, if all of the following conditions hold:
• The style:contextual-spacing attribute of both paragraphs has the value true.
• The paragraphs belong to the same content area.
• The text:style-name attribute of the paragraphs refer to the same common
paragraph style. In case a text:style-name attribute refers to an automatic style, the value of the style:parent-style-name attribute of the automatic style is taken for the style comparison. If a paragraph has a conditional style, the value of its text:cond-style-name attribute is taken for the style comparison.

Our code really does nothing intentional about attempting to define "different content areas". It looks like it is simply based on one TEXTFRAME following another. (see bug 75221, which also references the 3.6 commits)

Based on an MSO example, it suggests that they also don't have extremely intentional areas where it does or does not apply either.
- at the beginning of the document, the upper spacing is applied (LO OK)
- however the lower spacing is not applied at document end (LO OK).

- the upper spacing is not applied after a table (LO applies it),
- but lower spacing is applied before a table (LO OK).

- upper spacing is applied at the beginning of a table cell (LO OK)
- but lower spacing is not applied at the end of a table cell. (bug 155813)

- at section breaks, both upper and lower apply (LO merges like everywhere else)

- upper spacing is applied to header top (LO OK),
- and lower spacing is applied to header bottom. (bug 128195)
Comment 7 Commit Notification 2023-06-15 20:30:39 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/12f256cd1ae3e625c7b7f48987b7e843046924fa

tdf#133507 sw: hunt for documents with ULSpacing at section end

It will be available in 24.2.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 8 Commit Notification 2023-06-21 18:00:46 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/22c4df0282dce9d56207a440c523c2f3a16bc9f2

tdf#133507 sw layout: fix missing contextual spacing at section end

It will be available in 24.2.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 9 Justin L 2023-06-21 21:20:33 UTC
Created attachment 188047 [details]
Lync-Demo-Guide_publish-june-2012-_ENB.docx: triggered my hunt assert

Some kind of layout back and forth must also be triggering this layout condition. Deleting pretty much any paragraph in this document will cause it not to trigger any more. That is a bit scary.
Comment 10 Justin L 2023-06-24 20:32:04 UTC
(In reply to Justin L from comment #6)
> - the upper spacing is not applied from the paragraph after a table
Not true. Only not applied for the "Normal" paragraph style.

> - but lower spacing is applied before a table
True - unless the table starts with the same paragraph style!

> - upper spacing is applied at the beginning of a table cell
True for the first cell only if the paragraph before the table is different.
True for the first column only if it is not the "Normal" para style.
True only if the previous column has a different paragraph style.

In other words, being in a table really has no impact - always compare to the previous paragraph/column. In MSO at the end of a row, you can see some kind of control. That control always has the default paragraph style, so in your mind consider that to be a paragraph to compare against.

> - but lower spacing is not applied at the end of a table cell. (bug 155813)
Very conditional as already described. See examples in that bug report.
It is applied if the next column has a different paragraph style.
It is applied on the last column if it is not the "Normal" para style.