From e63efe6fb8394fa90bb0e9ed5a885ed2699ad2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Depin=C3=A9=20Dalpiaz?= Date: Wed, 26 Aug 2020 22:16:27 -0300 Subject: [PATCH 1/6] include overall align properties --- DzHTMLText.pas | 147 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 111 insertions(+), 36 deletions(-) diff --git a/DzHTMLText.pas b/DzHTMLText.pas index 568bc38..c398add 100644 --- a/DzHTMLText.pas +++ b/DzHTMLText.pas @@ -141,7 +141,8 @@ TDHStyleLinkProp = class(TPersistent) TDHEvLink = procedure(Sender: TObject; Link: TDHBaseLink) of object; TDHEvLinkClick = procedure(Sender: TObject; Link: TDHBaseLink; var Handled: Boolean) of object; - TDHLineVertAlign = (vaTop, vaCenter, vaBottom); + TDHVertAlign = (vaTop, vaCenter, vaBottom); + TDHHorzAlign = (haLeft, haCenter, haRight); TDHEvRetrieveImgRes = procedure(Sender: TObject; const ResourceName: String; Picture: TPicture; var Handled: Boolean) of object; @@ -173,7 +174,9 @@ TDzHTMLText = class(TGraphicControl) FOnRetrieveImgRes: TDHEvRetrieveImgRes; - FLineVertAlign: TDHLineVertAlign; + FLineVertAlign: TDHVertAlign; + FOverallVertAlign: TDHVertAlign; + FOverallHorzAlign: TDHHorzAlign; FLineSpacing: Integer; FListLevelPadding: Integer; @@ -208,7 +211,9 @@ TDzHTMLText = class(TGraphicControl) procedure CheckMouse(X, Y: Integer); //check links by mouse position procedure SetCursorWithoutChange(C: TCursor); procedure SetImages(const Value: TCustomImageList); - procedure SetLineVertAlign(const Value: TDHLineVertAlign); + procedure SetLineVertAlign(const Value: TDHVertAlign); + procedure SetOverallVertAlign(const Value: TDHVertAlign); + procedure SetOverallHorzAlign(const Value: TDHHorzAlign); procedure SetLineSpacing(const Value: Integer); procedure SetListLevelPadding(const Value: Integer); //procedure SetTransparent(const Value: Boolean); @@ -304,7 +309,9 @@ TDzHTMLText = class(TGraphicControl) property AutoOpenLink: Boolean read FAutoOpenLink write FAutoOpenLink default True; - property LineVertAlign: TDHLineVertAlign read FLineVertAlign write SetLineVertAlign default vaTop; + property LineVertAlign: TDHVertAlign read FLineVertAlign write SetLineVertAlign default vaTop; + property OverallVertAlign: TDHVertAlign read FOverallVertAlign write SetOverallVertAlign default vaTop; + property OverallHorzAlign: TDHHorzAlign read FOverallHorzAlign write SetOverallHorzAlign default haLeft; property LineSpacing: Integer read FLineSpacing write SetLineSpacing default 0; property ListLevelPadding: Integer read FListLevelPadding write SetListLevelPadding default _DEF_LISTLEVELPADDING; @@ -585,7 +592,7 @@ procedure TDzHTMLText.SetText(const Value: String); FLines.Text := Value; end; -procedure TDzHTMLText.SetLineVertAlign(const Value: TDHLineVertAlign); +procedure TDzHTMLText.SetLineVertAlign(const Value: TDHVertAlign); begin if Value<>FLineVertAlign then begin @@ -595,6 +602,26 @@ procedure TDzHTMLText.SetLineVertAlign(const Value: TDHLineVertAlign); end; end; +procedure TDzHTMLText.SetOverallVertAlign(const Value: TDHVertAlign); +begin + if Value<>FOverallVertAlign then + begin + FOverallVertAlign := Value; + + BuildAndPaint; + end; +end; + +procedure TDzHTMLText.SetOverallHorzAlign(const Value: TDHHorzAlign); +begin + if Value<>FOverallHorzAlign then + begin + FOverallHorzAlign := Value; + + BuildAndPaint; + end; +end; + procedure TDzHTMLText.SetLineSpacing(const Value: Integer); begin if Value<>FLineSpacing then @@ -1331,7 +1358,7 @@ TPreObj_Visual = class(TPreObj) Group: Integer; //group number {The group is isolated at each line or tabulation to delimit text horizontal align area} FixedPos: TFixedPosition; - Align: TAlignment; + Align: TDHHorzAlign; LineSpace: Integer; Space: Boolean; Print: Boolean; @@ -1360,7 +1387,7 @@ TTokensProcess = class Items: TListPreObj; BackColor: TColor; - Align: TAlignment; + Align: TDHHorzAlign; LineSpace: Integer; LBold: TListStack; @@ -1371,7 +1398,7 @@ TTokensProcess = class LFontSize: TListStack; LFontColor: TListStack; LBackColor: TListStack; - LAlign: TListStack; + LAlign: TListStack; LLineSpace: TListStack; LHTMLList: TObjectListStack; LSpoilerDet: THTMLSpoilerDetList; @@ -1425,7 +1452,7 @@ constructor TTokensProcess.Create(xBuilder: TBuilder); C.Font.Assign(Lb.Font); BackColor := clNone; - Align := taLeftJustify; + Align := haLeft; LineSpace := Lb.FLineSpacing; Items := TListPreObj.Create; @@ -1440,7 +1467,7 @@ constructor TTokensProcess.Create(xBuilder: TBuilder); LFontSize := TListStack.Create; LFontColor := TListStack.Create; LBackColor := TListStack.Create; - LAlign := TListStack.Create; + LAlign := TListStack.Create; LLineSpace := TListStack.Create; LHTMLList := TObjectListStack.Create; @@ -1562,9 +1589,9 @@ procedure TTokensProcess.DoBackColor(T: TToken); procedure TTokensProcess.DoAlignment(T: TToken); begin case T.Kind of - ttAlignLeft: Align := taLeftJustify; - ttAlignCenter: Align := taCenter; - ttAlignRight: Align := taRightJustify; + ttAlignLeft: Align := haLeft; + ttAlignCenter: Align := haCenter; + ttAlignRight: Align := haRight; end; LAlign.AddOrDel(T, Align); Align := LAlign.Last; @@ -1956,10 +1983,38 @@ type TSizes = record procedure TTokensProcess.Publish; var - Z: TPreObj; V: TPreObj_Visual; - B: TGroupBound; - Offset, GrpLim: Integer; + +type + TFuncAlignResult = record + Outside, Inside: Integer; + end; + TFuncAlign = reference to function: TFuncAlignResult; + + procedure CheckAlign(horz: Boolean; prop: Variant; func: TFuncAlign); + var + R: TFuncAlignResult; + P: TPoint; + Offset: Integer; + begin + if prop>0 then //center or right + begin + R := func; + Offset := R.Outside - R.Inside; + if prop=1 then Offset := Offset div 2; //center + + P := TPoint.Create(0, 0); + if horz then + P.X := Offset + else + P.Y := Offset; + + V.Visual.Rect.Offset(P); + end; + end; + +var + Z: TPreObj; begin for Z in Items do begin @@ -1968,29 +2023,49 @@ procedure TTokensProcess.Publish; if not V.Print then Continue; //horizontal align - if V.Align in [taCenter, taRightJustify] then - begin - B := LGroupBound[V.Group]; - if B.Limit = -1 then - begin //group has no limit - if Lb.FAutoWidth then GrpLim := Builder.CalcWidth else GrpLim := Lb.Width; - end - else GrpLim := B.Limit; - - Offset := GrpLim - B.Right; - if V.Align=taCenter then Offset := Offset div 2; + CheckAlign(True, V.Align, + function: TFuncAlignResult + var + B: TGroupBound; + GrpLim: Integer; + begin + B := LGroupBound[V.Group]; + if B.Limit = -1 then + begin //group has no limit + if Lb.FAutoWidth or (Lb.FOverallHorzAlign in [haCenter, haRight]) then + GrpLim := Builder.CalcWidth + else + GrpLim := Lb.Width; + end + else GrpLim := B.Limit; - V.Visual.Rect.Offset(Offset, 0); - end; + Result.Outside := GrpLim; + Result.Inside := B.Right; + end); - //vertical align - if Lb.FLineVertAlign in [vaCenter, vaBottom] then - begin - Offset := LLineInfo[V.Line].Height - V.Visual.Rect.Height; - if Lb.FLineVertAlign=vaCenter then Offset := Offset div 2; + //vertical align + CheckAlign(False, Lb.FLineVertAlign, + function: TFuncAlignResult + begin + Result.Outside := LLineInfo[V.Line].Height; + Result.Inside := V.Visual.Rect.Height; + end); - V.Visual.Rect.Offset(0, Offset); - end; + //overall horizontal align + CheckAlign(True, Lb.FOverallHorzAlign, + function: TFuncAlignResult + begin + Result.Outside := Lb.Width; + Result.Inside := Builder.CalcWidth; + end); + + //overall vertical align + CheckAlign(False, Lb.FOverallVertAlign, + function: TFuncAlignResult + begin + Result.Outside := Lb.Height; + Result.Inside := Builder.CalcHeight + end); Lb.LVisualItem.Add(V.Visual); V.Visual := nil; From 48abe9b6bea5691989d7c53c7cc0063e0e1a2dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Depin=C3=A9=20Dalpiaz?= Date: Wed, 26 Aug 2020 22:25:34 -0300 Subject: [PATCH 2/6] Update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index addd196..f509c1c 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ ## What's New +- 08/27/2020 + + - Included overall align properties. + - 08/03/2020 - Fixed Lazarus extra line break (issue #23). @@ -238,12 +242,16 @@ This property calls ShellExecute method. `LineSpacing: Integer` = Specify the default line spacing in overall text. You can use `` tag to determine line spacing at specific lines. -`LineVertAlign: TDHLineVertAlign (vaTop, vaCenter, vaBottom)` = Allows you to specify the vertical alignment of each element in the line. This property only take effects when the elements have different heights. Default is `vaTop`. +`LineVertAlign: TDHVertAlign (vaTop, vaCenter, vaBottom)` = Allows you to specify the vertical alignment of each element in the line. This property only take effects when the elements have different heights at same line. Default is `vaTop`. `ListLevelPadding: Integer` = Determines the width of each list level in pixels, when using HTML list tags. `MaxWidth: Integer` = Specify the maximum width of text, when using AutoWidth property. +`OverallHorzAlign: TDHHorzAlign (haLeft, haCenter, haRight)` = Determines overall text horizontal alignment. This property only take effects if `AutoWidth` is false. + +`OverallVertAlign: TDHVertAlign (vaTop, vaCenter, vaBottom)` = Determines overall text vertical alignment. This property only take effects if `AutoHeight` is false. + `StyleLinkNormal: TDHStyleLinkProp` = Properties to format a link when is not selected by mouse. `StyleLinkHover: TDHStyleLinkProp` = Properties to format a link when is selected by mouse. From 66fe5855dc9c28f6375192f617dc107aa328810f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Depin=C3=A9=20Dalpiaz?= Date: Thu, 27 Aug 2020 13:06:22 -0300 Subject: [PATCH 3/6] overall align - lazarus compatibility --- DzHTMLText.pas | 122 ++++++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 57 deletions(-) diff --git a/DzHTMLText.pas b/DzHTMLText.pas index c398add..df22422 100644 --- a/DzHTMLText.pas +++ b/DzHTMLText.pas @@ -1427,6 +1427,8 @@ TTokensProcess = class procedure Realign; procedure Publish; + + procedure CheckAlign(V: TPreObj_Visual); end; procedure TBuilder.ProcessTokens; @@ -1981,40 +1983,89 @@ type TSizes = record Lb.FLineCount := LineCount; end; -procedure TTokensProcess.Publish; -var - V: TPreObj_Visual; - -type +procedure TTokensProcess.CheckAlign(V: TPreObj_Visual); +type TFuncAlignResult = record Outside, Inside: Integer; end; - TFuncAlign = reference to function: TFuncAlignResult; - procedure CheckAlign(horz: Boolean; prop: Variant; func: TFuncAlign); + function funcAlignHorz: TFuncAlignResult; + var + B: TGroupBound; + GrpLim: Integer; + begin + B := LGroupBound[V.Group]; + if B.Limit = -1 then + begin //group has no limit + if Lb.FAutoWidth or (Lb.FOverallHorzAlign in [haCenter, haRight]) then + GrpLim := Builder.CalcWidth + else + GrpLim := Lb.Width; + end + else GrpLim := B.Limit; + + Result.Outside := GrpLim; + Result.Inside := B.Right; + end; + + function funcAlignVert: TFuncAlignResult; + begin + Result.Outside := LLineInfo[V.Line].Height; + Result.Inside := V.Visual.Rect.Height; + end; + + function funcOverallAlignHorz: TFuncAlignResult; + begin + Result.Outside := Lb.Width; + Result.Inside := Builder.CalcWidth; + end; + + function funcOverallAlignVert: TFuncAlignResult; + begin + Result.Outside := Lb.Height; + Result.Inside := Builder.CalcHeight; + end; + + procedure Check(fnIndex: Byte; horz: Boolean; prop: Variant); var R: TFuncAlignResult; P: TPoint; Offset: Integer; - begin + begin if prop>0 then //center or right begin - R := func; + case fnIndex of + 0: R := funcAlignHorz; + 1: R := funcAlignVert; + 2: R := funcOverallAlignHorz; + 3: R := funcOverallAlignVert; + end; + Offset := R.Outside - R.Inside; if prop=1 then Offset := Offset div 2; //center - + P := TPoint.Create(0, 0); if horz then P.X := Offset else P.Y := Offset; - + V.Visual.Rect.Offset(P); - end; + end; end; +begin + Check(0, True, V.Align); + Check(1, False, Lb.FLineVertAlign); + + Check(2, True, Lb.FOverallHorzAlign); + Check(3, False, Lb.FOverallVertAlign); +end; + +procedure TTokensProcess.Publish; var - Z: TPreObj; + Z: TPreObj; + V: TPreObj_Visual; begin for Z in Items do begin @@ -2022,50 +2073,7 @@ TFuncAlignResult = record V := TPreObj_Visual(Z); if not V.Print then Continue; - //horizontal align - CheckAlign(True, V.Align, - function: TFuncAlignResult - var - B: TGroupBound; - GrpLim: Integer; - begin - B := LGroupBound[V.Group]; - if B.Limit = -1 then - begin //group has no limit - if Lb.FAutoWidth or (Lb.FOverallHorzAlign in [haCenter, haRight]) then - GrpLim := Builder.CalcWidth - else - GrpLim := Lb.Width; - end - else GrpLim := B.Limit; - - Result.Outside := GrpLim; - Result.Inside := B.Right; - end); - - //vertical align - CheckAlign(False, Lb.FLineVertAlign, - function: TFuncAlignResult - begin - Result.Outside := LLineInfo[V.Line].Height; - Result.Inside := V.Visual.Rect.Height; - end); - - //overall horizontal align - CheckAlign(True, Lb.FOverallHorzAlign, - function: TFuncAlignResult - begin - Result.Outside := Lb.Width; - Result.Inside := Builder.CalcWidth; - end); - - //overall vertical align - CheckAlign(False, Lb.FOverallVertAlign, - function: TFuncAlignResult - begin - Result.Outside := Lb.Height; - Result.Inside := Builder.CalcHeight - end); + CheckAlign(V); Lb.LVisualItem.Add(V.Visual); V.Visual := nil; From 36a29f98229cb5753f870a22afad8685399546d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Depin=C3=A9=20Dalpiaz?= Date: Thu, 27 Aug 2020 13:15:49 -0300 Subject: [PATCH 4/6] realign function renamed --- DzHTMLText.pas | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DzHTMLText.pas b/DzHTMLText.pas index df22422..6b79905 100644 --- a/DzHTMLText.pas +++ b/DzHTMLText.pas @@ -1425,7 +1425,7 @@ TTokensProcess = class procedure DoTab(T: TToken); procedure DoBreak; - procedure Realign; + procedure DefineVisualRect; procedure Publish; procedure CheckAlign(V: TPreObj_Visual); @@ -1437,7 +1437,7 @@ procedure TBuilder.ProcessTokens; P := TTokensProcess.Create(Self); try P.Execute; - P.Realign; + P.DefineVisualRect; P.Publish; finally P.Free; @@ -1802,7 +1802,7 @@ procedure TTokensProcess.DoBreak; // -procedure TTokensProcess.Realign; +procedure TTokensProcess.DefineVisualRect; type TSizes = record LineHeight, LineSpace, OverallWidth, OverallHeight: Integer; end; From 4480a2fb8a200e23fc13e5b19474ed2d82f68e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Depin=C3=A9=20Dalpiaz?= Date: Thu, 27 Aug 2020 13:22:05 -0300 Subject: [PATCH 5/6] changed version to 2.3 --- DzHTMLText.pas | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DzHTMLText.pas b/DzHTMLText.pas index 6b79905..05bfe1b 100644 --- a/DzHTMLText.pas +++ b/DzHTMLText.pas @@ -459,7 +459,7 @@ constructor TDzHTMLText.Create(AOwner: TComponent); ControlStyle := ControlStyle + [csOpaque]; //Warning! The use of transparency in the component causes flickering - FAbout := 'Digao Dalpiaz / Version 2.2'; + FAbout := 'Digao Dalpiaz / Version 2.3'; FLines := TStringList.Create; //FLines.TrailingLineBreak := False; -- only supported by Delphi 10.1 and not full funcionally in Lazarus diff --git a/README.md b/README.md index f509c1c..c45a815 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ ## What's New -- 08/27/2020 +- 08/27/2020 (Version 2.3) - Included overall align properties. From c33ff509f90cf42e7fe721ddb359d137ce1c37df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Depin=C3=A9=20Dalpiaz?= Date: Sun, 30 Aug 2020 17:09:58 -0300 Subject: [PATCH 6/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c45a815..84ed0f1 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ ## What's New -- 08/27/2020 (Version 2.3) +- 08/30/2020 (Version 2.3) - Included overall align properties.