Annotation of pmsdk/samples/petzold/chap14/easyfont.c, revision 1.1

1.1     ! root        1: /*----------------------------------------------
        !             2:    EASYFONT.C -- Routines for Using Image Fonts
        !             3:   ----------------------------------------------*/
        !             4: 
        !             5: #define INCL_GPI
        !             6: #include <os2.h>
        !             7: #include <stdlib.h>
        !             8: #include <string.h>
        !             9: #include "easyfont.h"
        !            10: 
        !            11: static SHORT sFontSize[6]   = { 80, 100, 120, 140, 180, 240 } ;
        !            12: static CHAR  *szFacename[4] = { "System Proportional",
        !            13:                                 "Courier", "Helv", "Tms Rmn" } ;
        !            14: static LONG  alMatch[4][6] ;
        !            15: 
        !            16: BOOL EzfQueryFonts (HPS hps)
        !            17:      {
        !            18:      FONTMETRICS *pfm ;
        !            19:      HDC         hdc ;
        !            20:      LONG        lHorzRes, lVertRes, lRequestFonts, lNumberFonts ;
        !            21:      SHORT       sIndex, sFace, sSize ;
        !            22: 
        !            23:      hdc = GpiQueryDevice (hps) ;
        !            24:      DevQueryCaps (hdc, CAPS_HORIZONTAL_FONT_RES, 1L, &lHorzRes) ;
        !            25:      DevQueryCaps (hdc, CAPS_VERTICAL_FONT_RES,   1L, &lVertRes) ;
        !            26: 
        !            27:      for (sFace = 0 ; sFace < 4 ; sFace++)
        !            28:           {
        !            29:           lRequestFonts = 0 ;
        !            30:           lNumberFonts = GpiQueryFonts (hps, QF_PUBLIC, szFacename[sFace],
        !            31:                                         &lRequestFonts, 0L, NULL) ;
        !            32:           if (lNumberFonts == 0)
        !            33:                continue ;
        !            34: 
        !            35:           if (lNumberFonts * sizeof (FONTMETRICS) >= 65536L)
        !            36:                return FALSE ;
        !            37: 
        !            38:           pfm = malloc ((SHORT) lNumberFonts * sizeof (FONTMETRICS)) ;
        !            39: 
        !            40:           if (pfm == NULL)
        !            41:                return FALSE ;
        !            42: 
        !            43:           GpiQueryFonts (hps, QF_PUBLIC, szFacename[sFace],
        !            44:                          &lNumberFonts, (LONG) sizeof (FONTMETRICS), pfm) ;
        !            45: 
        !            46:           for (sIndex = 0 ; sIndex < (SHORT) lNumberFonts ; sIndex++)
        !            47:                if (pfm[sIndex].sXDeviceRes == (SHORT) lHorzRes &&
        !            48:                    pfm[sIndex].sYDeviceRes == (SHORT) lVertRes &&
        !            49:                   (pfm[sIndex].fsDefn & 1) == 0)
        !            50:                     {
        !            51:                     for (sSize = 0 ; sSize < 6 ; sSize++)
        !            52:                          if (pfm[sIndex].sNominalPointSize == sFontSize[sSize])
        !            53:                               break ;
        !            54: 
        !            55:                     if (sSize != 6)
        !            56:                          alMatch[sFace][sSize] = pfm[sIndex].lMatch ;
        !            57:                     }
        !            58: 
        !            59:           free (pfm) ;
        !            60:           }
        !            61:      return TRUE ;
        !            62:      }
        !            63: 
        !            64: LONG EzfCreateLogFont (HPS hps, LONG lcid, USHORT idFace, USHORT idSize,
        !            65:                                            USHORT fsSelection)
        !            66:      {
        !            67:      static FATTRS fat ;
        !            68: 
        !            69:      if (idFace > 3 || idSize > 5 || alMatch[idFace][idSize] == 0)
        !            70:           return FALSE ;
        !            71: 
        !            72:      fat.usRecordLength = sizeof fat ;
        !            73:      fat.fsSelection    = fsSelection ;
        !            74:      fat.lMatch         = alMatch[idFace][idSize] ;
        !            75: 
        !            76:      strcpy (fat.szFacename, szFacename[idFace]) ;
        !            77: 
        !            78:      return GpiCreateLogFont (hps, NULL, lcid, &fat) ;
        !            79:      }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.