diff --git a/components/tvplanit/source/vpcanvasutils.pas b/components/tvplanit/source/vpcanvasutils.pas index d3fc0a544..ebcd70038 100644 --- a/components/tvplanit/source/vpcanvasutils.pas +++ b/components/tvplanit/source/vpcanvasutils.pas @@ -1602,9 +1602,25 @@ end; function TVpLineWrapper.GetAverageCharSize(ACanvas: TCanvas): Integer; var Metrics: TTextMetric; + {$IFDEF LCL} + bmp: TBitmap; + {$ELSE} SavedFontHandle: THandle; DC: HDC; -begin + {$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 @@ -1613,7 +1629,8 @@ begin finally SelectObject(DC, SavedFontHandle); ReleaseDC(0, DC); - end; + end; + {$ENDIF} end; function TVpLineWrapper.GetNextRectangle(ARegion: HRGN;