Page 1 of 1

Editor demo supporting bidirectional text (Arabic, Hebrew)

Posted: Thu Jan 31, 2013 9:23 am
by Sergey Tkachenko
This is a modification of Demos\DelphiUnicode\Editors\Editor 2\ improved to support bi-directional text:
reditor_bidi.zip
(9.24 KiB) Downloaded 2847 times
Changes:

1) A default text direction (rve.BiDiMode) is made equal to rvbdLeftToRight:
- rve.BiDiMode := rvbdLeftToRight is assigned in "File | New"
- in "File | Open", if rve.BiDiMode=rvbdUnspecified, it is assigned equal to rvbdLeftToRight.
These changes do not allow rve.BiDiMode to be equal to rvbdUnspecified - it must be either RTL or LTR. In a real application, you can implement:
- commands to change the document default BiDiMode (just assign a value to rve.BiDiMode)
- implement an option dialog where users can choose the default text direction for new documents.

2) Two new buttons are added for changing BiDiMode of paragraphs to RTL or RTL. The buttons have a new unique value of GroupIndex and AllowAllUp=True.
Possible state of these buttons:
- LTR button is pressed: rvbdLeftToRight
- RTL button is pressed: rvbdRightToLeft
- both buttons unpressed: rvbdUnspecified (using a default document text direction, i.e. rvbdLeftToRight in this demo).
This value is returned in function GetParaBiDiFromUI: TRVBiDiMode.
A state of the buttons is updated in rve.OnCurParaStyleChanged.

A new constant is added to PARA_*** constants:
PARA_BIDIMODE = 5;
When the buttons are clicked:

Code: Select all

  rve.ApplyParaStyleConversion(PARA_BIDIMODE);
A new code is added to TForm1.rveParaStyleConversion:

Code: Select all

var ParaInfo: TParaInfo;
    OldBiDiMode, NewBiDiMode: TRVBiDiMode;
...
      PARA_BIDIMODE:
        begin
          OldBiDiMode := ParaInfo.BiDiMode;
          if OldBiDiMode=rvbdUnspecified then
            OldBiDiMode := rve.BiDiMode;
          NewBiDiMode := GetParaBiDiFromUI;
          if NewBiDiMode=rvbdUnspecified then
            NewBiDiMode := rve.BiDiMode;
          if OldBiDiMode<>NewBiDiMode then
            case ParaInfo.Alignment of
              rvaLeft: ParaInfo.Alignment := rvaRight;
              rvaRight: ParaInfo.Alignment := rvaLeft;
            end;
          ParaInfo.BiDiMode := GetParaBiDiFromUI;
        end;
As you can see, if text direction is changed to the opposite value, paragraph alignment is changed to the opposite value as well.

3) A new button is added to show special characters. It is useful, because TRichViewEdit shows a paragraph text direction in "end of paragraph" marks.

This demo does not include commands to change BiDiMode of selected text fragments, because changing paragraph properties is enough for the most cases.

PS: If you use RichViewActions, you can just use the following actions: TrvActionParaRTL, TrvActionParaLTR, TrvActionTextRTL, TrvActionTextLTR.
[+] History of updates
2021-12-07: compatibility with new version of TRichView

Re: Editor demo supporting bidirected text (Arabic, Hebrew)

Posted: Thu Apr 12, 2018 10:08 am
by Sergey Tkachenko
Known problem: in old versions of Delphi, this demo may crash on start.
Workaround: in Unit1.pas, add ActiveX in "uses" and the following code before the final "end.":

Code: Select all

initialization
  OleInitialize(nil)
finalization
  OleUninitialize;

Re: Editor demo supporting bidirectional text (Arabic, Hebrew)

Posted: Tue Dec 07, 2021 8:46 am
by Nostradamus
Hi Sergey,
This demo failed to compile on Delphi 11 Ent. in Win 10 64 Bit

cheers
Richard

Re: Editor demo supporting bidirectional text (Arabic, Hebrew)

Posted: Tue Dec 07, 2021 9:29 am
by Sergey Tkachenko
RVTypes must be added in "uses".
I updated the file.

Re: Editor demo supporting bidirectional text (Arabic, Hebrew)

Posted: Wed Dec 08, 2021 10:06 am
by Nostradamus
Thanks Sergey,
It works now.
cheers

Richard