overview.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Using Fonts and Character Primitives (1.2)
About Section  Function Group                     Up Next Previous
────────────────────────────────────────────────────────────────────────────
 
                    Using Fonts and Character Primitives
 
You can use the font and character functions to perform the following
tasks:
 
♦  Select a font from the public fonts loaded with Control Panel.
 
♦  Select a font from a library of private fonts loaded by the application.
 
♦  Draw a string of text using the selected font.
 
♦  Scale, translate, and rotate a string of text from an outline font.
 
♦  Scale, shear, and alter the direction of a string of text from image and
   outline fonts.
 
Selecting a Public Font
 
To select a public font, you must perform the following tasks:
 
♦  Call the GpiQueryFonts function, passing the QF_PUBLIC flag, a NULL
   pointer to the font's face name, and a count of 0 to determine the number
   of available public fonts.
 
♦  Copy this number (the GpiQueryFonts return value) into an integer
   variable.
 
♦  Call GpiQueryFonts again, passing the QF_PUBLIC flag, a NULL pointer to
   the font's face name, and the count returned by the previous call.
 
♦  Examine the metrics, looking for the face name and attributes of the font
   that your application needs.
 
♦  Copy the appropriate metrics from the font that suits your application
   into a FATTRS structure.
 
♦  Initialize a local identifier (lcid) for the new font.
 
♦  Call the GpiCreateLogFont function, passing a local identifier for the
   font, the address of an empty array of eight characters, and the address
   of the FATTRS structure.
 
♦  Examine the return value from GpiCreateLogFont. If the function was
   successful, it should be 2.
 
♦  Pass the local identifier to the GpiSetCharSet function, assigning the
   font to your application's presentation space.
 
The following code fragment shows how to select a Helvetica public font:
 
i = 0;
while (!strcomp(afm[i++].szFacename, "Helv"));
lFontCount = GpiQueryFonts(hps,
    QF_PUBLIC,
    NULL,
    &lCount,
    (LONG) (sizeof(fm)),
    (PFONTMETRICS) afm);
lCount = lFontCount;
lFontCount = GpiQueryFonts(hps,
    QF_PUBLIC,
    NULL,
    &lCount,
    (LONG) (sizeof(fm)),
    (PFONTMETRICS) afm);
fat.usRecordLength = sizeof(fat);
fat.fsSelection = afm[i].fsSelection;
fat.lMatch = afm[i].lMatch;
strcpy(fat.szFacename, afm[i].szFacename);
fat.idRegistry = afm[i].idRegistry;
fat.usCodePage = afm[i].usCodePage;
fat.lMaxBaselineExt = afm[i].lMaxBaselineExt;
fat.lAveCharWidth = afm[i].lAveCharWidth;
fat.fsType = afm[i].fsType;
fat.fsFontUse = 0;
GpiCreateLogFont(hps,
    (PSTR8) chName,
    lcid,
    (PFATTRS) &fat);
GpiSetCharSet(hps, lcid);
 
Drawing Text
 
Before drawing text, you must determine which of the four text-output
functions you should use. The following list describes the specific purpose
of each text-output function:
 
Function name       Purpose
────────────────────────────────────────────────────────────────────────────
GpiCharString       This function draws a string of text starting at the
                    current position.
 
GpiCharStringAt     This function draws a string of text starting at a point
                    that you pass as a function argument. It is identical to
                    a function sequence of GpiMove, GpiCharString.
 
GpiCharStringPos    This function alters the intercharacter spacing in a
                    string of text in order to shade a special rectangle
                    that surrounds a string of text, to draw a string of
                    text in halftones, or to clip a string of text to a
                    special rectangle. This function starts drawing the text
                    at the current position.
 
GpiCharStringPosAt  This function alters the intercharacter spacing in a
                    string of text in order to shade a special rectangle
                    that surrounds a string of text, to draw a string of
                    text in halftones, or to clip a string of text to a
                    special rectangle. This function starts drawing the text
                    at a point that you pass as one of the function
                    arguments.
 
The following code fragment shows how to load an array of characters with
the string "MS OS/2 Presentation Manager", set the current position to the
point (100,100) by calling the GpiMove function, and then draw the string by
calling the GpiCharString function:
 
ptl.x = 100; ptl.y = 100;
GpiMove (hps, &ptl);
GpiCharString(hps, 28L, "MS OS/2 Presentation Manager");
 
Transforming Text from an Outline Font
 
The following code fragment shows how to rotate a string of text 90 degrees
counterclockwise by using the model transformation:
 
matlfTransform.fxM11 = MAKEFIXED(1, 0);       /* translates text */
matlfTransform.fxM12 = MAKEFIXED(0, 0);
matlfTransform.lM13 = 0L;
matlfTransform.fxM21 = MAKEFIXED(0, 0);
matlfTransform.fxM22 = MAKEFIXED(1, 0);
matlfTransform.lM23 = 0L;
matlfTransform.lM31 = -300L;
matlfTransform.lM32 = -100L;
matlfTransform.lM33 = 1L;
GpiSetModelTransformMatrix(hps, 9L, &matlfTransform,
    TRANSFORM_REPLACE);
 
matlfTransform.fxM11 = MAKEFIXED(0, 0);       /* rotates text */
matlfTransform.fxM12 = MAKEFIXED(1, 0);
matlfTransform.lM13 = 0L;
matlfTransform.fxM21 = -MAKEFIXED(1, 0);
matlfTransform.fxM22 = MAKEFIXED(0, 0);
matlfTransform.lM23 = 0L;
matlfTransform.lM31 = 0L;
matlfTransform.lM32 = 0L;
matlfTransform.lM33 = 1L;
GpiSetModelTransformMatrix(hps, 9L, &matlfTransform, TRANSFORM_ADD);
 
matlfTransform.fxM11 = MAKEFIXED(1, 0);       /* translates again */
matlfTransform.fxM12 = MAKEFIXED(0, 0);
matlfTransform.lM13 = 0L;
matlfTransform.fxM21 = MAKEFIXED(0, 0);
matlfTransform.fxM22 = MAKEFIXED(1, 0);
matlfTransform.lM23 = 0L;
matlfTransform.lM31 = 300L;
matlfTransform.lM32 = 100L;
matlfTransform.lM33 = 1L;
GpiSetModelTransformMatrix(hps, 9L, &matlfTransform, TRANSFORM_ADD);
 
ptl.x = 100;
ptl.y = 100;
GpiMove(hps, &ptl);
GpiCharString(hps, 28L, "MS OS/2 Presentation Manager");
 
Transforming Text from an Image Font
 
The following code fragment shows how to double the size of the character
box, set the character mode to 2, and then print a string of text:
 
GpiQueryCharBox(hps, &sizfxBox);
sizfxBox.cx = 2 * sizfxBox.cx;
sizfxBox.cy = 2 * sizfxBox.cy;
GpiSetCharBox(hps, &sizfxBox);
ptl.x = 100;
ptl.y = 100;
GpiMove(hps, &ptl);
GpiCharString(hps, 28L, "MS OS/2 Presentation Manager");
 
 
                                      ♦