EnumFontFamiliesEX behaviour differs across widgetsets
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
Hi,
Whilst trying to get a cross-platform solution to get a list of all
fixed-pitch or mono-spaced fonts I noticed different behaviour of
EnumFontFamiliesEX between Win32 and Linux/GTK2 (I cannot test
QT/Carbon/Cocoa/CD/fpGui).
On Windows, when calling EnumFontFamiliesEX the lfPitchAndFamily field
of the TLogFont must be 0 (as per MS).
("lfPitchAndFamily Must be set to zero for all language versions of
the operating system." See:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd162620(v=vs.85).aspx
)
In the callbackfunction you can then check lfPitchAndFamily to see if
a font is fixed-pitcehd or mono-spaced.
On Linux-GTK2 (using pango functions) the lfPitchAndFamily however
must be set to the type of picth you want to retrieve. If you set it
to 0, then no fixed-pitched or mono-spaced fonts are retrieved.
I have been informed that Linux/QT behaves as Linux/GTK2 w.r.t. this.
Steps to reproduce:
Given the following callback function:
function EnumFontsFixedPitchNoDups(
var LogFont: TEnumLogFontEx;
var Metric: TNewTextMetricEx;
FontType: Longint;
Data: LParam):LongInt; stdcall;
var
L: TStringList;
S: String;
begin
L := TStringList(ptrint(Data));
S := LogFont.elfLogFont.lfFaceName;
if ((logfont.elfLogFont.lfPitchAndFamily and FIXED_PITCH) = FIXED_PITCH) and
(L.IndexOf(S) < 0) then
L.Add(S);
result := 1;
end;
And here the calling code:
procedure TForm1.LoadFontListFixedPitch;
var
DC: HDC;
lf: TLogFont;
L: TStringList;
i: Integer;
begin
L := TStringList.create;
lf.lfCharSet := DEFAULT_CHARSET;
lf.lfFaceName := '';
lf.lfPitchAndFamily := 0; // Needs to be FIXED_PITCH on Linux-GTK2
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DC := GetDC(0);
try
EnumFontFamiliesEX(DC, @lf, @EnumFontsFixedPitchNoDups, ptrint(L), 0);
L.Sort;
FixedBox.Items.Assign(L); //this is a TListBox on my form
finally
L.Free;
ReleaseDC(0, DC);
end;
end;
Setting lf.lfPitchAndFamily to FIXED_PITCH on Windows, does seem to
work, but since it is not how MS says it should be done, this might
stop functioning at any time.
Additional information:
The objective of this all is to have a reliable cross-platform way to get monospaced/fixed-pitch fonts, which would make selecting fonts for any editor that uses TSynEdit much easier.
Mantis conversion info:
- Mantis ID: 24231
- OS: Window
- OS Build: Win7
- Build: r40594
- Platform: i386
- Version: 1.1 (SVN)