Author: Jonas Bilinkevicius
Windows organizes fonts by family and categorizes families with five family names.
A sixth name ("Dontcare") allows an application to use the default font. These
family names correspond to constants found in the WINGDI.H file: FF_DECORATIVE,
FF_DONTCARE, FF_MODERN, FF_ROMAN, FF_SCRIPT, and FF_SWISS. An application uses
these constants when it creates a font, selects a font, or retrieves information
about a font. Fonts within a family are distinguished by size (10 point, 24 point,
and so on) and style (regular, italic, and so on). However, it doesn't say how I
can get that setting for any given font. Is there a way to use GetObject to do this?
Answer:
The following table describes the font-family names:
Font-family name: Description
Decorative: Specifies a novelty font. An example is Old English.
Dontcare: Specifies a generic family name. This name is used when information about
a font does not exist or does not matter.
Modern: Specifies a monospace font with or without serifs. Monospace fonts are
usually modern; examples include Pica, Elite, and Courier New.
Roman: Specifies a proportional font with serifs. An example is Times New Roman.
Script: Specifies a font that is designed to look like handwriting; examples
include Script and Cursive.
Swiss: Specifies a proportional font without serifs. An example is Arial.
Here's a sample method, using the form's font:
1 procedure TForm1.Button1Click(Sender: TObject);
2 var
3 LogFont: TLogFont;
4 BytesReturned: integer;
5 s: string;
6 begin
7 BytesReturned := GetObject(Font.Handle, sizeof(LogFont), @LogFont);
8 if BytesReturned = 0 then
9 begin
10 caption := 'Failed';
11 exit;
12 end;
13 case LogFont.lfPitchAndFamily and $F0 of
14 FF_DONTCARE: s := 'Don''t care, or don''t know.';
15 FF_ROMAN: s := 'Variable stroke width, serifed.';
16 FF_SWISS: s := 'Variable stroke width, sans-serifed.';
17 FF_MODERN: s := 'Constant stroke width, serifed or sans-serifed.';
18 FF_SCRIPT: s := 'Script; Cursive, etc.';
19 FF_DECORATIVE: s := 'Decorative: Old English, etc.';
20 end;
21 caption := s;
22 end;
|