RTl with LTR alignment at the end of a line problem

General TRichView support forum. Please post your questions here
Post Reply
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

RTl with LTR alignment at the end of a line problem

Post by jgkoehn »

RVF appears to work correctly RTF and DOCX do not
Bidimode is set Left to Right.

When the file is loaded lines like

Code: Select all

whenever it is the last letter in a word). This occurs with the letters כ מ נ פ צ. 
Get switched around to this (The punctuation can get rotated around)

Code: Select all

whenever it is the last letter in a word). This occurs with the letters .כ מ נ פ צ
This can happen in line but rarely. It appears connected to ( ) . [ ] " (mainly punctuation) if there is an English character like a-z or A-Z after in Left to Right it does not appear to happen.
RVF seems to be fine.
Thoughts on the cause?
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: RTl with LTR alignment at the end of a line problem

Post by Sergey Tkachenko »

Please send me a file that is displayed incorrectly (to email richviewgmailcom)
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: RTl with LTR alignment at the end of a line problem

Post by Sergey Tkachenko »

This is quite a complex issue.
I'll try to explain what happens.

1. How TRichView arranges text in a line.
In TRichView, a document consists of items. One text item may contain a text of the same font.
If the paragraph has BiDiMode = "unspecified", all items on the line are arranged LTR.
If the paragraph has BiDiMode = LTR or RTL, items are arranged using more complex algorithm, depending on the paragraph LTR, but taking the item properties into account. Items can have LTR or RTL properties, or, if text BiDiMode = "unspecified", its text is taken into account.

What's with your text? I consider only the first paragraph.
The paragraph's BiDiMode = LTR, so a complex line arranging algorithm is used.
The Hebrew characters and spaces between them are separate items, because characters and spaces use different fonts. So TRichView line arrangement is important.
The Hebrew characters and spaces between them are explicitly marked as LTR, so they are arranged LTR.

What if they were not marked as LTR? TRichView would arrange this text RTL even in LTR paragraph, because in this case it takes text (Hebrew) into account.

2. What happens when you save and load RVF?

Document is saved and loaded as it is, with all BiDiMode properties, so the loaded document is displayed exactly like the original.

3. What happens when you save and load DocX/RTF?

TRichView saves BiDi properties of paragraphs and text (LTR and LTR in your case).
Loading: BiDi properties of text and paragraphs are loaded only if RichViewEdit.BiDiMode <> "unspecified" (because, in this case, the component assumes that you are not interested in BiDi properties).
So, if you want to load BiDi properties from DocX, assign RichViewEdit.BiDiMode = LTR (or RTL) before loading.
But there is one more problem: by default, if text's BiDiMode = paragraph's BiDiMode, the text's BiDiMode is reset to "unspecified". It was done to remove redundancy in RTF: in RTF, text's BiDiMode is usually always saved equal to the paragraph's BiDiMode.
However, it's not good in your case, because it affects item arrangement in the paragraph.
There is a compiler $define RVRTFNOTEXTBIDIRESET. If you define it, TRichView will not try to reset text's BiDiMode if it is equal to the paragraph's BiDiMode.
As a result,
- all text will be imported as LTR from RTF
- text will be imported from DocX like from RTF.

4. What happens if you load DocX/RTF in Word?

When I open this DocX in MS Word, it:
- displays the Hebrew text RTL
- starts a spelling checking
- when checking is finished, MS Word rearranges this Hebrew text RTL.
I found a way how to specify BiDiMode property of text differently, so that it will be displayed in MS Word LTR immediately.
It will be included in the next update. If you want, I can send changed files to you.

As for RTF, MS Word does not understand BiDi properties saved by TRichView. Unfortunately, this is a complex issue, I cannot fix it in near future.
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: RTl with LTR alignment at the end of a line problem

Post by jgkoehn »

Greetings Sergey,
Using the sample we sent over do you happen to have a way we can fix it via code? We run into this often whenever we have resources mixed with Hebrew and English.
Thank you sir.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: RTl with LTR alignment at the end of a line problem

Post by Sergey Tkachenko »

I fixed it only DocX. Currently, I do not know how to fix it in RTF.
If you want, I can send changed units to you.
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: RTl with LTR alignment at the end of a line problem

Post by jgkoehn »

Greetings Sergey I missee that you had the files. If you could send them over that would be great. Also for whrn it is in TRichView how would you fix it via code when. RTL has punctuation right after it. Do I need to put in a space with a ltr in it?
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: RTl with LTR alignment at the end of a line problem

Post by Sergey Tkachenko »

I sent modified TRichView files to the email in your profile. It includes changes in saving text BiDiMode in DocX, and some other changes.
Replace the files in TRichView\Source\
Post Reply