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

silvioprog silvioprog at gmail.com
Tue Jun 21 12:30:12 CEST 2011


Em 20 de junho de 2011 19:39, Flávio Etrusco
<flavio.etrusco at gmail.com> escreveu:
[...]
> TFreeTypeFont constructor doesn't receive a font name, so...
>
> I don't have freetype installed right now (I'm on Windows) so I can't
> test, but maybe you could try font.AllocateResources or
> FontMgr.RequestFont.

I tested this early on, but not work too.

I solved the problem, please see:

function LSFontExists(const AFileName: TFileName): Boolean;
{$IFDEF UNIX}
const
  VFontPath = '/usr/share/fonts';
{$ENDIF}
begin
  Result := FileExists(AFileName) or
{$IFDEF UNIX}
   (FileExists(VFontPath + AFileName)) or
   (FileExists(VFontPath + '/truetype/' + AFileName)) or
   (FileExists(VFontPath + '/truetype/freefont/')) ;
{$ENDIF}
{$IFDEF MSWINDOWS}
    FileExists(IncludeTrailingBackslash(GetEnvironmentVariable('windir')) +
      'Fonts' + DirectorySeparator + AFileName);
{$ENDIF}
end;

(...)
  VFreeTypeFont: TFreeTypeFont;
  VFPImageCanvas: TFPImageCanvas;
begin
  VFreeTypeFont := TFreeTypeFont.Create;
  VFPImageCanvas := TFPImageCanvas.Create(AImage);
  AImage.SetSize(80, 20);
  try
    VFreeTypeFont.Name := AFontName;
    VFreeTypeFont.Size := AFontSize;
    VFreeTypeFont.FPColor := AFontColor;
    if not function LSFontExists(ftLiberationSerifRegularTTF) then
      raise Exception.Create(Format(sErrFontFileNotFound,
        [ftLiberationSerifRegularTTF]));
      raise
    VFPImageCanvas.Font := VFreeTypeFont;
(...)

> Best regards,
> Flávio

-- 
Silvio Clécio
===============================================
Blog - <silvioprog.com.br>
Twitter - <twitter.com/silvioprog>
LazSolutions - <code.google.com/p/lazsolutions>
LazWebSolutions - <code.google.com/p/lazwebsolutions>
Lazarus-BR - <groups.google.com.br/group/lazarus-br?hl=pt-BR>
===============================================
   * Conheça nosso canal IRC sobre Lazarus: #lazarus-br *
===============================================




More information about the Lazarus mailing list