mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-10 21:30:35 +02:00
LCL: Fixed Canvas.TextExtend if system font is used for drawing. Issue #32319
git-svn-id: trunk@55757 -
This commit is contained in:
parent
30a4170152
commit
ec8f0f7ed0
@ -1762,12 +1762,39 @@ end;
|
||||
Gets the width and height of a text
|
||||
------------------------------------------------------------------------------}
|
||||
function TCanvas.TextExtent(const Text: string): TSize;
|
||||
var
|
||||
DCIndex: Integer;
|
||||
ARect: TRect;
|
||||
|
||||
procedure SaveState;
|
||||
begin
|
||||
if DCIndex <> 0 then exit;
|
||||
DCIndex := SaveDC(FHandle);
|
||||
end;
|
||||
|
||||
procedure RestoreState;
|
||||
begin
|
||||
if DCIndex = 0 then exit;
|
||||
RestoreDC(FHandle, DCIndex);
|
||||
end;
|
||||
|
||||
begin
|
||||
Result.cX := 0;
|
||||
Result.cY := 0;
|
||||
if Text='' then exit;
|
||||
RequiredState([csHandleValid, csFontValid]);
|
||||
|
||||
DCIndex := 0;
|
||||
if Font.IsDefault then
|
||||
begin
|
||||
SaveState;
|
||||
SelectObject(FHandle, OnGetSystemFont());
|
||||
end;
|
||||
|
||||
ARect := Rect(0, 0, 0, 0);
|
||||
GetTextExtentPoint(FHandle, PChar(Text), Length(Text), Result);
|
||||
|
||||
RestoreState;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user