TvPlanIt: More compatibile calculation of average character size, avoids crash in cocoa.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8889 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-07-21 21:41:21 +00:00
parent d9d497757b
commit 64ad1bbe8c

View File

@ -1602,9 +1602,25 @@ end;
function TVpLineWrapper.GetAverageCharSize(ACanvas: TCanvas): Integer;
var
Metrics: TTextMetric;
{$IFDEF LCL}
bmp: TBitmap;
{$ELSE}
SavedFontHandle: THandle;
DC: HDC;
{$ENDIF}
begin
{$IFDEF LCL}
// The Delphi version crashes in cocoa.
bmp := TBitmap.Create;
try
bmp.SetSize(10, 10);
bmp.Canvas.Font.Assign(ACanvas.Font);
GetTextMetrics(bmp.Canvas.Handle, Metrics) then
Result := Metrics.tmAveCharWidth;
finally
bmp.Free;
end;
{$ELSE}
DC := GetDC(0);
SavedFontHandle := SelectObject(DC, ACanvas.Font.Reference.Handle);
try
@ -1614,6 +1630,7 @@ begin
SelectObject(DC, SavedFontHandle);
ReleaseDC(0, DC);
end;
{$ENDIF}
end;
function TVpLineWrapper.GetNextRectangle(ARegion: HRGN;