Document from right to left.
Document from right to left.
How can I create a document that is read from right to left, instead of the traditional left to right format, in RichView?
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Document from right to left.
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.
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.
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?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.
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Document from right to left.
Please send me a simple project reproducing the problem (to email richviewgmailcom)
Re: Document from right to left.
I sended the email.Sergey Tkachenko wrote: ↑Sat Nov 23, 2024 6:31 pm Please send me a simple project reproducing the problem (to email richviewgmailcom)
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Document from right to left.
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:
(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.
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;
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.
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Document from right to left.
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:
As I said, BiDiMode assignment from HTML is not implemented yet. But alignment of paragraph is assigned according to the direction.
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>
Re: Document from right to left.
Thank you very much. Two issue remain.
- After loading html using your code I copy it by CopyDef and paste it in MS Word, All paragraphs is left to right there. so before CopyDef statement, I writed this code:
and the problem fixed.
Code: Select all
for i := 0 to RichViewEdit1.Style.ParaStyles.Count - 1 do begin RichViewEdit1.Style.ParaStyles[i].BiDiMode := rvbdRightToLeft; end;
- When I insert a footnote, the footnote number appears in English. Please see the screenshot.
- Attachments
-
- RichViewNote.png (47.02 KiB) Viewed 761 times
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Document from right to left.
Pasting from MS Word occurs via RTF format.
TRichView can read bi-di properties of text and paragraphs from RTF.
It happens if:
1. these properties are explicitly defined in RTF document
2. the target editor's BiDiMode is one of rvbdLeftToRight or rvbdRightToLeft (bi-di properties from RTF are ignored if the editor's BiDiMode = rvbdUnspecified)
As for footnotes, TRichView supports only the following types of numbering: https://www.trichview.com/help/idh_type_trvseqtype.html
See FootnoteNumbering property https://www.trichview.com/help/idh_trvs ... ering.html .
TRichView can read bi-di properties of text and paragraphs from RTF.
It happens if:
1. these properties are explicitly defined in RTF document
2. the target editor's BiDiMode is one of rvbdLeftToRight or rvbdRightToLeft (bi-di properties from RTF are ignored if the editor's BiDiMode = rvbdUnspecified)
As for footnotes, TRichView supports only the following types of numbering: https://www.trichview.com/help/idh_type_trvseqtype.html
See FootnoteNumbering property https://www.trichview.com/help/idh_trvs ... ering.html .