Bug 112118 - When using page-border, size of margins increases every time file is saved as DOC(X) (see comment 3)
Summary: When using page-border, size of margins increases every time file is saved as...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:6.1.0
Keywords: filter:doc, filter:docx
: 116247 (view as bug list)
Depends on:
Blocks: Borders Page-Margins DOCX-Page DOC-Page
  Show dependency treegraph
 
Reported: 2017-08-30 22:32 UTC by ROAR
Modified: 2019-09-27 05:19 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
docx file and screenshots (6.89 KB, application/zip)
2017-08-31 12:11 UTC, ROAR
Details
Sample ODT (8.65 KB, application/vnd.oasis.opendocument.text)
2018-03-12 16:18 UTC, Aron Budea
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ROAR 2017-08-30 22:32:21 UTC
If my document has a page border and I create a table then save the document as a docx file, when I open the docx file, I can see slight increase in table widths. If I save that file again (as docx) table width increases again and again without ever doing anything new to that file myself.
This doesn't happen if I save to odt file or remove page-border.

steps to reproduce:
 1- Create a new document and define a page border.
 2- Create a table.
 3- Save the document as a docx file.  
 4- Open the docx file and see the difference.
 5- You can redo the 4th step over and over and you can see that it increases every time.

I can only confirm this bug on my Linux Mint 64-bit machine. I don't have Windows and do not know if this is present on other platforms.
Comment 1 Dieter 2017-08-31 07:19:34 UTC
I can't confirm this under Win10. Can you add an attachment?
Comment 2 ROAR 2017-08-31 12:11:57 UTC
Created attachment 135901 [details]
docx file and screenshots

Here's the docx file. If I open this and save it, after opening it up again there's an increase. If I keep doing it the width increases continuously. 3 screen-shots of this problem are provided.
Comment 3 Dieter 2017-08-31 13:26:07 UTC
I could reproduce it only with your document. What I could find out is, that not the size of the tabls changed, but the size of the margins
in your document every margin has the size of 2,40 cm
save as docx and reopen in LO => size of 2,49 cm
save as docx and reopen in LO => size of 2,59 cm

I delated the table, but the size of the margin still changed.

So my suggestion is to change the summry of this bug to: "Size of margin changes when saving as docx". What do you think? I haven't checked, if this bug is already known.
Comment 4 ROAR 2017-08-31 15:30:48 UTC
You are right the problem is margins! Could you attach a docx file created with your machine (1 with LibreOffice and 1 with ms-word if you have it) to see if it's just my docx file or it's a problem with my installation or something.
The culprit might be something I've done to my default style. If it is just my docx file then I probably should delete this bug because it can't be reproduced in normal situations. But to be sure I have to check other docx files created with other machines.
Comment 5 Dieter 2017-08-31 19:57:42 UTC
I found some bugs, that seem to be similar: 89628 94009 95374.
Comment 6 Dieter 2017-08-31 19:59:57 UTC
(In reply to Dieter Praas from comment #5)
> I found some bugs, that seem to be similar: 89628 94009 95374.

I meant 89621 instead of 89628
Comment 7 ROAR 2017-08-31 20:39:42 UTC
(In reply to Dieter Praas from comment #6)
> (In reply to Dieter Praas from comment #5)
> > I found some bugs, that seem to be similar: 89628 94009 95374.
> 
> I meant 89621 instead of 89628

94009 is very similar but in a different situation. Mine only happens when I use page-border. 95374 could be the same thing but I couldn't reproduce it. And  89621 isn't very much related to this. And again none of them mention page-border. 

So I changed my summery to include page-border again and removed 89621 from list.
Comment 8 Dieter 2017-08-31 21:02:03 UTC
I forgot the page border in my own test-document. With page borders I can confirm this bug.
Comment 9 ROAR 2017-08-31 21:36:35 UTC
(In reply to Dieter Praas from comment #8)
> I forgot the page border in my own test-document. With page borders I can
> confirm this bug.

If you can confirm it on windows or any other machine you can change Hardware values.
Comment 10 Dieter 2018-03-07 10:31:56 UTC
*** Bug 116247 has been marked as a duplicate of this bug. ***
Comment 11 Aron Budea 2018-03-08 03:53:40 UTC
Simpler repro steps as described in duplicate bug 116247:

Add borders to an empty page, and save it in DOC or DOCX format, then reopen the document.

=> Margin is changed (eg. default 2 cm is changed to 2.05 cm).

Attaching a sample with varied margins:  1.5 / 2.5 / 1 / 3 cm (left / right / top / bottom).

When saving in DOC format the margins become: 1.51 / 2.51 / 1.01 / 3.01 cm.
When saving in DOCX format the margins become: 1.55 / 2.55 / 1.05 / 3.05 cm.
Comment 12 Aron Budea 2018-03-12 16:18:13 UTC
Created attachment 140583 [details]
Sample ODT

Attaching a sample with somewhat more exotic settings than in bug 116247, with varying margin, padding and border width.
Comment 13 Mike Kaganski 2018-03-14 10:25:24 UTC
https://gerrit.libreoffice.org/51267 is the DOCX part.

Please note that there are fundamental difference in document models between ODF and MS formats, that disallows from fully preserving the border/margin sizes/distances. Partly (!) it's discussed at https://wiki.openoffice.org/wiki/Writer/MSInteroperability/PageBorder.

MS Word only allows one to have page borders to have offset no more than 31 pt (~1.1 cm) from either page edge, or page text, while ODF allows for any offset value (so, MS Word cannot display correctly borders placed outside of the mentioned limits); note that this is Word limitation, not of OOXML. OTOH, ODT doesn't allow for placing border outside of the page, or inside of text area (which Word allows).

MS formats only can have integer pt size as border offset, and 1/8 pt as border width (0.25 pt minimum). So, given that ODF allows for much more precise control over the sizes, not every size valid for ODF could be saved intact to MS formats, and so on round-trip, sizes may arrive changed a little.

The patch takes care to preserve size from page edge to text (the most important size that affects document layout). This should be done correctly now.

Also, it positions borders properly on import, taking into account the border width, in all cases supported by ODF (when border is inside ODF page margin). When borders go outside of range valid for ODF, the margin is set to keep text area intact, and the border is placed as close to intended position as possible.

Export code now also handles border width (which it didn't); also it improves the logic in cases when borders in document are outside of ranges possible for Word. Note that we write correct sizes to OOXML, so that when reopened by LO, the borders will be in correct places; but as Word cannot handle sizes more than 31 pt, it will show borders shifted. To test the change, you may create a sample text document in Writer with all margins 4 cm, and borders 6 pt wide padded by 2 cm; and another one with all margins 2 cm, and border padding 4 cm; and compare the results of export in Word.
Comment 14 Commit Notification 2018-03-14 14:33:56 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=fb959e581c900b392efd0bb329b7cf30c8ed56a5

tdf#112118: DOCX: properly import/export border distance

It will be available in 6.1.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 15 Mike Kaganski 2018-03-15 18:55:27 UTC
https://gerrit.libreoffice.org/51366 is the DOC part.
Comment 16 Commit Notification 2018-03-16 03:56:34 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=8805e10f5887df66edfd0a2fa4b70e87f0c74700

tdf#112118: DOC: properly import/export border distance

It will be available in 6.1.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 17 Mike Kaganski 2018-03-16 13:19:44 UTC Comment hidden (obsolete)
Comment 18 Mike Kaganski 2018-03-17 21:19:29 UTC
https://gerrit.libreoffice.org/51474

The description in comment 17 is incorrect. The pushed commits are fine; just since they ensure that export of margins to DOC(X) is correct, it became apparent that we had a longstanding (at least since 2000: it's already there in commit 7b0b5cdf) import bug with margin width calculations, which only shows up when left and right border distances/widths are not the same. The left and right were simply switched in the code, which is fixed now in this patch. Thanks Aron for pointing this out!
Comment 19 Commit Notification 2018-03-18 00:25:48 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=45f1b733e0f736f4db677ba1fd17695ac1009c9f

tdf#112118: use correct border when calculating margin

It will be available in 6.1.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 20 Dieter 2019-09-27 05:19:11 UTC
VERIFIED with

Version: 6.3.2.2 (x64)
Build-ID: 98b30e735bda24bc04ab42594c85f7fd8be07b9c
CPU-Threads: 4; BS: Windows 10.0; UI-Render: GL; VCL: win; 
Gebietsschema: de-DE (de_DE); UI-Sprache: de-DE
Calc: threaded