LCL: Fixed Canvas.TextExtend if system font is used for drawing. Issue #32319

git-svn-id: trunk@55757 -
This commit is contained in:
michl 2017-08-30 07:56:35 +00:00
parent 30a4170152
commit ec8f0f7ed0

View File

@ -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;
{------------------------------------------------------------------------------