Bug 164787 - Unexpected top margin for paragraph at the top of non-first pages from DOCX
Summary: Unexpected top margin for paragraph at the top of non-first pages from DOCX
Status: RESOLVED WORKSFORME
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
25.2.0.1 rc
Hardware: All All
: medium normal
Assignee: Not Assigned
URL: https://vmiklos.hu/blog/sw-ignore-mar...
Whiteboard: compatibilityMode15
Keywords:
Depends on: 160952
Blocks: DOCX-Page DOCX-compatibilityMode-15
  Show dependency treegraph
 
Reported: 2025-01-21 15:44 UTC by Piotr Osada
Modified: 2025-05-31 11:31 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Unexpected space above paragraph is added (221.60 KB, image/png)
2025-01-21 15:44 UTC, Piotr Osada
Details
Original 'minimal reproducer' by Miklos Vajna (14.55 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2025-01-21 15:47 UTC, Piotr Osada
Details
'REPRODUCER' saved in LO25.2.0.2 (9.79 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2025-01-21 15:48 UTC, Piotr Osada
Details
'REPRODUCER' saved in Word 2412 (2024) (14.85 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2025-01-21 15:49 UTC, Piotr Osada
Details
LO25.8 displays similar to Word (414.21 KB, image/png)
2025-05-31 11:14 UTC, Piotr Osada
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Piotr Osada 2025-01-21 15:44:10 UTC
Created attachment 198649 [details]
Unexpected space above paragraph is added

+++ This bug was initially created as a clone of Bug #160952 +++

It looks like an introduction of *SwFrame::IsCollapseUpper()* function from the commit 6200d89b905d51776ff4f3c8a84f338655ffaa7f is a workaround for 'purging' top margin, and not for collapsing top margin.

Observations:
+--------------------------------------------------------------+
|          <TOP MARGIN>---<PARAGRAPH> SPACING BEHAVIOR         |
+--------------+-----------------------------------------------+
|              |                    Open by                    |
+--------------+---------------+---------------+---------------+
| FILE         |      Word     |       LO      |       LO      |
|              |               |    7.6.5.2    |    25.2.0.2   |
+--------------+---------------+---------------+---------------+
| scratch.docx | NO additional | THERE IS      | THERE IS      |
|              | space         | additional    |               |
|              |               | space         | additional    |
|              |               |               | space         |
|              | guess:        | guess: LO     |               |
|              | ignored/      | can't ignore  | guess: LO     |
|              | collapsed     | this          | can't ignore  |
|              |               |               | this          |
+--------------+---------------+---------------+---------------+
| scratch.docx | NO additional | NO additional | NO additional |
| saved in     | space         | space         | space         |
| LO25.2.0.2   |               |               |               |
|              | guess:        | guess:        | guess:        |
|              | margin value  | margin value  | margin value  |
|              | is set to 0   | is set to 0   | is set to 0   |
+--------------+---------------+---------------+---------------+
| scratch.docx | NO additional | THERE IS      | THERE IS      |
| saved in     | space         | additional    | additional    |
| Word 2412    |               | space         | space         |
|              |               |               |               |
|              | guess:        | guess: LO     |               |
|              | ignored/      | can't ignore  | guess: LO     |
|              | collapsed     | this          | can't ignore  |
|              |               |               | this          |
+--------------+---------------+---------------+---------------+
|         https://www.tablesgenerator.com/text_tables#         |
+--------------+---------------+---------------+---------------+

attachment 193984 [details]
is a DOCX file claimed to be created in Word 2013
-- 1) only existing paragraph on first page has 0 pt paragraph-spacing before
-- 2) only existing paragraph on second page has 120 pt paragraph-spacing before


Step to reproduce the problem:

1) Open the attached DOCX file (attachment 193984 [details]) in LO25.2.0.2 or earlier.

Expected result: no top margin is displayed, like in Word.

Actual result: 4.23 cm top margin is displayed.
Comment 1 Piotr Osada 2025-01-21 15:47:07 UTC
Created attachment 198650 [details]
Original 'minimal reproducer' by Miklos Vajna
Comment 2 Piotr Osada 2025-01-21 15:48:28 UTC
Created attachment 198651 [details]
'REPRODUCER' saved in LO25.2.0.2
Comment 3 Piotr Osada 2025-01-21 15:49:32 UTC
Created attachment 198652 [details]
'REPRODUCER' saved in Word 2412 (2024)
Comment 4 Piotr Osada 2025-01-21 15:54:09 UTC
Mentioned software in comment 0:

Microsoft® Word dla Microsoft 365 MSO (wersja 2412 kompilacji 16.0.18324.20092) 64-bitowa 

Version: 7.6.5.2 (X86_64) / LibreOffice Community
Build ID: 38d5f62f85355c192ef5f1dd47c5c0c0c6d6598b
CPU threads: 8; OS: Windows 10.0 Build 26100; UI render: Skia/Vulkan; VCL: win
Locale: pl-PL (pl_PL); UI: en-US
Calc: CL threaded

Version: 25.2.0.2 (X86_64) / LibreOffice Community
Build ID: 62af784cc06624122f17ee71c7cf13d906cbaed0
CPU threads: 8; OS: Windows 11 X86_64 (10.0 build 26100); UI render: Skia/Vulkan; VCL: win
Locale: pl-PL (pl_PL); UI: en-US
Calc: CL threaded
Comment 5 Piotr Osada 2025-01-21 15:57:42 UTC
How attachment 193984 [details] DOCX was edited so that it have paragraph-spacing, but it is skipped when displaying?
Comment 6 Piotr Osada 2025-01-21 15:59:12 UTC
BTW 25.2.0.2 RC did not exist at the moment of filing this ticket.
Comment 7 Miklos Vajna 2025-01-22 07:41:09 UTC
Thanks for filing the new bug. Let's reset assignee back to default till I or somebody else has the time to investigate this.
Comment 8 Justin L 2025-04-08 14:20:28 UTC
repro after my fixes landed for bug 165047.

In MS Word 2010, it looks like LO is showing it - with Page 2 way down near the bottom of the page.

So this must be a compatibilityMode 15 thing. Indeed, Scratch.docx's settings.xml has <w:compatSetting w:name="compatibilityMode" w:val="15"/>
Comment 9 Justin L 2025-04-08 14:26:24 UTC
<w:pPr>
  <w:pageBreakBefore/>
</w:pPr>
<w:r>
  <w:lastRenderedPageBreak/>
  <w:t>Page 2</w:t>

I don't know if it is related, but this doesn't use the normal w:br for a page break. Actually, based on my experience I would have expected the top margin to be applied for compat15. So I'm a bit surprised at this result.

Notice that the break is occurring INSIDE of a <w:p> paragraph. So technically this paragraph is on two pages. Thus the top margin is applied to the start of the paragraph (on page 1) and obviously then should not be applied again as the paragraph continues on page 2.
Comment 10 Justin L 2025-05-12 20:31:22 UTC
(In reply to Justin L from comment #9)
> page break. Actually, based on my experience I would have expected the top
> margin to be applied for compat15.
Actually, compat15 NEVER applies the top margin after the page break. Compat14 does IF the page break is the first thing in the paragraph - before any runs.

It is worth noting here that comment 2's 25.2 round-tripped file is compat12 instead of compat15. (fixed in 25.8).

I remember being rather confused when trying to figure out what this bug report is about. I'm still confused, and in general I can't reproduce "additional space" in any of my bibisects. So I'm not sure what I "repro'd" in comment 8.

This bug report should be re-evaluated using LO 25.8 and if there is still a problem, clear steps to reproduce should be provided. (25.8 will be entering beta this week, so I'm not expecting an immediate response...)
Comment 11 Piotr Osada 2025-05-31 11:14:38 UTC
Created attachment 201052 [details]
LO25.8 displays similar to Word

25.8 behaves as expected.

So, I think, that this ticket could be closed.

Version: 25.8.0.0.alpha1+ (X86_64) / LibreOffice Community
Build ID: b559e6371c2abf5c75622f602da87f28ff499a91
CPU threads: 16; OS: Windows 11 X86_64 (build 26100); UI render: Skia/Vulkan; VCL: win
Locale: pl-PL (pl_PL); UI: en-US
Calc: CL threaded

https://dev-builds.libreoffice.org/daily/master/Win-x86_64@tb77-TDF/2025-05-31_03.35.26/