From f07535e01480192cd05bbb6ab1a040de3d5b7f05 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 9 Jul 2017 19:16:35 +0000 Subject: [PATCH] spktoolbar: Fix font scaling for Laz >= 1.8 git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5985 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../spktoolbar/SpkToolbar/SpkToolbar.pas | 27 +++++++++++++++++-- .../spktoolbar/SpkToolbar/spkt_Buttons.pas | 5 ---- .../spktoolbar/SpkToolbar/spkt_Checkboxes.pas | 2 -- .../spktoolbar/SpkToolbar/spkt_Const.pas | 20 -------------- .../spktoolbar/SpkToolbar/spkt_Pane.pas | 2 -- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/components/spktoolbar/SpkToolbar/SpkToolbar.pas b/components/spktoolbar/SpkToolbar/SpkToolbar.pas index d7fd6c407..c083c1fab 100644 --- a/components/spktoolbar/SpkToolbar/SpkToolbar.pas +++ b/components/spktoolbar/SpkToolbar/SpkToolbar.pas @@ -315,9 +315,14 @@ type { Setter for toolbar style, i.e. quick selection of new appearance theme } procedure SetStyle(const Value: TSpkStyle); + { LCL Scaling } {$IF lcl_fullversion >= 1080000} procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy; const AXProportion, AYProportion: Double); override; + + procedure FixDesignFontsPPI(const ADesignTimePPI: Integer); override; + + procedure ScaleFontsPPI(const AProportion: Double); override; {$ENDIF} public @@ -1394,7 +1399,6 @@ procedure TSpkToolbar.ValidateBuffer; TabRect := FTabRects[index]; FBuffer.canvas.font.Assign(AFont); - SpkScaleFont(FBuffer.Canvas.Font); if AOverrideTextColor <> clNone then clr := AOverrideTextColor else @@ -1737,7 +1741,6 @@ begin else TabAppearance := FAppearance; FBuffer.Canvas.font.Assign(TabAppearance.Tab.TabHeaderFont); - SpkScaleFont(FBuffer.Canvas.Font); TabWidth := 2 + // Frame 2 * TabCornerRadius + @@ -1794,6 +1797,9 @@ procedure TSpkToolbar.DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy; begin inherited; + if not (AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI]) then + exit; + LargeButtonDropdownFieldSize := round(LARGEBUTTON_DROPDOWN_FIELD_SIZE * AXProportion); LargeButtonGlyphMargin := round(LARGEBUTTON_GLYPH_MARGIN * AXProportion); LargeButtonCaptionHMargin := round(LARGEBUTTON_CAPTION_HMARGIN * AXProportion); @@ -1869,6 +1875,23 @@ begin if ToolbarCornerRadius > 1 then ToolbarCornerRadius := round(ToolbarCornerRadius * AXProportion); end; + +procedure TSpkToolbar.FixDesignFontsPPI(const ADesignTimePPI: Integer); +begin + inherited; + DoFixDesignFontPPI(FAppearance.Tab.TabHeaderFont, ADesignTimePPI); + DoFixDesignFontPPI(FAppearance.Pane.CaptionFont, ADesignTimePPI); + DoFixDesignFontPPI(FAppearance.Element.CaptionFont, ADesignTimePPI); +end; + +procedure TSpkToolbar.ScaleFontsPPI(const AProportion: Double); +begin + inherited; + DoScaleFontPPI(FAppearance.Tab.TabHeaderFont, AProportion); + DoScaleFontPPI(FAppearance.Pane.CaptionFont, AProportion); + DoScaleFontPPI(FAppearance.Element.CaptionFont, AProportion); +end; + {$ENDIF} end. diff --git a/components/spktoolbar/SpkToolbar/spkt_Buttons.pas b/components/spktoolbar/SpkToolbar/spkt_Buttons.pas index dea3e7f2e..e56682cd8 100644 --- a/components/spktoolbar/SpkToolbar/spkt_Buttons.pas +++ b/components/spktoolbar/SpkToolbar/spkt_Buttons.pas @@ -1082,7 +1082,6 @@ begin // Text ABuffer.Canvas.Font.Assign(FAppearance.Element.CaptionFont); ABuffer.Canvas.Font.Color := fontColor; - SpkScaleFont(ABuffer.Canvas.Font); if FButtonKind in [bkButton, bkToggle] then FindBreakPlace(FCaption, breakPos, breakWidth) @@ -1148,7 +1147,6 @@ begin exit; Bitmap.Canvas.Font.Assign(FAppearance.Element.CaptionFont); - SpkScaleFont(Bitmap.Canvas.Font); Width := Bitmap.Canvas.TextWidth(FCaption); @@ -1241,7 +1239,6 @@ begin begin // do not break the label Bitmap.Canvas.Font.Assign(FAppearance.Element.CaptionFont); - SpkScaleFont(Bitmap.Canvas.Font); TextWidth := 2 * LargeButtonCaptionHMargin + Bitmap.Canvas.TextWidth(FCaption); end; @@ -1322,7 +1319,6 @@ begin if FShowCaption then begin Bitmap.Canvas.Font.Assign(FAppearance.Element.CaptionFont); - SpkScaleFont(Bitmap.Canvas.Font); TextWidth := Bitmap.Canvas.TextWidth(FCaption); BtnWidth := BtnWidth + SmallButtonPadding + TextWidth; @@ -1542,7 +1538,6 @@ begin begin ABuffer.Canvas.Font.Assign(FAppearance.Element.CaptionFont); ABuffer.Canvas.Font.Color := fontColor; - SpkScaleFont(ABuffer.Canvas.Font); if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then x := FButtonRect.Left + SmallButtonHalfBorderWidth diff --git a/components/spktoolbar/SpkToolbar/spkt_Checkboxes.pas b/components/spktoolbar/SpkToolbar/spkt_Checkboxes.pas index b04a9c786..d604af1a5 100644 --- a/components/spktoolbar/SpkToolbar/spkt_Checkboxes.pas +++ b/components/spktoolbar/SpkToolbar/spkt_Checkboxes.pas @@ -200,7 +200,6 @@ begin exit; Bitmap.Canvas.Font.Assign(FAppearance.Element.CaptionFont); - SpkScaleFont(Bitmap.Canvas.Font); TextWidth := Bitmap.Canvas.TextWidth(FCaption); BtnWidth := SmallButtonPadding + SmallButtonGlyphWidth + @@ -334,7 +333,6 @@ begin // Text ABuffer.Canvas.Font.Assign(FAppearance.Element.CaptionFont); - SpkScaleFont(ABuffer.Canvas.Font); case FButtonState of bsIdle : fontColor := FAppearance.Element.IdleCaptionColor; diff --git a/components/spktoolbar/SpkToolbar/spkt_Const.pas b/components/spktoolbar/SpkToolbar/spkt_Const.pas index 05400c973..695ab9188 100644 --- a/components/spktoolbar/SpkToolbar/spkt_Const.pas +++ b/components/spktoolbar/SpkToolbar/spkt_Const.pas @@ -20,7 +20,6 @@ uses procedure SpkInitLayoutConsts(FromDPI: Integer; ToDPI: Integer = 0); function SpkScaleX(Size: Integer; FromDPI: Integer; ToDPI: Integer = 0): integer; function SpkScaleY(Size: Integer; FromDPI: Integer; ToDPI: Integer = 0): integer; -procedure SpkScaleFont(AFont: TFont; ToDPI: Integer = 0); const // **************** @@ -391,25 +390,6 @@ begin end; -procedure SpkScaleFont(AFont: TFont; ToDPI: Integer = 0); -var - FromDPI: Integer; -begin - if ToDPI = 0 then - ToDPI := ScreenInfo.PixelsPerInchY; - - FromDPI := AFont.PixelsPerInch; - - if (not DPI_AWARE) or (ToDPI = FromDPI) then - exit; - - if AFont.Size = 0 then - AFont.Height := MulDiv(GetFontData(AFont.Reference.Handle).Height, FromDPI, ToDPI) - else - AFont.Height := MulDiv(AFont.Height, FromDPI, ToDPI); - AFont.PixelsPerInch := ToDPI; -end; - initialization diff --git a/components/spktoolbar/SpkToolbar/spkt_Pane.pas b/components/spktoolbar/SpkToolbar/spkt_Pane.pas index f343c3a87..cbfb09911 100644 --- a/components/spktoolbar/SpkToolbar/spkt_Pane.pas +++ b/components/spktoolbar/SpkToolbar/spkt_Pane.pas @@ -316,7 +316,6 @@ begin // Pane label ABuffer.Canvas.Font.Assign(FAppearance.Pane.CaptionFont); - SpkScaleFont(ABuffer.Canvas.Font); x := FRect.Left + (FRect.Width - ABuffer.Canvas.TextWidth(FCaption)) div 2; y := FRect.Bottom - PaneBorderSize - PaneCaptionHeight + 1 + (PaneCaptionHeight - ABuffer.Canvas.TextHeight('Wy')) div 2; @@ -702,7 +701,6 @@ begin if tmpBitmap = nil then exit; tmpBitmap.Canvas.Font.Assign(FAppearance.Pane.CaptionFont); - SpkScaleFont(tmpBitmap.Canvas.Font); // *** Minimalna szerokoϾ tafli (tekstu) *** TextW := tmpBitmap.Canvas.TextWidth(FCaption);