Bug 119961 - EDITING: Automatic cell alignment in Calc breaks with bidi-neutral characters
Summary: EDITING: Automatic cell alignment in Calc breaks with bidi-neutral characters
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
(earliest affected) release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
Keywords: implementationError
Depends on:
Blocks: RTL-CTL
  Show dependency treegraph
Reported: 2018-09-18 16:55 UTC by vaaydayaasra
Modified: 2019-10-16 09:05 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:

Screenshot of a Calc sheet which shows wrong default alignment (89.24 KB, image/png)
2018-09-18 16:56 UTC, vaaydayaasra

Note You need to log in before you can comment on or make changes to this bug.
Description vaaydayaasra 2018-09-18 16:55:42 UTC
Calc seems to assign the alignment of any particular text cell based on the contents of the cell: if the first character is a LTR character, the cell is aligned to the left, and if the first character is RTL, the cell is aligned to the right. This is desirable behavior but it breaks when the first character is neutral, i.e. a character that behaves as RTL in an RTL context and as LTR in a LTR context.

See the attached screenshot where cell A1 "abc" is automatically aligned to the left and cell A2 "ابت" to the right. When I surround these strings with parentheses, which are bidi-neutral characters, in A3 and A4, both are aligned to the left. For some reason, even font metrics break with this assignment, as the last character of the Arabic string overlaps visually with the closing parenthesis (I filed this as a separate issue at https://bugs.documentfoundation.org/show_bug.cgi?id=119960).

In column C, I have copied the contents of column A but changed the directionality setting of cell C4 manually to RTL through Format Cells > Text direction. Here the cell is properly aligned to the right and the closing parenthesis does not overlap with the last character of the string.

According to the Unicode standard, neutral characters should not affect directionality, and that’s what I would expect as a user, too. I think the best solution would be for Calc to skip all neutral characters in the beginning of the string and just consider the first strong character for cell alignment. Even better, Calc could use this heuristics to assign full text directionality for the cell, not just change alignment. Right now, if you start the cell with an RTL character followed by a LTR inset and then continue with RTL again, the substrings are ordered as in a LTR context ("FIRST second THIRD"), not as in true RTL ("THIRD second FIRST").

This bug was first reported for LO on Launchpad at https://bugs.launchpad.net/ubuntu/+source/libreoffice/+bug/1793126 . Another user there confirmed the bug on LO and

Steps to Reproduce:
1. In an empty Calc cell with default directionality, write some text in Arabic enclosed in parentheses.

Actual Results:
The cell is automatically aligned to the left.

Expected Results:
The cell should be aligned to the right, as parentheses are bidi-neutral and should not affect directionality at all.

Reproducible: Always

User Profile Reset: No

Additional Info:
Comment 1 vaaydayaasra 2018-09-18 16:56:33 UTC
Created attachment 144989 [details]
Screenshot of a Calc sheet which shows wrong default alignment
Comment 2 Buovjaga 2018-10-12 17:11:19 UTC
Apparently this feature was not yet in 3.3.0, but I can already repro in 3.6.7

Arch Linux 64-bit
LibreOffice 3.3.0 
OOO330m19 (Build:6)
tag libreoffice-

Arch Linux 64-bit
Version (Build ID: e183d5b)
Comment 3 QA Administrators 2019-10-13 02:34:14 UTC Comment hidden (obsolete)
Comment 4 vaaydayaasra 2019-10-16 09:05:42 UTC
Still reproducible on

Build ID: libreoffice-
CPU threads: 4; OS: Linux 4.15; UI render: default; VCL: gtk3; 
Locale: fi-FI (fi_FI.UTF-8); UI-Language: en-US
Calc: threaded