Page 1 of 1

Document from right to left.

Posted: Sun Jul 07, 2024 10:15 pm
by Jeffreysox
How can I create a document that is read from right to left, instead of the traditional left to right format, in RichView?

Re: Document from right to left.

Posted: Mon Jul 08, 2024 10:19 am
by Sergey Tkachenko
Assign TRichView.BiDiMode = rvbdRightToLeft.
You can also assign BiDiMode of paragraphs of text fragments (using RVStyle.ParaStyles[].BiDiMode and RVStyle.TextStyles.BiDiMode). RichViewActions have actions to apply BiDiMode to selected paragraphs and text.

Re: Document from right to left.

Posted: Sat Nov 23, 2024 10:42 am
by saeid2016
Sergey Tkachenko wrote: Mon Jul 08, 2024 10:19 am Assign TRichView.BiDiMode = rvbdRightToLeft.
You can also assign BiDiMode of paragraphs of text fragments (using RVStyle.ParaStyles[].BiDiMode and RVStyle.TextStyles.BiDiMode). RichViewActions have actions to apply BiDiMode to selected paragraphs and text.
Hi, I downloaded the trial version and installed it on Delphi 12. I set all of TRichViewEdit.BidiMode and RVStyle.ParaStyles[].BiDiMode and RVStyle.TextStyles.BiDiMode to rvbdRightToLeft, But it is still left to right. How to fix this?

Re: Document from right to left.

Posted: Sat Nov 23, 2024 6:31 pm
by Sergey Tkachenko
Please send me a simple project reproducing the problem (to email richviewgmailcom)

Re: Document from right to left.

Posted: Sat Nov 23, 2024 7:26 pm
by saeid2016
Sergey Tkachenko wrote: Sat Nov 23, 2024 6:31 pm Please send me a simple project reproducing the problem (to email richviewgmailcom)
I sended the email.

Re: Document from right to left.

Posted: Wed Nov 27, 2024 9:44 am
by Sergey Tkachenko
Sorry for the delay.
In your example, everything works as expected.
 
1. The default BiDi mode (LTR or RTL) is applied to characters that do not have strong directional properties (i.e., to punctuation and spaces). Western characters are always displayed LRT, Arabic characters are always displayed RTL. Try typing any English text in your demo. You can see, the last space is always displayed to the left of the text, because the default direction is RTL. English characters are still displayed LTR (because that have a strong LTR property) as well as spaces between them (because spaces between LTR characters are considered LTR).

2. You can also see, since the default direction in this document is RTL, the LEFT and RIGHT arrow keys work in RTL mode: LEFT key moves to the next character, RIGHT key moves to the previous character. You can see it both in English and in Arabic text.

3. To make your HTML loading code work on my (non-Arabic) Windows, I modified it to load HTML in UTF-8 encoding:

Code: Select all

  strStream := TStringStream.Create(Memo1.Text, TEncoding.UTF8);
  RichViewEdit1.Clear;
  RichViewEdit1.DeleteUnusedStyles(true, true, true);
  RichViewEdit1.LoadHTMLFromStream(TStream(strStream), '', CP_UTF8);
  RichViewEdit1.Format;
(see the new parameters in TStringStream.Create and RichViewEdit1.LoadHTMLFromStream.

4. TRichView does not support loading DIR attribute from HTML (it will be implemented in the next update), so it is ignored. All paragraphs are loaded with default BiDi property (rvbdUnspecified). However, RichViewEdit1.BidiMode = rvbdRightToLeft, so the default direction in all paragraphs is RTL.

5. Arabic text from your HTML is displayed RTL.

Re: Document from right to left.

Posted: Wed Nov 27, 2024 10:01 am
by Sergey Tkachenko
6. About paragraph alignment. Unlike HTML, TRichView does not support "Start" and "End" alignment, only Left and Right (as well as Center, Justify and Distribute). Like in HTML, Left and Right alignments do not depend on BiDiMode.
However, when reading HTML, "Start" and "End" alignments are converted to "Left" and "Right" depending on the HTML direction.
So, why does text is left-aligned in your example? Because TRichView does not implement loading dir attribute yet (it will be implemented in the next update), However, CSS direction is supported. Try this:

Code: Select all

<div style="direction:rtl;">
<p style="color:red;">سلام</p>
</div>
As I said, BiDiMode assignment from HTML is not implemented yet. But alignment of paragraph is assigned according to the direction.