Bug 129448 - FORMATTING: Line spacing (wrongly) affects automatic first-line indent of Chinese text
Summary: FORMATTING: Line spacing (wrongly) affects automatic first-line indent of Chi...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
6.2.8.2 release
Hardware: All All
: medium normal
Assignee: Kevin Suo
URL:
Whiteboard: target:7.4.0
Keywords:
Depends on:
Blocks: Paragraph-Indent
  Show dependency treegraph
 
Reported: 2019-12-17 13:24 UTC by Liaison to zh-CN User Community
Modified: 2022-09-09 07:39 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Example document with Chinese text, automatic first-line indent, double line spacing (9.90 KB, application/vnd.oasis.opendocument.text)
2019-12-17 13:28 UTC, Liaison to zh-CN User Community
Details
Same example document with flag (12.73 KB, application/vnd.oasis.opendocument.text)
2021-12-21 08:45 UTC, Kevin Suo
Details
layout-bad.xml (5.95 KB, text/xml)
2021-12-21 08:47 UTC, Kevin Suo
Details
layout-good.xml (5.73 KB, text/xml)
2021-12-21 08:47 UTC, Kevin Suo
Details
compare.diff (9.28 KB, patch)
2021-12-21 08:50 UTC, Kevin Suo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Liaison to zh-CN User Community 2019-12-17 13:24:46 UTC
Description:
Forwarding a bug report discovered during discussion in a Chinese LO discussion group.

In mainland China (and I've heard in other places that uses CJK text, too), it's conventional to use "two-character width" indent for the first line of a paragraph.  LO correctly implement this with automatic first-line indent for Chinese text.

However it seems to only work for single spacing, and changing the line spacing to anything else proportional would change the indent width as well.

Steps to Reproduce:
1. Create a new document with Writer;
2. Type or paste a paragraph of Chinese text (at least two lines for better visual cues), leave them in "Default Style", not "Text Body";
3. Set the first-line indent to automatic (either directly change paragraph format or modify the paragraph style, then "Indents & Spacing" tab -> Indent -> check the box in front of "Automatic" under "First line"), also make sure the "Line Spacing" on the same tab is "Single";
4. Notice that the first line is nicely indented by two characters, so far so good;
5. Go back to the Format/Style dialog, same "Indents & Spacing" tab, change "Line Spacing" to "Double".

Actual Results:
The first line is now indented by four character's width

Expected Results:
The first line indent keeps at two character's width


Reproducible: Always


User Profile Reset: Yes



Additional Info:
The effect is proportional to the spacing, as "1.5 Lines" spacing gives three-character-width indent.  The "At least" spacing doesn't seem to affect the indent.

I don't know what the indent convention for western text is, and whether it should depend on line spacing; but for Chinese (and I assume most other CJK) text, it should keep constant regardless of the line spacing.

The original reporter uses LO 6.2.8 on Windows:
版本: 6.2.8.2 (x64)
Build ID: f82ddfca21ebc1e222a662a32b25c0c9d20169ee
CPU 线程: 8; 操作系统: Windows 10.0; UI 渲染: 默认; VCL: win; 
区域语言: zh-CN (zh_CN); UI 语言: zh-CN
Calc: threaded

I can reproduce on both 6.3.4
版本: 6.3.4.2 (x64)
Build ID: 60da17e045e08f1793c57c00ba83cdfce946d0aa
CPU 线程: 2; 操作系统: Windows 10.0; UI 渲染: 默认; VCL: win; 
区域语言: zh-CN (zh_CN); UI 语言: zh-CN
Calc: threaded
... and 6.4.0 beta1
Version: 6.4.0.0.beta1 (x64)
Build ID: 4d7e5b0c40ed843384704eca3ce21981d4e98920
CPU threads: 2; OS: Windows 10.0 Build 18363; UI render: default; VCL: win; 
Locale: zh-CN (zh_CN); UI-Language: en-US
Calc: threaded
Comment 1 Liaison to zh-CN User Community 2019-12-17 13:28:38 UTC
Created attachment 156622 [details]
Example document with Chinese text, automatic first-line indent, double line spacing

This should be reproducible with any Chinese text, but for convenience I'm attaching an example document.  Here I changed format by modifying the "Default Style" paragraph style, with automatic first-line indent and double line spacing.

It should show the wrong "four-character width" indent.  Change the line spacing back to single and see the correct "two-character width" indent.
Comment 2 Liaison to zh-CN User Community 2019-12-18 10:42:40 UTC
According to bug 64975, Japanese text and Korean text use "one-character width" first line indent.  I assume that they don't want this indent width to be depending on line spacing, either.
Comment 3 Kevin Suo 2020-01-15 00:34:35 UTC
Set platfotm to all as in the Chinese discussion group people already reprodced on Debian.

https://bbs.libreofficechina.org/forum.php?mod=viewthread&tid=2371
Comment 4 Kevin Suo 2020-01-15 00:50:19 UTC
https://cgit.freedesktop.org/libreoffice/core/tree/sw/source/core/text/itrcrsr.cxx

void SwTextMargin::CtorInitTextMargin(...)
Comment 5 Kevin Suo 2020-01-15 14:55:23 UTC
Reproduced in
版本: 6.5.0.0.alpha0+
Build ID: 03fd45dce6afa83fc1fcbcd890edb36affd61981
CPU 线程: 4; 操作系统: Linux 5.0; UI 渲染: 默认; VCL: gtk3; 
区域语言: zh-CN (zh_CN.UTF-8); UI 语言: zh-CN
Calc: threaded

Ubuntu 18.04 X64

Set to NEW.
Comment 6 Liaison to zh-CN User Community 2020-01-16 08:56:51 UTC
(In reply to Kevin Suo from comment #4)
> https://cgit.freedesktop.org/libreoffice/core/tree/sw/source/core/text/
> itrcrsr.cxx
> 
> void SwTextMargin::CtorInitTextMargin(...)

Before trying to solve this ourselves, let's first ping the paragraph-indent meta bug and see if any developer there can provide some pointers.
Comment 7 Kevin Suo 2021-11-21 12:41:23 UTC
This(In reply to Liaison to zh-CN User Community from comment #6)
The "if( pSpace )" code block in there was since the very beginning of the file was imported, so it never worked.

I assume for some languages (e.g. English), for a better look the first line indent should change according to the line spacing. However for all the Chinese languages (Simplified Chinese, Traditional Chinese etc) if the indent is auto then it should always be 2-characters, no matter what the line space is.
Comment 8 Kevin Suo 2021-11-21 14:56:24 UTC
@Mark Hung:

I see you have worked on https://cgit.freedesktop.org/libreoffice/core/commit/?id=6cd04e9ea447a4828a6fc03d47a7d136f3914501.

Could you please advice, why the aLang as in:
LanguageType aLang = pNode->GetLang( 0, 1, css::i18n::ScriptType::ASIAN);

is always 2052 (i.e. Simplified Chinese, as defined in [1]) for me, even if I switch to a English locale or UI language? i even tried to set my system's user local and language to English, but the aLang is still 2052. If that is the case, then the following block will always be reached:

              if (aLang != LANGUAGE_KOREAN && aLang != LANGUAGE_JAPANESE)
                  nFirstLineOfs<<=1;

I want to use the aLang to see whether the language is Chinese, and if yes, then disable those if( pSpace ) code as shown in [2]. I am asking because, I find that if I do that then if the local or UI language is english then that block is also disabled.

[1] https://opengrok.libreoffice.org/xref/core/include/i18nlangtag/lang.h?r=29c41568#179
[2] https://opengrok.libreoffice.org/xref/core/sw/source/core/text/itrcrsr.cxx?r=20306831#254
Comment 9 Kevin Suo 2021-12-21 08:45:44 UTC
Created attachment 177046 [details]
Same example document with flag

This file is with the newly added "AutoFirstLineIndentDisregardLineSpace" in the patch.
Comment 10 Kevin Suo 2021-12-21 08:47:12 UTC
Created attachment 177047 [details]
layout-bad.xml

layout xml file generated without the patch
Comment 11 Kevin Suo 2021-12-21 08:47:46 UTC
Created attachment 177048 [details]
layout-good.xml

layout xml file generated with the patch
Comment 12 Kevin Suo 2021-12-21 08:50:16 UTC
Created attachment 177049 [details]
compare.diff

Diff of the two xml files.
Comment 13 Commit Notification 2022-01-03 07:35:44 UTC
Kevin Suo committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/86cffd61c1f01a18f4016bb09c8d63a581f5cded

tdf#129448: Auto first-line indent should not be effected by line space

It will be available in 7.4.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 14 Kevin Suo 2022-01-03 08:09:36 UTC
Fixed on master.
Comment 15 Kevin Suo 2022-01-13 15:48:42 UTC
Although this is now fixed, those who use this feature should be aware of the following:

1. As pointed out in the commit message, for compatibility with old documents, a compatability flag 'AutoFirstLineIndentDisregardLineSpace' is added in this patch, thus this patch only has effect to new ODF documents. This means that only fresh new documents created by the current master (and the future 7.4 release) will work. Old documents created by previous versions, even open with the newest libreoffice, will still change the first line indent value if the line spacing changes.

2. If you save to DOCX or DOC format, you must be aware of bug 58194 (that is, currently the auto first line indent is lost, i.e. reset to zero).
Comment 16 Liaison to zh-CN User Community 2022-01-27 09:45:30 UTC
Confirmed with 7.4/master daily build on Windows 10:
Version: 7.4.0.0.alpha0+ (x64) / LibreOffice Community
Build ID: eb69767d7c1bb8e6e780fd9503f08c9d7f5ecb45
CPU threads: 2; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: zh-CN (zh_CN); UI: zh-CN
Calc: threaded

Tested changing line spacing as well as changing font size, both with style-based formatting and direct formatting.  All working as expected.

Thanks Kevin for the great work!