Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-03

Font handles from Win API

2 messages · 1 person · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Wolfram Kläger

Hi everyone,

IŽm too stupid for Windows. Before drawing text on a bitmap, I need to know the handle of the selected font, specified by name, say 'Arial'. This is my last attempt. Anybody knows, where IŽm still wrong?

  function CallbackProc(
    var AFontInfoVar : TEnumLogFont;
    var AMetricVar   : TNewTextMetric;
        AFontType    : DWORD;
        FontInfo     : TLogFont) : Integer stdcall;
  begin
    AMetricVar := AMetricVar; // avoid FPC hint 'not used'
    AFontType  := AFontType; // dito
    FontInfo := AFontInfoVar.elfLogFont;
    Result := 0; // assume success and stop enumeration
  end;
  function GetFontHandle(
    const AFontName : String) : hFont;
  var
    FontInfo : TLogFont;
  begin
    EnumFontFamilies(
      DeviceContext,
      PChar(AFontName),
      @CallbackProc,
      LongInt(nil + @FontInfo)
    );
    Result := CreateFontIndirect(@FontInfo);
  end;

Thanks in advance
Wolfram

Wolfram Kläger

I wrote something like

... CallbackProc( ... EnumFontFamilies( DeviceContext,

The problem is solved. Finally I managed to draw text of any style on any bitmap I want by squeezing Windows GDI the way it likes to be squeezed. Fortunately, the FPC windows unit works great. In some special cases, here or there was a flag, that the compiler could not identify, where MSDN says, it should. But these are of minor priority.

I learned a lot. But what about Linux? Suppose, itŽs the same effort, to find a low level recipe for printing text labels on bitmaps. Should I better change my kitchen at all, and install Lazarus? Though I donŽt need any visual components, full blown IDE etc.?

What is the appropriate pendant to GDI on Linux, for such lean purposes in a console / batch environment?

Regards
Wolfram