From 451028576205f5d5c9d22f1b56c3b2ae6375b5f2 Mon Sep 17 00:00:00 2001 From: zeljan1 Date: Thu, 2 Jan 2025 12:08:47 +0100 Subject: [PATCH] LCL: changed SetDeviceScaleRatio HGDIOBJ param to HDC to be inline with cocoa abilities. --- components/turbopower_ipro/iphtml.pas | 2 +- lcl/include/intfbaselcl.inc | 4 ++-- lcl/include/lclintf.inc | 4 ++-- lcl/include/lclintfh.inc | 2 +- lcl/interfaces/qt5/qtlclintf.inc | 11 +++++++---- lcl/interfaces/qt5/qtlclintfh.inc | 2 +- lcl/interfaces/qt6/qtlclintf.inc | 11 +++++++---- lcl/interfaces/qt6/qtlclintfh.inc | 2 +- 8 files changed, 22 insertions(+), 16 deletions(-) diff --git a/components/turbopower_ipro/iphtml.pas b/components/turbopower_ipro/iphtml.pas index 1b0b9c843d..e585526d75 100644 --- a/components/turbopower_ipro/iphtml.pas +++ b/components/turbopower_ipro/iphtml.pas @@ -3429,7 +3429,7 @@ begin AScale := Application.MainForm.GetCanvasScaleFactor; PaintBufferBitmap.Width := Round(FClientRect.Right * AScale); PaintBufferBitmap.Height := Round(FClientRect.Bottom * AScale); - LCLIntf.SetDeviceScaleRatio(PaintBufferBitmap.Handle, AScale); + LCLIntf.SetDeviceScaleRatio(PaintBufferBitmap.Canvas.Handle, AScale); PaintBuffer := PaintBufferBitmap.Canvas; end; FTarget := PaintBuffer; diff --git a/lcl/include/intfbaselcl.inc b/lcl/include/intfbaselcl.inc index 1a05d0e6b1..becf6106e8 100644 --- a/lcl/include/intfbaselcl.inc +++ b/lcl/include/intfbaselcl.inc @@ -643,8 +643,8 @@ end; //This routine is used only by platforms which uses Scale instead of font DPI changes (or both). //Currently cocoa, qt5, qt6 and gtk3 are known to support this. Without proper scale ratio //setup, bitmap text rendering is blurred.See iphtml.pas, procedure TIpHtml.Render() how -//we use it.Param aObj is TQtImage under qt5 and qt6, under cocoa it's TBitmapContext. -procedure TWidgetSet.SetDeviceScaleRatio(aObj: HGDIOBJ; const AScaleRatio: double); +//we use it.Param DC is device context with selected bitmap/image into. +procedure TWidgetSet.SetDeviceScaleRatio(DC: HDC; const AScaleRatio: double); begin end; diff --git a/lcl/include/lclintf.inc b/lcl/include/lclintf.inc index 10e19b2df0..2895b15b1e 100644 --- a/lcl/include/lclintf.inc +++ b/lcl/include/lclintf.inc @@ -423,9 +423,9 @@ procedure SendCachedLCLMessages; begin end; -procedure SetDeviceScaleRatio(aObj: HGDIOBJ; const AScaleRatio: double); +procedure SetDeviceScaleRatio(DC: HDC; const AScaleRatio: double); begin - WidgetSet.SetDeviceScaleRatio(aObj, AScaleRatio); + WidgetSet.SetDeviceScaleRatio(DC, AScaleRatio); end; function SetCaretRespondToFocus(Handle: hWnd; ShowHideOnFocus: boolean):Boolean; diff --git a/lcl/include/lclintfh.inc b/lcl/include/lclintfh.inc index 5357b29e25..5377cc6c4b 100644 --- a/lcl/include/lclintfh.inc +++ b/lcl/include/lclintfh.inc @@ -109,7 +109,7 @@ procedure RemovePipeEventHandler(var AHandler: PPipeEventHandler); {$IFDEF IF_BA function RequestInput(const InputCaption, InputPrompt : String; MaskInput : Boolean; var Value : String) : Boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} procedure SendCachedLCLMessages; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} -procedure SetDeviceScaleRatio(aObj: HGDIOBJ; const AScaleRatio: double); {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} +procedure SetDeviceScaleRatio(DC: HDC; const AScaleRatio: double); {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} function SetCaretRespondToFocus(handle: HWND; ShowHideOnFocus: boolean): Boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} function SetComboMinDropDownSize(Handle: HWND; MinItemsWidth, MinItemsHeight, MinItemCount: integer): boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} procedure SetEventHandlerFlags(AHandler: PEventHandler; NewFlags: dword); {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} diff --git a/lcl/interfaces/qt5/qtlclintf.inc b/lcl/interfaces/qt5/qtlclintf.inc index 3000aaaf00..98512fb820 100644 --- a/lcl/interfaces/qt5/qtlclintf.inc +++ b/lcl/interfaces/qt5/qtlclintf.inc @@ -868,12 +868,15 @@ begin // todo end; -procedure TQtWidgetSet.SetDeviceScaleRatio(aObj: HGDIOBJ; const AScaleRatio: double); +procedure TQtWidgetSet.SetDeviceScaleRatio(DC: HDC; const AScaleRatio: double); +var + QtDc: TQtDeviceContext absolute DC; begin - if aObj <> 0 then + if IsValidDC(DC) and (QtDC.vImage <> nil) and (QtDC.vImage.Handle <> nil) then begin - if TObject(aObj) is TQtImage then - QImage_setDevicePixelRatio(TQtImage(aObj).Handle, AScaleRatio); + QPainter_end(QtDC.Widget); + QImage_setDevicePixelRatio(QtDC.vImage.Handle, AScaleRatio); + QPainter_begin(QtDC.Widget, QtDC.vImage.Handle); end; end; diff --git a/lcl/interfaces/qt5/qtlclintfh.inc b/lcl/interfaces/qt5/qtlclintfh.inc index 76476bdc09..af5eae1c92 100644 --- a/lcl/interfaces/qt5/qtlclintfh.inc +++ b/lcl/interfaces/qt5/qtlclintfh.inc @@ -73,7 +73,7 @@ procedure RemovePipeEventHandler(var AHandler: PPipeEventHandler); override; procedure RemoveProcessEventHandler(var AHandler: PProcessEventHandler); override; procedure SetEventHandlerFlags(AHandler: PEventHandler; NewFlags: dword); override; -procedure SetDeviceScaleRatio(aObj: HGDIOBJ; const AScaleRatio: double); override; +procedure SetDeviceScaleRatio(DC: HDC; const AScaleRatio: double); override; function SetComboMinDropDownSize(Handle: HWND; MinItemsWidth, MinItemsHeight, MinItemCount: integer): boolean; override; procedure SetRubberBandRect(const ARubberBand: HWND; const ARect: TRect); override; diff --git a/lcl/interfaces/qt6/qtlclintf.inc b/lcl/interfaces/qt6/qtlclintf.inc index 9b1d6a8446..1e494fe413 100644 --- a/lcl/interfaces/qt6/qtlclintf.inc +++ b/lcl/interfaces/qt6/qtlclintf.inc @@ -887,12 +887,15 @@ begin // todo end; -procedure TQtWidgetSet.SetDeviceScaleRatio(aObj: HGDIOBJ; const AScaleRatio: double); +procedure TQtWidgetSet.SetDeviceScaleRatio(DC: HDC; const AScaleRatio: double); +var + QtDc: TQtDeviceContext absolute DC; begin - if IsValidGDIObject(aObj) then + if IsValidDC(DC) and (QtDC.vImage <> nil) and (QtDC.vImage.Handle <> nil) then begin - if TObject(aObj) is TQtImage then - QImage_setDevicePixelRatio(TQtImage(aObj).Handle, AScaleRatio); + QPainter_end(QtDC.Widget); + QImage_setDevicePixelRatio(QtDC.vImage.Handle, AScaleRatio); + QPainter_begin(QtDC.Widget, QtDC.vImage.Handle); end; end; diff --git a/lcl/interfaces/qt6/qtlclintfh.inc b/lcl/interfaces/qt6/qtlclintfh.inc index 76476bdc09..af5eae1c92 100644 --- a/lcl/interfaces/qt6/qtlclintfh.inc +++ b/lcl/interfaces/qt6/qtlclintfh.inc @@ -73,7 +73,7 @@ procedure RemovePipeEventHandler(var AHandler: PPipeEventHandler); override; procedure RemoveProcessEventHandler(var AHandler: PProcessEventHandler); override; procedure SetEventHandlerFlags(AHandler: PEventHandler; NewFlags: dword); override; -procedure SetDeviceScaleRatio(aObj: HGDIOBJ; const AScaleRatio: double); override; +procedure SetDeviceScaleRatio(DC: HDC; const AScaleRatio: double); override; function SetComboMinDropDownSize(Handle: HWND; MinItemsWidth, MinItemsHeight, MinItemCount: integer): boolean; override; procedure SetRubberBandRect(const ARubberBand: HWND; const ARect: TRect); override;