[Lazarus] RE : How to I publish the SearchFont method of TFontManager?

Hans-Peter Diettrich DrDiettrich1 at aol.com
Tue Jun 21 09:19:40 CEST 2011


silvioprog schrieb:

> Another code that not works:
> 
> (...)
>   VFreeTypeFont: TFreeTypeFont;
>   VFPImageCanvas: TFPImageCanvas;
> begin
>   VFreeTypeFont := TFreeTypeFont.Create;
>   VFPImageCanvas := TFPImageCanvas.Create(AImage);
>   try
>     VFreeTypeFont.Name := AFontName;

If VFreeTypeFont were Nil, the AV would occur here!

>     VFreeTypeFont.Size := AFontSize;
>     VFreeTypeFont.FPColor := AFontColor;
>     if not Assigned(VFreeTypeFont) then
>       raise Exception.Create('My custom message');

The following is the really critical statement, where the platform 
fontmanager is asked to select the (closest) installed font, and assign 
it to the canvas:

>     VFPImageCanvas.Font := VFreeTypeFont;

Are you sure that VFPImageCanvas is not Nil???

When it definitely is the font, and not the canvas, then I'd try-except 
only *this* statement, and when it fails modify the FontName until no 
exception occurs.

When it is the font name, there should exist means to enumerate the 
installed fonts. At least the WinAPI allows to ask for the name of the 
closest font, based on general font attributes (w/o serifes...). Dunno 
what LCL/RTL offers for that purpose...

I also don't know how e.g. Win32 deals with *FreeType* fonts, in Delphi 
I've been working with *TrueType* fonts only.

DoDi





More information about the Lazarus mailing list