Bug 143899 - FILEOPEN DOCX Shapes overlap vertical margin in CompatibilityMode15
Summary: FILEOPEN DOCX Shapes overlap vertical margin in CompatibilityMode15
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: target:25.2.0
Keywords: filter:docx
: 161559 (view as bug list)
Depends on:
Blocks: DOCX-Objects DOCX-compatibilityMode-15
  Show dependency treegraph
 
Reported: 2021-08-16 11:35 UTC by NISZ LibreOffice Team
Modified: 2024-09-09 10:52 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments
Positioning of the top left image side by side in Word and Writer (1.39 MB, image/png)
2021-08-16 11:35 UTC, NISZ LibreOffice Team
Details
Positioning of the bottom left image side by side in Word and Writer (1.30 MB, image/png)
2021-08-16 11:35 UTC, NISZ LibreOffice Team
Details
The original bugdoc from bug 37315 saved in Word 2010 C14 mode for convenience. Same as the original. (904.44 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2021-08-16 11:37 UTC, NISZ LibreOffice Team
Details
The C14 and C15 example files in Word 2019 side by side (1.05 MB, image/png)
2021-08-16 11:37 UTC, NISZ LibreOffice Team
Details
para from_top-positive_compat15.docx: image is 10 inches below the top of paragraph, and 10 inches to the right (20.41 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2024-08-20 19:52 UTC, Justin L
Details
para from_top-positive_compat15.pdf: how it looks in MSO 2019 (36.82 KB, application/pdf)
2024-08-20 19:53 UTC, Justin L
Details
tdf99004_c15.docx: Word 2013 version of sw/qa/extras/uiwriter/uiwriter4.cxx (16.38 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2024-08-28 16:34 UTC, Justin L
Details
143899_tableAndImage_c15.docx: floating tables are an exception to the rule (55.26 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2024-08-28 17:21 UTC, Justin L
Details
143899_tableAndImage_c15-mso2019.pdf: how it looks in Word 2019 (62.77 KB, application/pdf)
2024-08-28 17:22 UTC, Justin L
Details
143899_framePr.docx: framePr also are not limited to the body text area (14.12 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2024-08-29 21:58 UTC, Justin L
Details

Note You need to log in before you can comment on or make changes to this bug.
Description NISZ LibreOffice Team 2021-08-16 11:35:15 UTC
Created attachment 174316 [details]
Positioning of the top left image side by side in Word and Writer

This is split off from bug 37315
The attachment 147135 [details] shows that layout in Word has changed with CompatibilityMode15.
In particular the vertical position of the left side images changed: 
* the top one specifies a negative position, but is aligned to the top of the page, while in Writer it overlaps the top margin of the page, just like in CompatibilityMode <= 14.
* the bottom left one is positioned 12.77 cm below paragraph in Word but it does not overlap the bottom margin: however – were this value taken literally by Word – it should since it is anchored to the second paragraph and that is positioned below the top right image. As you can see, there is no 12 cm vertical space between the second paragraph and the top of the bottom left image.
In Word with CompatibilityMode<=14 and in Writer the 12.77 cm value is taken literally and the image overlaps the bottom margin a bit.

Steps to reproduce:
1.	Open attachment 147135 [details] in Word and Writer, observe the positioning of the shapes on the left

Actual results:
Top left image overlaps the top margin, bottom left margin overlaps the bottom margin.

Expected results:
They should not overlap the top/bottom margin.

LibreOffice details:
Version: 7.3.0.0.alpha0+ (x64) / LibreOffice Community
Build ID: d1f1f546b212ecd651146addeb328806bb270d5f
CPU threads: 4; OS: Windows 10.0 Build 18363; UI render: Skia/Raster; VCL: win
Locale: hu-HU (hu_HU); UI: en-US
Calc: CL
Comment 1 NISZ LibreOffice Team 2021-08-16 11:35:49 UTC
Created attachment 174317 [details]
Positioning of the bottom left image side by side in Word and Writer
Comment 2 NISZ LibreOffice Team 2021-08-16 11:37:08 UTC
Created attachment 174318 [details]
The original bugdoc from bug 37315 saved in Word 2010 C14 mode for convenience. Same as the original.
Comment 3 NISZ LibreOffice Team 2021-08-16 11:37:39 UTC
Created attachment 174319 [details]
The C14 and C15 example files in Word 2019 side by side
Comment 4 Ezinne 2021-08-22 22:03:20 UTC
Reproducible in:

Version: 7.3.0.0.alpha0+ / LibreOffice Community
Build ID: 7c1bad415ae48635dc67041c413bb7b76a530c22
CPU threads: 8; OS: Linux 5.8; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
TinderBox: Linux-rpm_deb-x86_64@86-TDF, Branch:master, Time: 2021-07-05_06:55:03
Calc: threaded
Comment 5 QA Administrators 2023-08-23 03:20:08 UTC Comment hidden (obsolete)
Comment 6 Tex2002ans 2023-12-06 20:43:37 UTC
I can still reproduce in:

Version: 7.6.3.2 (X86_64) / LibreOffice Community
Build ID: 29d686fea9f6705b262d369fede658f824154cc0
CPU threads: 8; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL threaded
Comment 7 Justin L 2024-08-19 14:26:58 UTC
This bug is very confusing because the layout is bad-looking even in MS Word 2013.

repro 25.2+ with comment 0's 37315 crop-problem MSO.docx
    - the skating picture is intruding into the top page margin
    - the Cathedral Square picture is intruding into the bottom page margin.

The horizontal position of Cathedral Square was fixed in 24.8 by
commit 838eb1a370b3bc533e81e819ae697222d3da5022
Author: Miklos Vajna on Thu Jun 13 08:04:30 2024 +0200
    tdf#161199 sw DoNotCaptureDrawObjsOnPage: capture wrap=none draw objects

INTERESTING - note vmklos' remark in the commit message, which is exactly what this bug report is about...:
    "Note that Word goes a bit further here and even keeps the shape inside
    the body text area, but that doesn't seem to be a regression, so leave
    that unchanged for now."
Comment 8 Justin L 2024-08-19 14:38:20 UTC
*** Bug 161559 has been marked as a duplicate of this bug. ***
Comment 9 Justin L 2024-08-19 14:43:32 UTC
Note that only the vertical margin cannot be overlapped. The horizontal one can. This sounds identical to vertical layoutInCell, where both "page" and "margin" are implemented as "margin". (see https://gerrit.libreoffice.org/c/core/+/171433)
Comment 10 Justin L 2024-08-20 19:52:04 UTC
Created attachment 195917 [details]
para from_top-positive_compat15.docx: image is 10 inches below the top of paragraph, and 10 inches to the right

In this simple example file, if the fly distance was taken literally it would be well off the page. But in MSO 2013 it hugs the right edge of the paper, above the footer area. (In MSO 2010, it hugs the bottom, right corner of the paper - just like LO.)

Not surprisingly, this has nothing to do with layoutInCell.

Vertically, the image is forced into the page-margin area (PAGE_PRINT_AREA).
Horizontally, the image is forced into the page area (PAGE_FRAME).

This only applies to the non-page orientations (i.e. line or paragraph).

This applies to all the orientations: top/center/bottom/from top. (If it doesn't fit before the bottom margin, it will move the paragraph to the next page - somewhat arbitrarily as this document shows. I would have expected it to move as a second paragraph too, but it didn't move to page 2 until it was the third paragraph. It depends on the image size. As long as there is enough room to be "below" the first line, it stays on the page.)

It does not apply to wrap-through flies.
Comment 11 Justin L 2024-08-20 19:53:04 UTC
Created attachment 195918 [details]
para from_top-positive_compat15.pdf: how it looks in MSO 2019
Comment 12 Justin L 2024-08-28 16:34:34 UTC
Created attachment 196071 [details]
tdf99004_c15.docx: Word 2013 version of sw/qa/extras/uiwriter/uiwriter4.cxx

testTdf99004 has a very nice unit test with tdf99004.docx which is a compatibilityMode14 file, and tests that the two shapes should not overlap.

However, simply changing the compatibility mode number to 15 version does cause the shapes to overlap, since the top shape gets pushed below the header area (as would be expected from this bug report).

It is useful to note that there is no header.xml in this document, and yet the header restriction is enforced.
Comment 13 Justin L 2024-08-28 17:21:48 UTC
Created attachment 196072 [details]
143899_tableAndImage_c15.docx: floating tables are an exception to the rule

Apparently tables are an exception to the rule.

sw/qa/core/layout/flycnt.cxx's floattable-tab-join.docx is already a good test which ensures the table doesn't spill over to the next page (which it does if the negative offset isn't applied).
Comment 14 Justin L 2024-08-28 17:22:21 UTC
Created attachment 196073 [details]
143899_tableAndImage_c15-mso2019.pdf: how it looks in Word 2019
Comment 15 Justin L 2024-08-29 21:58:19 UTC
Created attachment 196105 [details]
143899_framePr.docx: framePr also are not limited to the body text area
Comment 16 Justin L 2024-09-03 12:15:58 UTC
A patch that fixes it (and results in a layout loop somewhere during unit tests) is https://gerrit.libreoffice.org/c/core/+/172536
Comment 17 Commit Notification 2024-09-04 12:32:57 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/309aded3145f8ecec9e9af61a3c64804258f8336

NFC prep for tdf#143899: move TextBoxIsFramePr into SwTextBoxHelper

It will be available in 25.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 18 Commit Notification 2024-09-09 10:48:52 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/1de6bea27ed36167ec138818607da7b49e92ec4a

tdf#143899 compat15 layout: restrict body fly to PAGE_PRINT_AREA

It will be available in 25.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.