Skip to content

Commit

Permalink
#42 right to left text supporting
Browse files Browse the repository at this point in the history
  • Loading branch information
digao-dalpiaz committed Dec 15, 2024
1 parent d8adbb5 commit d8d103f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Source/Vcl.DHTokenEngine.pas
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ TDHBuilder = class
procedure ProcessSpecificObjects(List: TDHPreVisualItemList);

procedure CheckMissingClosingTags;
function GetDefaultHorzTextAlign: TDHHorzAlign;
public
constructor Create(Lb: TDzHTMLText; Canvas: TCanvas;
VisualItems: TDHVisualItemList; ProcBoundsAndLines: TDHProcBoundsAndLines);
Expand Down Expand Up @@ -1422,7 +1423,7 @@ procedure TDHToken_Div.Process;
Props.Offset.Top := 0;
Props.Offset.Bottom := 0;
Props.BackColor := clNone;
Props.HorzAlign := haLeft;
Props.HorzAlign := Builder.GetDefaultHorzTextAlign;
Props.VertAlign := vaTop;
Props.LineSpace := 0;
Props.ParagraphSpace := 0;
Expand Down Expand Up @@ -1677,7 +1678,7 @@ constructor TDHBuilder.Create(Lb: TDzHTMLText; Canvas: TCanvas;
Props.Offset.Bottom := Lb.CalcScale(Lb.Offset.Bottom);

Props.VertAlign := Lb.LineVertAlign;
Props.HorzAlign := Lb.LineHorzAlign;
Props.HorzAlign := GetDefaultHorzTextAlign;

Props.LineSpace := Lb.CalcScale(Lb.LineSpacing);
Props.ParagraphSpace := Lb.CalcScale(Lb.ParagraphSpacing);
Expand Down Expand Up @@ -1753,6 +1754,12 @@ procedure TDHBuilder.CheckMissingClosingTags;
end;
end;

function TDHBuilder.GetDefaultHorzTextAlign: TDHHorzAlign;
begin
Result := Lb.LineHorzAlign;
if Lb.RightToLeftText and (Result = haLeft) then Result := haRight;
end;

procedure TDHBuilder.AddInvalidToken(Position: Integer; const ErrorDescription: string);
var
Token: TDHToken_Word;
Expand Down Expand Up @@ -2282,6 +2289,9 @@ TFuncAlignResult = record
end;

begin
if Lb.RightToLeftText then
Item.Position.X := Line.TextSize.Width - (Item.Position.X + Item.Size.Width);

Check(0, True, Item.HorzAlign);
Check(1, False, Item.VertAlign);

Expand Down
16 changes: 16 additions & 0 deletions Source/Vcl.DzHTMLText.pas
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ TDzHTMLText = class(

FCursor: TCursor;

FRightToLeftText: Boolean;

UpdatingSemaphore: Integer;
InternalResizing: Boolean;

Expand Down Expand Up @@ -435,6 +437,8 @@ TDzHTMLText = class(
procedure SetParagraphIndent(const Value: TPixels);
procedure SetCustomStyles(const Value: TDHCustomStyles);

procedure SetRightToLeftText(const Value: Boolean);

{$IFDEF USE_IMGLST}
procedure SetImages(const Value: TCustomImageList);
{$ENDIF}
Expand Down Expand Up @@ -644,6 +648,8 @@ TDzHTMLText = class(
property ParagraphSpacing: TPixels read FParagraphSpacing write SetParagraphSpacing {$IFDEF VCL}default 0{$ENDIF};
property ParagraphIndent: TPixels read FParagraphIndent write SetParagraphIndent {$IFDEF VCL}default 0{$ENDIF};

property RightToLeftText: Boolean read FRightToLeftText write SetRightToLeftText default False;

property About: string read FAbout;
end;

Expand Down Expand Up @@ -1089,6 +1095,16 @@ procedure TDzHTMLText.SetParagraphIndent(const Value: TPixels);
end;
end;

procedure TDzHTMLText.SetRightToLeftText(const Value: Boolean);
begin
if Value<>FRightToLeftText then
begin
FRightToLeftText := Value;

BuildAndPaint;
end;
end;

procedure TDzHTMLText.SetListLevelPadding(const Value: TPixels);
begin
if Value<>FListLevelPadding then
Expand Down

0 comments on commit d8d103f

Please sign in to comment.