home *** CD-ROM | disk | FTP | other *** search
/ Inside Multimedia 1995 August / IMM0895.ISO01.iso / share / os2 / track061 / easyfont.c < prev    next >
Text File  |  1992-11-15  |  3KB  |  79 lines

  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] = { "Tracker Digital",
  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_PRIVATE|QF_PUBLIC, szFacename[sFace],
  31.                                         &lRequestFonts, 0L, NULL) ;
  32.           if (!lNumberFonts) continue;
  33.  
  34.           if (lNumberFonts * sizeof (FONTMETRICS) >= 65536L)
  35.                return FALSE ;
  36.  
  37.           pfm = malloc ((SHORT) lNumberFonts * sizeof (FONTMETRICS)) ;
  38.  
  39.           if (pfm == NULL)
  40.                return FALSE ;
  41.  
  42.           GpiQueryFonts (hps, QF_PRIVATE|QF_PUBLIC, szFacename[sFace],
  43.                          &lNumberFonts, (LONG) sizeof (FONTMETRICS), pfm) ;
  44.  
  45.           for (sIndex = 0 ; sIndex < (SHORT) lNumberFonts ; sIndex++)
  46.                if (pfm[sIndex].sXDeviceRes == (SHORT) lHorzRes &&
  47.                    pfm[sIndex].sYDeviceRes == (SHORT) lVertRes &&
  48.                   (pfm[sIndex].fsDefn & 1) == 0)
  49.                     {
  50.                     for (sSize = 0 ; sSize < 6 ; sSize++)
  51.                          if (pfm[sIndex].sNominalPointSize == sFontSize[sSize])
  52.                               break ;
  53.  
  54.                     if (sSize != 6)
  55.                          alMatch[sFace][sSize] = pfm[sIndex].lMatch ;
  56.                     }
  57.  
  58.           free (pfm) ;
  59.           }
  60.      return TRUE ;
  61.      }
  62.  
  63. LONG EzfCreateLogFont (HPS hps, LONG lcid, USHORT idFace, USHORT idSize,
  64.                                            USHORT fsSelection)
  65.      {
  66.      static FATTRS fat ;
  67.  
  68.      if (idFace > 3 || idSize > 5 || alMatch[idFace][idSize] == 0)
  69.           return FALSE ;
  70.  
  71.      fat.usRecordLength = sizeof fat ;
  72.      fat.fsSelection    = fsSelection ;
  73.      fat.lMatch         = alMatch[idFace][idSize] ;
  74.  
  75.      strcpy (fat.szFacename, szFacename[idFace]) ;
  76.  
  77.      return GpiCreateLogFont (hps, NULL, lcid, &fat) ;
  78.      }
  79.