Bug 119908 - FILEOPEN: DOCX: Layout differences with justified paragraph. MS 2013 introduced a new "smart justify" that can shrink as well as expand.
Summary: FILEOPEN: DOCX: Layout differences with justified paragraph. MS 2013 introduc...
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: Not Assigned
URL:
Whiteboard: compatibilityMode15 target:24.2.0 tar...
Keywords: filter:docx
: 124769 134062 (view as bug list)
Depends on: 130088
Blocks: DOCX-Paragraph DOCX-compatibilityMode-15
  Show dependency treegraph
 
Reported: 2018-09-16 18:23 UTC by Luke
Modified: 2024-11-01 16:09 UTC (History)
9 users (show)

See Also:
Crash report or crash signature:


Attachments
Native 2016 **without** compatibiliy mode (16.31 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2018-09-16 18:23 UTC, Luke
Details
Word vs Writer. (146.91 KB, image/png)
2018-09-16 18:26 UTC, Luke
Details
When compatibily mode is forced, Writer and Word are identical (16.26 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2018-09-16 18:27 UTC, Luke
Details
[MS-DOC]: format correctly imported (28.00 KB, application/msword)
2018-09-16 18:28 UTC, Luke
Details
simple test file (16.36 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2023-10-17 12:23 UTC, László Németh
Details
simple test file in MSO, LO 7.6 and LO 24 (fixing Bug 130088) (448.98 KB, image/jpeg)
2023-10-17 12:24 UTC, László Németh
Details
visual comparison of justification of Writer and MSO (109.53 KB, image/jpeg)
2023-10-17 13:27 UTC, László Németh
Details
screenshot (275.32 KB, image/png)
2023-10-17 18:56 UTC, BogdanB
Details
Screenshot of shrinking lines of the simple test file (947.71 KB, image/jpeg)
2023-11-16 15:29 UTC, László Németh
Details
composite screenshots of before (black) and after (red) (193.78 KB, image/jpeg)
2023-12-20 00:09 UTC, László Németh
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Luke 2018-09-16 18:23:30 UTC
Created attachment 144915 [details]
Native 2016 **without** compatibiliy mode

When opening .doc files or .docx files that were created in pre-2007 versions, Word uses 'compatibility mode'. We appear to be using compatibility mode by default for documents that were created Word 2010+ without this option enabled.

Steps to reproduce:
1. Open August12.docx in Word
2. Open in Writer
3. Note the line spacing layout issues
Comment 1 Luke 2018-09-16 18:26:05 UTC
Created attachment 144916 [details]
Word vs Writer.

Note writer incorrectly imports the documents, taking up 2 pages instead of 1.
Comment 2 Luke 2018-09-16 18:27:04 UTC
Created attachment 144917 [details]
When compatibily mode is forced, Writer and Word are identical
Comment 3 Luke 2018-09-16 18:28:15 UTC
Created attachment 144918 [details]
[MS-DOC]: format correctly imported
Comment 4 Aron Budea 2018-09-16 20:45:56 UTC
Confirmed using LO 6.1.1.2 / Windows 7.
To be precise, in Word the DOCX and DOC look different, and in Writer they look the same (and as the DOC in Word). The difference is that the paragraph that takes 4 lines in one case takes 5 lines in the other.

When comparing the DOCX and DOC in Word, the difference comes from different character layout/spacing. In fact, it only occurs if the text is justified, not with other kinds of alignments.
Comment 5 QA Administrators 2019-09-17 02:47:41 UTC Comment hidden (noise)
Comment 6 Justin L 2020-07-10 08:53:17 UTC
(In reply to Aron Budea from comment #4)
>The difference is that the paragraph
> that takes 4 lines in one case takes 5 lines in the other.
There are two places where this happens (in Word 2016). The other is the line that starts with "Coffee Morning" which only takes one line in 2016, compared to 2 lines in old Word 2003.

Confirmed that changing word/settings.xml compatibilityMode to 12 is all that is necessary to have Word 2016 treat it the same as Writer handles it.

Like Aron says - nothing really special about these paragraphs...
<w:pPr>
  <w:widowControl w:val="0"/>
  <w:jc w:val="both"/>
  <w:rPr>
    <w:rFonts w:eastAsia="MS Mincho"/>
    <w:sz w:val="20"/>
    <w:szCs w:val="20"/>
    <w:lang w:val="en-US"/>
  </w:rPr>
</w:pPr>
Comment 7 Justin L 2020-08-04 09:55:26 UTC
(In reply to Luke from comment #0)
> When opening .doc files or .docx files that were created in pre-2007
> versions, Word uses 'compatibility mode'. We appear to be using
> compatibility mode by default for documents that were created Word 2010+

I don't think this statement is quite true. Word uses compatibility mode for any document that has an older version than it does.
August12.docx has the setting compatibilityMode = 15. (native for Word 2013-2019)

I changed that mode to 14 (native version of Word 2010) and then Word 2016 acted like LO. So this should be a change starting in Word 2013, and not starting in Word 2010 as implied.

This really looks like a Microsoft bug to me.  How can shifting to full justification reduce the amount of space needed for your text? But yeah, I tried typing a sentence in a new Word 2016 document. If it is only one or two characters spilling over to the next line, then full justification must be SHRINKING something and so the entire paragraph now fits on one line instead of two in non-justified mode.
Comment 8 Justin L 2020-08-04 10:46:00 UTC
Ahh, "intelligent spacing" is probably to blame here. See bug 71732, which would result in these kinds of "random" layouts. Perhaps nice on the eyes, but impossible for exact reproducibility.

I'm tempted to mark this as a duplicate of that bug, but apparently Word has been doing this for longer than 2013. Google's instructions to turn on "justify like WordPerfect 6" only work for Word 2007 or Word 2010. So, it looks like in 2013 they have implemented their own algorithm and enabled it by default.

https://answers.microsoft.com/en-us/office/forum/office_2013_release-word/wordperfect-justification-style-no-longer/d341fcca-c1b1-462b-a9a4-0c89a1489184
Comment 9 Justin L 2020-08-04 10:48:26 UTC
(In reply to Justin L from comment #8)
> Ahh, "intelligent spacing" is probably to blame here. 
Oops. That should be bug 38159
Comment 10 Justin L 2022-06-24 19:35:29 UTC
*** Bug 124769 has been marked as a duplicate of this bug. ***
Comment 11 Justin L 2023-03-22 19:37:25 UTC
Lots of good information in bug 38159. Required reading.
Comment 12 Justin L 2023-03-27 14:35:48 UTC
sw/source/core/text/portxt.cxx lcl_AddSpace indicates that Asian text needs to justify very differently from Western. The "Format_" function is likely the place to hook in a smart-justify compatibility flag.

The "CalcSpacing" and "GetSpaceCnt" functions calculate justified alignment.

sw/source/core/text/guess.cxx and a few other places make it sound like fields might be a complicating factor.
Comment 13 Justin L 2023-05-26 19:39:20 UTC
*** Bug 130088 has been marked as a duplicate of this bug. ***
Comment 14 Commit Notification 2023-10-17 08:38:31 UTC
László Németh committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7d08767b890e723cd502b1c61d250924f695eb98

tdf#130088 tdf#119908 smart justify: fix DOCX line count + compat opt.

It will be available in 24.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 15 László Németh 2023-10-17 12:23:23 UTC
Created attachment 190256 [details]
simple test file
Comment 16 László Németh 2023-10-17 12:24:18 UTC
Created attachment 190257 [details]
simple test file in MSO, LO 7.6 and LO 24 (fixing Bug 130088)
Comment 17 László Németh 2023-10-17 13:27:46 UTC
Created attachment 190260 [details]
visual comparison of justification of Writer and MSO

The picture shows, how the shrinking is implemented in MSO by using the available spaces (but the maximal shrinking is independent from the number of the spaces – at least in a line with enough spaces). Black text: MS Word, red text: LibreOffice Writer – the black text contains an extra character spacing after the text “3 Au” to give the same position after the last space).
Comment 18 BogdanB 2023-10-17 18:56:56 UTC
Created attachment 190267 [details]
screenshot

Justin, this is how I see the test documents from description and from comment 15. 
August is not ok yet, but Lorem it is.
Comment 19 Commit Notification 2023-11-16 15:21:33 UTC
László Németh committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/17eaebee279772b6062ae3448012133897fc71bb

tdf#119908 sw smart justify: fix justification by shrinking

It will be available in 24.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 20 László Németh 2023-11-16 15:29:35 UTC
Created attachment 190875 [details]
Screenshot of shrinking lines of the simple test file

Composite picture of Writer screenshots before (red) and after (black) implementing shrinking.
Comment 21 László Németh 2023-11-16 15:36:56 UTC
Áron, Bogdan, Justin, Luke: thanks for your feedback!

Remaining problems (fix cursor positions in the shrunk lines, text portions, hyphenation etc.) will be filed in new issues.
Comment 22 BogdanB 2023-11-17 05:32:34 UTC
"simple test file" from comment 15 is looking now as in Microsoft. Thanks, László Németh.

Verified with
Version: 24.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 17eaebee279772b6062ae3448012133897fc71bb
CPU threads: 16; OS: Linux 6.2; UI render: default; VCL: gtk3
Locale: ro-RO (ro_RO.UTF-8); UI: en-US
Calc: threaded
Comment 23 Commit Notification 2023-11-17 08:34:06 UTC
László Németh committed a patch related to this issue.
It has been pushed to "master":

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

tdf#119908 sw smart justify: add unit test

It will be available in 24.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 24 Gabor Kelemen (allotropia) 2023-11-24 09:19:50 UTC
*** Bug 134062 has been marked as a duplicate of this bug. ***
Comment 25 Commit Notification 2023-11-28 23:16:45 UTC
László Németh committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/20cbe88ce5610fd8ee302e5780a4c0821ddb3db4

tdf#119908 tdf#158419 sw smart justify: fix cursor position

It will be available in 24.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 26 Commit Notification 2023-12-04 20:41:11 UTC
László Németh committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7059a1858ddb044c5f3f0c8e0386d3e1d9dd2b5f

tdf#119908 tdf#158439 sw smart justify: fix freezing with NBSP

It will be available in 24.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 27 Commit Notification 2023-12-19 21:18:57 UTC
László Németh committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/36bfc86e27fa03ee16f87819549ab126c5a68cac

tdf#119908 tdf#158776 sw smart justify: shrink only spaces

It will be available in 24.8.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 28 László Németh 2023-12-20 00:09:43 UTC
Created attachment 191521 [details]
composite screenshots of before (black) and after (red)
Comment 29 Commit Notification 2023-12-28 12:50:23 UTC
László Németh committed a patch related to this issue.
It has been pushed to "libreoffice-24-2":

https://git.libreoffice.org/core/commit/8d247e3ad47e0b828437abb019e1573dbb1c05b1

tdf#119908 tdf#158776 sw smart justify: shrink only spaces

It will be available in 24.2.0.2.

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 30 devseppala 2024-01-27 22:38:46 UTC
I think this feature will be a great improvement for LO. There has been great interest for better text justification in Writer for long time, see bug #38159. However, have I understood correctly that this feature will be enabled only for imported Word documents that use 'smart justify' feature. If so, I would ask you to consider bringing this feature to all Writer documents. Either as paragraph alignment justified sub option or as
Tools->Options->LibreOffice Writer->Compatibility
option.
Comment 31 zarglu 2024-02-02 09:46:06 UTC
I highly seconde devseppala's comment, I would really like to test the new text justification for typesetting, but I am not willing to convert all documents to docx for that.
Since the option is available for odt converted from docx, is there a way to force it manually? Even if it requires fiddling with the xml manually inside the odt.
Comment 32 Heiko Tietze 2024-03-01 13:54:26 UTC
Opening the simple test file from comment 15 I still get "Aliquam velit massa... Donec" in the third paragraph (while with a spacing of -0.1pt the following "consequat" would fit on the line). Anything I have to enable first?

Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 806362b915ee89a4f907905a8ac8c1527ea99223
CPU threads: 32; OS: Linux 6.7; UI render: default; VCL: kf5 (cairo+xcb)
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 33 Werner Tietz 2024-06-07 07:46:04 UTC
the fix of »this« is propably related to https://bugs.documentfoundation.org/show_bug.cgi?id=161451
Comment 34 László Németh 2024-10-18 06:31:41 UTC
(In reply to Heiko Tietze from comment #32)
> Opening the simple test file from comment 15 I still get "Aliquam velit
> massa... Donec" in the third paragraph (while with a spacing of -0.1pt the
> following "consequat" would fit on the line). Anything I have to enable
> first?

@Heiko: automatic letter spacing hasn't been supported (yet), only shrinking the space characters, like MSO does. This interoperability fix resulted the same layout in LibreOffice, too.