home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / MLEVIEW.ZIP / EZFONTS.C next >
Text File  |  1991-04-04  |  4KB  |  133 lines

  1. /*--------------------------------------------
  2.    EZFONT.C -- Routines for Using Image Fonts
  3.   --------------------------------------------*/
  4.  
  5. /* Note:                                                             */
  6. /*    The EZFONT routines are a direct port of the EASYFONT routines */
  7. /*    from Charles Petzold's book "Programming the OS/2 Presentation */
  8. /*    Manager". They have been enhanced and updated for OS/2 1.2 and */
  9. /*    later to make them more generally useful. Thanks Charles.      */
  10. /*                                        W. David Ashley            */
  11.  
  12. #define INCL_GPI
  13. #include <os2.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include "ezfonts.h"
  17.  
  18. static LONG  alMatch[EZF_NUMFONTFACES][EZF_NUMSIZES] =
  19.                                 {0L, 0L, 0L, 0L, 0L, 0L,
  20.                                  0L, 0L, 0L, 0L, 0L, 0L,
  21.                                  0L, 0L, 0L, 0L, 0L, 0L,
  22.                                  0L, 0L, 0L, 0L, 0L, 0L,
  23.                                  0L, 0L, 0L, 0L, 0L, 0L};
  24. static SHORT sFontSize[EZF_NUMSIZES] = { 80, 100, 120, 140, 180, 240 };
  25. static CHAR  szFacename[EZF_NUMFONTFACES][FACESIZE]  =
  26.                                 {"Courier", "Helv", "System Monospaced",
  27.                                 "System Proportional", "Tms Rmn" };
  28.  
  29.  
  30. PCHAR EzfQueryFacename (SHORT sFaceIndex) {
  31.  
  32.    if (sFaceIndex >= EZF_NUMFONTFACES || sFaceIndex < 0)
  33.       return NULL;
  34.  
  35.    return szFacename[sFaceIndex];
  36.    }
  37.  
  38.  
  39. LONG EzfQueryMatchNum (SHORT sFaceIndex, SHORT sSizeIndex) {
  40.  
  41.    if (sSizeIndex >= EZF_NUMSIZES || sSizeIndex < 0 ||
  42.     sFaceIndex >= EZF_NUMFONTFACES || sFaceIndex < 0)
  43.       return 0;
  44.  
  45.    return (alMatch[sFaceIndex][sSizeIndex]);
  46.    }
  47.  
  48.  
  49. SHORT EzfQuerySize (SHORT sSizeIndex) {
  50.  
  51.    if (sSizeIndex >= EZF_NUMSIZES || sSizeIndex < 0)
  52.       return 0;
  53.  
  54.    return (sFontSize[sSizeIndex]);
  55.    }
  56.  
  57.  
  58. SHORT EzfQuerySizeIndex (SHORT sSize) {
  59.    SHORT sCntr;
  60.  
  61.    for (sCntr = 0; sCntr < EZF_NUMSIZES; sCntr++)
  62.       if (sSize == sFontSize[sCntr])
  63.          return sCntr;
  64.  
  65.    return (0);
  66.    }
  67.  
  68.  
  69. BOOL EzfQueryFonts (HPS hps) {
  70.    PFONTMETRICS pfm;
  71.    HDC          hdc;
  72.    LONG         lHorzRes, lVertRes, lRequestFonts, lNumberFonts;
  73.    SHORT        sIndex, sFace, sSize;
  74.    SEL          selTemp;
  75.  
  76.    hdc = GpiQueryDevice (hps);
  77.    DevQueryCaps (hdc, CAPS_HORIZONTAL_FONT_RES, 1L, &lHorzRes);
  78.    DevQueryCaps (hdc, CAPS_VERTICAL_FONT_RES,   1L, &lVertRes);
  79.  
  80.    for (sFace = 0;  sFace < EZF_NUMFONTFACES;  sFace++) {
  81.       lRequestFonts = 0;
  82.       lNumberFonts = GpiQueryFonts (hps, QF_PUBLIC, szFacename[sFace],
  83.                                     &lRequestFonts, 0L, NULL);
  84.       if (lNumberFonts == 0)
  85.          continue;
  86.  
  87.       if (lNumberFonts * sizeof (FONTMETRICS) >= 65535L)
  88.          return FALSE;
  89.  
  90.       DosAllocSeg ((SHORT) (lNumberFonts * sizeof (FONTMETRICS)),
  91.                    &selTemp, SEG_NONSHARED);
  92.       pfm = MAKEP (selTemp, 0);
  93.  
  94.       if (pfm == NULL)
  95.          return FALSE;
  96.  
  97.       GpiQueryFonts (hps, QF_PUBLIC, szFacename[sFace],
  98.                      &lNumberFonts, (LONG) sizeof (FONTMETRICS), pfm);
  99.  
  100.       for (sIndex = 0;  sIndex < (SHORT) lNumberFonts;  sIndex++)
  101.          if (pfm[sIndex].sXDeviceRes == (SHORT) lHorzRes &&
  102.           pfm[sIndex].sYDeviceRes == (SHORT) lVertRes &&
  103.           (pfm[sIndex].fsDefn & 1) == 0) {
  104.             for (sSize = 0;  sSize < EZF_NUMSIZES;  sSize++)
  105.                if (pfm[sIndex].sNominalPointSize == sFontSize[sSize])
  106.                   break;
  107.  
  108.             if (sSize != EZF_NUMSIZES)
  109.                alMatch[sFace][sSize] = pfm[sIndex].lMatch;
  110.             }
  111.  
  112.       DosFreeSeg (selTemp);
  113.       }
  114.    return TRUE;
  115.    }
  116.  
  117. LONG EzfCreateLogFont (HPS hps, LONG lcid, USHORT idFace, USHORT idSize,
  118.                        USHORT fsSelection) {
  119.    static FATTRS fat;
  120.  
  121.    if (idFace >= EZF_NUMFONTFACES || idSize >= EZF_NUMSIZES ||
  122.     alMatch[idFace][idSize] == 0)
  123.       return 0;
  124.  
  125.    fat.usRecordLength = sizeof fat;
  126.    fat.fsSelection    = fsSelection;
  127.    fat.lMatch         = alMatch[idFace][idSize];
  128.  
  129.    strcpy (fat.szFacename, szFacename[idFace]);
  130.  
  131.    return GpiCreateLogFont (hps, NULL, lcid, &fat);
  132.    }
  133.