Skip to content

Commit

Permalink
version 6.3 - vcl font scaling review
Browse files Browse the repository at this point in the history
  • Loading branch information
digao-dalpiaz committed Mar 25, 2024
1 parent 169223d commit 9231a0f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CompInstall.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ IniVersion=2

[General]
Name=Digao Dalpiaz - DzHTMLText component
Version=6.2
Version=6.3
DelphiVersions=XE3;XE4;XE5;XE6;XE7;XE8;10;10.1;10.2;10.3;10.4;11;12
Packages=DzHTMLText_VCL;DzHTMLText_FMX;DzHTMLTextDesign_VCL;DzHTMLTextDesign_FMX
AddLibrary=1
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@

## What's New

- 03/24/2024 (Version 6.2)
- 03/25/2024 (Version 6.3)

- Better FMX design-time border (using the Delphi pattern).
- Keep Canvas properties state in FMX (font changes and other Canvas properties were retained and could affect the painting of other controls on the form)
- VCL font scaling review (Height is calculated by default screen PPI)

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

- 03/24/2024 (Version 6.2)

- Better FMX design-time border (using the Delphi pattern).
- Keep Canvas properties state in FMX (font changes and other Canvas properties were retained and could affect the painting of other controls on the form)

- 02/26/2024 (Version 6.1)

- Opacity supporting in FMX environment.
Expand Down
35 changes: 20 additions & 15 deletions Source/Vcl.DzHTMLText.pas
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface
{$ENDIF}
{$ENDIF};

const DZHTMLTEXT_INTERNAL_VERSION = 712; //Synchronizes TDam component
const DZHTMLTEXT_INTERNAL_VERSION = 713; //Synchronizes TDam component

const _DEF_LISTLEVELPADDING = 20;

Expand Down Expand Up @@ -487,7 +487,7 @@ TDzHTMLText = class(
property SyntaxErrors: TDHSyntaxErrorList read LError;

{$IFDEF VCL}
function CalcMulDiv(Size, DesignPPI: Integer; IsFont: Boolean): Integer;
function CalcMulDiv(Size: Integer): Integer;
function CalcFontHeight(Size: Integer): Integer;
{$ENDIF}
function CalcScale(Size: TPixels): TPixels;
Expand Down Expand Up @@ -679,7 +679,7 @@ implementation
{$ENDIF}
{$ENDIF};

const STR_VERSION = '6.2';
const STR_VERSION = '6.3';

const DEFAULT_PPI = 96;

Expand Down Expand Up @@ -1651,35 +1651,40 @@ procedure TDzHTMLText.CMMouseleave(var Message: TMessage);

{$IFDEF VCL}
type THackForm = class(TCustomForm); //older Delphi version - Scaled is a protected property
function TDzHTMLText.CalcMulDiv(Size, DesignPPI: Integer; IsFont: Boolean): Integer;
function TDzHTMLText.CalcMulDiv(Size: Integer): Integer;
var
MonitorPPI: Integer;
MonitorPPI, DesignPPI: Integer;
begin
MonitorPPI := DEFAULT_PPI;
{$IF (Defined(DCC) and (CompilerVersion >= 30)) or Defined(FPC)} //D10 Seattle or Lazarus
if {$IFDEF DCC}not (csDesigning in ComponentState) and{$ENDIF} //design always based on Default PPI in Delphi
(ParentForm<>nil) and THackForm(ParentForm).Scaled then
if (ParentForm<>nil) and THackForm(ParentForm).Scaled
{$IFDEF DCC}and not (csDesigning in ComponentState){$ENDIF} //design always based on Default PPI in Delphi
then
begin
MonitorPPI := ParentForm.Monitor.PixelsPerInch;
{$ENDIF}
DesignPPI := {$IFDEF FPC}ParentForm.PixelsPerInch{$ELSE}DEFAULT_PPI{$ENDIF};
//in Delphi, form PixelsPerInch changes by current monitor
//in Lazarus, form PixelsPerInch stay fixed by designer (default screen)

{$IFDEF FPC}
if not IsFont and (ParentForm<>nil) then DesignPPI := ParentForm.DesignTimePPI;
Result := Round(Size * MonitorPPI / DesignPPI); //MulDiv equivalent
end else
{$ENDIF}

Result := Round(Size * MonitorPPI / DesignPPI); //MulDiv equivalent
Result := Size;
end;

function TDzHTMLText.CalcFontHeight(Size: Integer): Integer;
var
H: Integer;
begin
Result := -CalcMulDiv(Size, 72, True);
H := -Round(Size * Screen.PixelsPerInch / 72);
Result := CalcMulDiv(H);
end;
{$ENDIF}

function TDzHTMLText.CalcScale(Size: TPixels): TPixels;
begin
Result :=
{$IFDEF VCL}
CalcMulDiv(Size, DEFAULT_PPI, False)
CalcMulDiv(Size)
{$ELSE}
Size
{$ENDIF};
Expand Down

0 comments on commit 9231a0f

Please sign in to comment.