Editor demo supporting bidirected text (Arabic, Hebrew)

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 13149
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Editor demo supporting bidirected text (Arabic, Hebrew)

Post by Sergey Tkachenko » Thu Jan 31, 2013 9:23 am

This is a modification of Demos\DelphiUnicode\Editors\Editor 2\ improved to support bidirected text:
http://www.trichview.com/support/files/reditor_bidi.zip

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest