Bug 120761 - FILEOPEN Z-order of objects in attached DOC is wrong
Summary: FILEOPEN Z-order of objects in attached DOC is wrong
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:7.2.0
Keywords: filter:doc
: 48715 (view as bug list)
Depends on:
Blocks: DOC-Header-Footer
  Show dependency treegraph
 
Reported: 2018-10-21 23:53 UTC by Aron Budea
Modified: 2021-09-15 14:26 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Sample DOC (52.50 KB, application/msword)
2018-10-21 23:53 UTC, Aron Budea
Details
Comparison screenshot (54.09 KB, image/png)
2018-10-21 23:56 UTC, Aron Budea
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aron Budea 2018-10-21 23:53:54 UTC
Created attachment 145885 [details]
Sample DOC

The attached DOC (created in Word) contains two images and a text box in the header, and was saved from bug 120760's bugdoc in Word.
One image is the page background (light blue), and should be behind the others (a red box and text box with green background).

=> It's shown in front instead (results are slightly different compared to bug 120760).
It's a Z-order bug, because if the image Picture 2 (the background) is deleted in the Navigator, the others are shown.

Observed using LO 6.2.0.0.alpha0+ (2018-10-09, 425af6845ebe066c950b0b63f50563e067485f3e) & 3.3.0 / Windows 7.
Comment 1 Aron Budea 2018-10-21 23:56:06 UTC
Created attachment 145886 [details]
Comparison screenshot
Comment 2 Xavier Van Wijmeersch 2018-10-22 09:06:38 UTC
confirm with

Version: 6.2.0.0.alpha1+
Build ID: 8274c4c62df5b937b3f0bec9e1eeca85f3b219d4
CPU threads: 8; OS: Linux 4.14; UI render: default; VCL: kde4; 
TinderBox: Linux-rpm_deb-x86_64@70-TDF, Branch:master, Time: 2018-10-22_00:35:58
Locale: nl-BE (en_US.UTF-8); Calc: threaded

Version: 6.2.0.0.alpha0+
Build ID: aa3b2f90a62678c8e594830277a32e3ad742e826
CPU threads: 8; OS: Linux 4.14; UI render: default; VCL: kde4; 
Locale: nl-BE (en_US.UTF-8); Calc: threaded

But not with

Version: 6.1.4.0.0+
Build ID: ac39aba9b2d08b061b0eef651f5ebc7a84391171
CPU threads: 8; OS: Linux 4.14; UI render: default; VCL: kde4; 
Locale: nl-BE (en_US.UTF-8); Calc: group threaded
Comment 3 Aron Budea 2018-10-23 16:39:50 UTC
Thanks for checking, Xavier! I'd be surprised if this was actually fine in 6.1, but not in master, so that result seems fishy.
Comment 4 Aron Budea 2018-10-23 18:20:51 UTC
Also checked with 6.1.4.0.0+ daily build (2018-10-23, 5de85be43198804573787d4186b156b5931c4a9f), and I'm still only seeing the background, so the bug is still there. Let's set the bug to NEW.
Comment 5 QA Administrators 2019-10-24 02:41:09 UTC Comment hidden (obsolete, spam)
Comment 6 Justin L 2020-04-23 17:07:40 UTC
// #i14045# MM If we are in a header or footer then make the object transparent
// Not exactly like word but close enough for now
const bool bMoveToBackgrd = pRecord->bDrawHell ||
                            ( ( m_bIsHeader || m_bIsFooter ) && pF->nwr == 3 );
if ( bMoveToBackgrd )
    aFlySet.Put(SvxOpaqueItem(RES_OPAQUE,false));
Comment 7 Justin L 2021-04-08 15:21:09 UTC
Unfortunately there is no documentation in the code that indicates what determines z-order in DOC files, nor what determines zorder in LO. So we are left guessing as to whether the implementation is generally correct.

Inserting these three items in reverse order seems to fix the problem (and no unit tests fail either), but based on a code read, I would expect that the code is correct too. Confusing!

DOCX supposedly has something like "relativeHeight=“251657728"”, but that doesn't exist when I round-trip this example as DOCX (but it does have z-index, which is what is used in this case.)

My guess (which may be entirely wrong) is that DOC has zorder similar to DOCX.
But I see no evidence that this is actually being used. Our implementation seems to be simply based on the order in which the shape is read from the document, with the first read as the lowest zorder.

LO seems to use 0-n, where 0 is the lowest zorder.

And that seems like exactly what is happening for attachment 145885 [details]. But I notice something very strange. I expect that the IDs from DOCX will match DOC (because that is true for the example documents that I made to try to test my ideas), but in this case they are the opposite!
DOCX -   item     -  DOC
2049 - Text Box 2 - 2051
2050 - Picture 1  - 2050
2051 - Picture 2  - 2049
Comment 8 Justin L 2021-04-09 09:14:55 UTC
The key is that the blue shape was marked as "in background" while the other shapes were "before text". Amazingly, there was nothing in the existing shape ordering that put background shapes behind foreground shapes.

proposed fix at https://gerrit.libreoffice.org/c/core/+/113837
Comment 9 Justin L 2021-04-09 13:27:38 UTC
Oops - had the wrong bug numbering in the patch summary.

7.2 patch applied with https://cgit.freedesktop.org/libreoffice/core/commit/?id=32013f0dccde8407aa907112399dc2a9efb7f906
Comment 10 Commit Notification 2021-04-10 16:04:51 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/a6e271621843f454d92bc2c73a4425ad4afd1211

tdf#120761 doc import: fix z-order background logic

It will be available in 7.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 12 Commit Notification 2021-05-10 08:55:05 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/eef7fab8962b74da7e6bb1d4fee8a54f95e6594b

tdf#120761: sw_ww8import: fix typo in unittest

It will be available in 7.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 13 Timur 2021-09-15 14:26:38 UTC
*** Bug 48715 has been marked as a duplicate of this bug. ***