Skip to content

Commit d8adbb5

Browse files
Merge pull request #95 from digao-dalpiaz/gdi-paint
Gdi paint
2 parents 20af4a0 + 1376373 commit d8adbb5

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

CompInstall.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ IniVersion=2
33

44
[General]
55
Name=Digao Dalpiaz - DzHTMLText component
6-
Version=6.5
6+
Version=6.6
77
DelphiVersions=XE3;XE4;XE5;XE6;XE7;XE8;10;10.1;10.2;10.3;10.4;11;12
88
Packages=DzHTMLText_VCL;DzHTMLText_FMX;DzHTMLTextDesign_VCL;DzHTMLTextDesign_FMX
99
AddLibrary=1

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@
3838

3939
## What's New
4040

41-
- 10/14/2024 (Version 6.5)
41+
- 11/14/2024 (Version 6.6)
4242

43-
- New Corner Radius ("radius") property for Div tag
43+
- Use GDI painting from Windows API when using VCL + Windows to draw rounded div
44+
- Fix access violation when DPI Scaling in VCL (early access to TForm.Monitor)
4445

4546
<details>
4647
<summary>Click here to view the entire changelog</summary>
4748

49+
- 10/14/2024 (Version 6.5)
50+
51+
- New Corner Radius ("radius") property for Div tag
52+
4853
- 03/26/2024 (Version 6.4)
4954

5055
- Fix Delphi XE3 compiling (Design packages and FMX FillRect)

Source/Defines.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
{$DEFINE VCL}
1111
{$DEFINE USE_NEW_ENV}
1212
{$DEFINE USE_IMGLST}
13+
14+
{$IFDEF MSWINDOWS}
15+
{$DEFINE USE_GDI}
16+
{$ENDIF}
1317
{$ENDIF}
1418

1519
{$ZEROBASEDSTRINGS OFF}

Source/Vcl.DzHTMLText.pas

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ interface
3535

3636
{$INCLUDE Types.inc}
3737
type
38+
TMyFontStyle = TFontStyle;
39+
3840
TDzHTMLText = class;
3941

4042
TDHLinkKind = (lkLinkRef, lkSpoiler);
@@ -678,9 +680,12 @@ implementation
678680
{$IFDEF MSWINDOWS}
679681
, Winapi.Windows, Winapi.ShellAPI
680682
{$ENDIF}
683+
{$ENDIF}
684+
{$IFDEF USE_GDI}
685+
, Winapi.GDIPOBJ, Winapi.GDIPAPI
681686
{$ENDIF};
682687

683-
const STR_VERSION = '6.5';
688+
const STR_VERSION = '6.6';
684689

685690
const DEFAULT_PPI = 96;
686691

@@ -1370,6 +1375,46 @@ procedure TDzHTMLText.Paint_VisualItem(W: TDHVisualItem; C: TCanvas);
13701375
raise EDHInternalExcept.Create('Invalid visual item object');
13711376
end;
13721377

1378+
{$IFDEF USE_GDI}
1379+
function ToGPColor(Color: TColor): TGPColor;
1380+
var
1381+
ColRef: COLORREF;
1382+
begin
1383+
ColRef := ColorToRGB(Color);
1384+
Result := MakeColor(GetRValue(ColRef), GetGValue(ColRef), GetBValue(ColRef));
1385+
end;
1386+
1387+
procedure PaintRoundRectangleUsingWindowsGDI(Canvas: TCanvas; Thick, Radius: Single; Rect: TRect; PenColor, BrushColor: TColor);
1388+
var
1389+
Gpx: TGPGraphics;
1390+
Pen: TGPPen;
1391+
Path: TGPGraphicsPath;
1392+
Brush: TGPSolidBrush;
1393+
begin
1394+
Gpx := TGPGraphics.Create(Canvas.Handle);
1395+
Pen := TGPPen.Create(ToGPColor(PenColor), Thick);
1396+
Brush := TGPSolidBrush.Create(ToGPColor(BrushColor));
1397+
Path := TGPGraphicsPath.Create;
1398+
try
1399+
Gpx.SetSmoothingMode(SmoothingModeAntiAlias);
1400+
1401+
Path.AddArc(Rect.Left, Rect.Top, Radius, Radius, 180, 90);
1402+
Path.AddArc(Rect.Left + Rect.Width - Radius, Rect.Top, Radius, Radius, 270, 90);
1403+
Path.AddArc(Rect.Left + Rect.Width - Radius, Rect.Top + Rect.Height - Radius, Radius, Radius, 0, 90);
1404+
Path.AddArc(Rect.Left, Rect.Top + Rect.Height - Radius, Radius, Radius, 90, 90);
1405+
Path.CloseFigure;
1406+
1407+
if BrushColor<>clNone then Gpx.FillPath(Brush, Path);
1408+
if (PenColor<>clNone) and (Thick>0) then Gpx.DrawPath(Pen, Path);
1409+
finally
1410+
Path.Free;
1411+
Brush.Free;
1412+
Pen.Free;
1413+
Gpx.Free;
1414+
end;
1415+
end;
1416+
{$ENDIF}
1417+
13731418
procedure TDzHTMLText.Paint_Div(C: TCanvas; R: TAnyRect; W: TDHVisualItem_Div);
13741419

13751420
procedure PaintSide(var Side: TDHDivBorderLineAttrRec; X, Y, W, H: TPixels);
@@ -1394,6 +1439,9 @@ procedure TDzHTMLText.Paint_Div(C: TCanvas; R: TAnyRect; W: TDHVisualItem_Div);
13941439

13951440
if W.CornerRadius>0 then
13961441
begin
1442+
{$IFDEF USE_GDI}
1443+
PaintRoundRectangleUsingWindowsGDI(C, W.Left.Thick, W.CornerRadius, R, W.Left.Color, W.InnerColor);
1444+
{$ELSE}
13971445
if (W.Left.Thick>0) and (W.Left.Color<>clNone) then
13981446
begin
13991447
{$IFDEF FMX}
@@ -1422,6 +1470,7 @@ procedure TDzHTMLText.Paint_Div(C: TCanvas; R: TAnyRect; W: TDHVisualItem_Div);
14221470
{$ELSE}
14231471
C.RoundRect(R, W.CornerRadius, W.CornerRadius);
14241472
{$ENDIF}
1473+
{$ENDIF}
14251474
end else
14261475
begin
14271476
if W.InnerColor<>clNone then
@@ -1696,7 +1745,7 @@ function TDzHTMLText.CalcMulDiv(Size: Integer): Integer;
16961745
{$ENDIF}
16971746
begin
16981747
{$IFDEF PPI_SCALING}
1699-
if (ParentForm<>nil) and THackForm(ParentForm).Scaled
1748+
if (ParentForm<>nil) and THackForm(ParentForm).Scaled and (ParentForm.Monitor<>nil)
17001749
{$IFDEF DCC}and not (csDesigning in ComponentState){$ENDIF} //design always based on Default PPI in Delphi
17011750
then
17021751
begin
@@ -1894,7 +1943,7 @@ procedure TDHStyleLinkProp.SetPropsToCanvas(C: TCanvas);
18941943
begin
18951944
if FFontColor<>clNone then DefineFontColor(C, FFontColor);
18961945
if FBackColor<>clNone then DefineFillColor(C, FBackColor);
1897-
if FUnderline then C.Font.Style := C.Font.Style + [TFontStyle.fsUnderline];
1946+
if FUnderline then C.Font.Style := C.Font.Style + [TMyFontStyle.fsUnderline];
18981947
end;
18991948

19001949
procedure TDHStyleLinkProp.Assign(Source: TPersistent);

0 commit comments

Comments
 (0)