Page 119 - DCAP408_WEB_PROGRAMMING
P. 119
Unit 7: Character Sets, Fonts and the Keyboard
7.7 Selecting a Stock Font Notes
Windows comprises six stock fonts that are always obtainable. The fg_fontload() function states
which stock font fg_print() uses for showing strings. The stock font identifiers and their numeric
equivalents are:
OEM_FIXED_FONT (10)
ANSI_FIXED_FONT (11)
ANSI_VAR_FONT (12)
SYSTEM_FONT (13)
DEVICE_DEFAULT_FONT (14)
SYSTEM_FIXED_FONT (16)
Passing one of these identifiers or its numeric equivalent to fg_fontload() makes that font the
existing font, meaning fg_print() will use it for exhibiting strings.
To select the system font, for example, call fg_fontload(13) or fg_fontload(SYSTEM_FONT). By
default, fg_print() utilizes the OEM_FIXED_FONT because this font most closely looks like the
BIOS font used Fastgraph for DOS. We’ll show an example program that uses fg_fontload() in the
next section.
Self Assessment
Fill in the blank:
9. The ......................... function states which stock font fg_print() uses for showing strings.
7.8 Using Logical Fonts
Windows allows you to create additional fonts relying on the stock fonts, or from character
definitions in an external font file. Such fonts are known as logical fonts, and programs frequently
use logical fonts to offer additional typefaces and dissimilar character sizes. The Windows API
functions CreateFont() or CreateFontIndirect() generate logical fonts, and the fg_logfont()
function allows you to use logical fonts in a Fastgraph program.
Example: Logical Fonts
Generating a logical font first includes defining the fields in a LOGFONT structure. In the
Fontdemo example, we perform this at the end of the WM_CREATE handler, filling the LOGFONT
structure with values to generate a 24x12 script font from one of the stock fonts. The WM_CREATE
handler then passes this structure to the Windows API function CreateFontIndirect(), which
returns a handle of type HFONT to the new logical font. We can then pass this font handle to
fg_logfont() to turn on the font for fg_print() in the WM_PAINT handler.
Apart from showing how to create a logical font, the Fontdemo example displays how to use
stock fonts and logical fonts in Fastgraph programs. Its WM_PAINT handler consecutively
activates each of the six stock fonts and calls fg_print() to exhibit the font name by means of each
font (strings are output directly to the client area). It then activates the logical font and again
calls fg_print() to exhibit the text “script font” by means of the logical font. The result appears
like this:
LOVELY PROFESSIONAL UNIVERSITY 113