An application can select either a public or a private font with GpiCreateLogFont. A public font is available to all applications. A private font is loaded by an application for its exclusive use.
Use the Presentation Manager Control Panel to load a public font. Four DLLs contain the Times Roman, Helvetica, Courier, and System Monospaced image fonts. The names of these libraries are:
Unlike most DLLs, font libraries typically use the file name extension .FON. If the user loads all four libraries, a total of 76 public fonts are available. An application can use both outline and image formats of these fonts. Characters in the image format are available in sizes ranging from 8 to 24 points. Characters in the outline format can be any size.
Call GpiLoadFonts to load a private font. Pass the function the path and name of the DLL that contains the font. After the application loads the DLL of fonts, it can determine the characteristics of the fonts in that library by calling GpiQueryFonts.
To select a public font from all of the available public fonts, do the following:
#define INCL_GPILCIDS#include <os2.h> void fncFONT06(void){ FONTMETRICS fm, afm[80]; LONG cFonts = 0, cPublicFonts; HPS hps; cPublicFonts = GpiQueryFonts(hps, /* Queries all public fonts */ QF_PUBLIC, (PSZ) NULL, &cFonts, sizeof(fm), (PFONTMETRICS) NULL); } /* fncFONT06 */
Note: To load and use a private font, follow the same procedure, but specify QF_PRIVATE, instead of QF_PUBLIC, in the calls to GpiQueryFonts.
GpiQueryFonts the font metrics of every font available the array of FONTMETRICS structures. The font metrics define in detail the physical characteristics of a font.
Because the font metrics are so detailed, the amount of information returned to you from GpiQueryFonts can be extensive. You can restrict the amount of information returned by this function by:
If you request information for fewer fonts than are available on the system (that match the specified face name, and so forth), GpiQueryFonts returns a value indicating the number of fonts that it was unable to return.
The following figure is an example of this technique of selecting a font.
#define INCL_GPILCIDS #include <os2.h> PFONTMETRICS fncFONT07 (HPS hps, PLONG pcPublicFonts) { PFONTMETRICS afm = NULL; LONG fonts = 1000; *pcPublicFonts = GpiQueryFonts(hps, QF_PUBLIC, (PSZ) NULL, &fonts, sizeof(*afm), (PFONTMETRICS) NULL); if (!DosAllocMem(&afm, sizeof(*afm)*(*pcPublicFonts), PAG_COMMIT | PAGWRITE )) { GpiQueryFonts(hps, QF_PUBLIC, (PSZ) NULL, pcPublicFonts, sizeof(*afm), afm); } /* endif */ return afm; }
a.
If you do not supply a face name, the default font is used. If you supply a face name, and the presentation driver cannot find a matching font, a default font is selected.
The FATTRS structure describes a logical font. An application can have up to 254 logical fonts defined at any one time in a single presentation space. A logical font is a list of font attributes, whereas a physical font is the bit-map or vector information that the system uses to draw characters.
Copying the entries in the FATTRS structure ensures that, if a particular font is unavailable, an attempt is made to find the most suitable substitute. Without the FATTRS information, PM is less likely to locate a suitable font.
The following figure shows how to select an image font at least 14 device coordinate units high.
#define INCL_GPILCIDS#include <os2.h> LONG fncFONT08(HPS hps, LONG lcid, LONG xres, LONG yres) { FATTRS fat; PFONTMETRICS afm; LONG cFonts; LONG i; LONG rc = 0; afm = fncFONT07(hps, &cfonts); if (amf) { for (i=0; 1<cfonts; i++) { if (!(afm[i].fsDefn & FM_DEFN_OUTLINE) afm[i].sXDeviceRes == xres && afm[i].sYDeviceRes == yres && afm[i].lMaxBaselineExt >= 14) { fat.usRecordLength = sizeof(fat); fat.fsSelection = 0; fat.lMatch = 0; strcpy(fat.szFacename, afm[i].szFacename); fat.idRegistry = afm[i].idRegistry; fat.usCodePage = 0; fat.lMaxBaselineExt = afm[i].lMaxBaselineExt; fat.lAveCharWidth = afm[i].lAveCharWidth; fat.fsType = 0; fat.fsFontUse = 0; rc = GpiCreateLogFont(hps, (PSTR8) NULL, lcid, &fat); if (rc) { GpiSetCharSet(hps, lcid); } /* endif */ } /* endfor */ } /* endif */ return rc; }
GpiQueryFonts returns device coordinates for image fonts. For outline fonts, it returns notional coordinates. Notional coordinates are the coordinate in which the font was defined. Usually outline fonts are defined over a 1000-by-1000 matrix, with the unit of the matrix a 1/1000 of the em height.