Bug 122103

Summary: DOCX IMAGE: Problems with achor an image "to paragraph" if document is saved as docx (see comment 5)
Product: LibreOffice Reporter: Gabor Kelemen (allotropia) <kelemeng>
Component: WriterAssignee: Not Assigned <libreoffice-bugs>
Status: RESOLVED DUPLICATE    
Severity: normal CC: dgp-mail, libreoffice, nemeth
Priority: medium    
Version: 5.1.0.3 release   
Hardware: All   
OS: All   
See Also: https://bugs.documentfoundation.org/show_bug.cgi?id=121300
Whiteboard:
Crash report or crash signature: Regression By:
Bug Depends on:    
Bug Blocks: 104468    
Attachments: Original file as odt
The same file as problematic docx
The docx file before deleting the empty paragraph
The docx after pressing Delete after the first image

Description Gabor Kelemen (allotropia) 2018-12-14 12:32:05 UTC
Created attachment 147540 [details]
Original file as odt

Attached odt file contains a few paragraphs and two images.
If this is saved as docx and reopened in Writer, deleting the empty paragraph after the first image causes the image to disappear.

1, Save attached file as docx
2, Open the docx in Writer, and delete the empty paragraph between the first image and the "Nyissuk meg a Fájl – Tulajdonságok ablakot!" sentence.

Actual result:
The first image disappears

Expected result:
The image remains.

The problem does not happen with the odt file. 

Version information:

Version: 5.1.0.0.alpha1+
Build ID: 87ac0b1e75a880a68ecb748bd4b34ae5a3d2ae98
Locale: hu-HU (hu_HU)

From bibisect-win32-5.0 but it happens with current master too.
Comment 1 Gabor Kelemen (allotropia) 2018-12-14 12:32:45 UTC
Created attachment 147541 [details]
The same file as problematic docx
Comment 2 Gabor Kelemen (allotropia) 2018-12-14 12:33:30 UTC
Created attachment 147542 [details]
The docx file before deleting the empty paragraph
Comment 3 Gabor Kelemen (allotropia) 2018-12-14 12:34:08 UTC
Created attachment 147543 [details]
The docx after pressing Delete after the first image
Comment 4 Dieter 2018-12-14 13:53:35 UTC
I confirm it with

Version: 6.2.0.0.beta1 (x64)
Build ID: d1b41307be3f8c19fe6f1938cf056e7ff1eb1d18
CPU threads: 4; OS: Windows 10.0; UI render: default; VCL: win; 
Locale: en-US (de_DE); UI-Language: en-GB
Calc: threaded
Comment 5 NISZ LibreOffice Team 2018-12-14 14:41:43 UTC
Some additional details we discovered regarding the issue:
– The anchoring of the image changes from “To Paragraph” to “To Character”.
– Opening the same DOCX file in Microsoft Word shows the horizontal anchoring as “To Column”.
– The word/document.xml describes the anchoring of the image as follows:
<wp:positionH relativeFrom="column"><wp:align>center</wp:align></wp:positionH><wp:positionV relativeFrom="paragraph">

This is why the image disappears when we delete the paragraph because it is anchored to the “end of paragraph” character: deleting the anchor also deletes the image, which makes totally sense – the real issue is that the image was originally anchored to the paragraph, and not the character. If we change back the anchoring of the image from “To Character” to “To Paragraph” it behaves exactly like the original ODS when the paragraph is deleted: the image is retained and the anchor moves up one paragraph.

So the root cause for this whole issue is that Word and Writer handle the anchoring of images differently:
– Microsoft Word has separate anchors for the horizontal and vertical alignment, while LibreOffice Writer has the same one for both.
– In Microsoft Word there are a few options for horizontal alignment (including Page, Margins, Character and Column) but Paragraph isn't among them.
– Anchoring to Column is not supported in LibreOffice Writer.

So, when a document with an image anchored to Paragraph is saved LibreOffice Writer as DOCX and the reopened again, the following happens:
1. The “To Paragraph” anchoring is interpreted as “Horizontal: to Column”, “Vertical: to Paragraph” when saved as DOCX.
2. When the same document is re-opened again, the anchoring is interpreted as “To Character” because “To Column” alignment doesn't exist is LibreOffice Writer.

A possible solution could be that if we see an image that is anchored to column vertically, and anchored to paragraph horizontally we interpret it as anchored to paragraph when importing a DOCX document – but there might be a reason why LibreOffice doesn't work like this right now, so we must beware of possible regressions.
Comment 6 Dieter 2018-12-14 14:58:07 UTC
I changed the bug summary.
Comment 7 Gabor Kelemen (allotropia) 2018-12-15 10:31:54 UTC
Sorry, this is a duplicate of another one by us.

*** This bug has been marked as a duplicate of bug 121300 ***