From d8d103f6ef686c9d48e51f1888875dd5889c2ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Depin=C3=A9=20Dalpiaz?= Date: Sun, 15 Dec 2024 18:57:45 -0300 Subject: [PATCH] #42 right to left text supporting --- Source/Vcl.DHTokenEngine.pas | 14 ++++++++++++-- Source/Vcl.DzHTMLText.pas | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Source/Vcl.DHTokenEngine.pas b/Source/Vcl.DHTokenEngine.pas index 7fd6a5a..279be0a 100644 --- a/Source/Vcl.DHTokenEngine.pas +++ b/Source/Vcl.DHTokenEngine.pas @@ -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); @@ -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; @@ -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); @@ -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; @@ -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); diff --git a/Source/Vcl.DzHTMLText.pas b/Source/Vcl.DzHTMLText.pas index 99e84db..7db5bc9 100644 --- a/Source/Vcl.DzHTMLText.pas +++ b/Source/Vcl.DzHTMLText.pas @@ -377,6 +377,8 @@ TDzHTMLText = class( FCursor: TCursor; + FRightToLeftText: Boolean; + UpdatingSemaphore: Integer; InternalResizing: Boolean; @@ -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} @@ -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; @@ -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