home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / prnt3.zip / Fonts.C < prev    next >
C/C++ Source or Header  |  1995-03-14  |  24KB  |  708 lines

  1. #pragma    title("Printer Driver  --  Version 3  --  (Fonts.C)")
  2. #pragma    subtitle("   Application Window - Interface Definitions")
  3.  
  4. #define    INCL_DEV           /* Include OS/2 Device Interface    */
  5. #define    INCL_DOS           /* Include OS/2 DOS Kernal        */
  6. #define    INCL_DOSERRORS           /* Include OS/2 DOS Errors        */
  7. #define    INCL_GPI           /* Include OS/2 PM GPI Interface    */
  8. #define    INCL_WIN           /* Include OS/2 PM Windows Interface    */
  9.  
  10. #pragma    info(noext)
  11.  
  12. #include <os2.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15.  
  16. #include "appdefs.h"
  17. #include "prnsetup.h"
  18.  
  19. /* This    module contains    the font handling routines.            */
  20.  
  21. /* Filename:   Fonts.C                            */
  22.  
  23. /*  Version:   3                            */
  24. /*  Created:   1995-03-09                        */
  25. /*  Revised:   1995-03-11                        */
  26.  
  27. /* Routines:   LONG lSetFonts(HWND hwndFontNames);            */
  28. /*           VOID SetFontSize(HWND hwndFont, HWND hwndFontSize);    */
  29. /*           BOOL fQuerySelectedFont(HWND hwndFont,            */
  30. /*                       HWND hwndFontSize);        */
  31. /*           LONG lSelectFont(HPS hPS, HDC hDC, PSZ pszFacename,    */
  32. /*                LONG lNominalPointSize,    ULONG fl);    */
  33.  
  34.  
  35. /************************************************************************/
  36. /************************************************************************/
  37. /************************************************************************/
  38. /* DISCLAIMER OF WARRANTIES:                        */
  39. /* -------------------------                        */
  40. /* The following [enclosed] code is sample code    created    by IBM        */
  41. /* Corporation and Prominare Inc.  This    sample code is not part    of any    */
  42. /* standard IBM    product    and is provided    to you solely for the purpose    */
  43. /* of assisting    you in the development of your applications.  The code    */
  44. /* is provided "AS IS",    without    warranty of any    kind.  Neither IBM nor    */
  45. /* Prominare shall be liable for any damages arising out of your    */
  46. /* use of the sample code, even    if they    have been advised of the    */
  47. /* possibility of such damages.                        */
  48. /************************************************************************/
  49. /************************************************************************/
  50. /************************************************************************/
  51. /*               D I S C L A I M E R                */
  52. /* This    code is    provided on an as is basis with    no implied support.    */
  53. /* It should be    considered freeware that cannot    be rebundled as        */
  54. /* part    of a larger "*ware" offering without our consent.        */
  55. /************************************************************************/
  56. /************************************************************************/
  57. /************************************************************************/
  58.  
  59. /* Copyright ╕ International Business Machines Corp., 1995.        */
  60. /* Copyright ╕ 1995  Prominare Inc.  All Rights    Reserved.        */
  61.  
  62. /* --------------------------------------------------------------------    */
  63.  
  64. /************************************************************************/
  65. /*                                    */
  66. /*     Module Data Definitions                        */
  67. /*                                    */
  68. /************************************************************************/
  69.  
  70. PFONTMETRICS pfm;           /* Font Metrics Pointer        */
  71. LONG         cFonts;           /* Font Count            */
  72. FONTSEL         fsel;           /* Font Selection            */
  73.  
  74. FONTSIZE afsiz[    ] = { {     "6",  6 },
  75.               {     "8",  8 },
  76.               {    "10", 10 },
  77.               {    "12", 12 },
  78.               {    "14", 14 },
  79.               {    "16", 16 },
  80.               {    "18", 18 },
  81.               {    "20", 20 },
  82.               {    "24", 24 },
  83.               {    "32", 32 },
  84.               {    "40", 40 },
  85.               {    "48", 48 } };
  86.  
  87. BOOL   afLCID[255] = { TRUE };
  88.  
  89. #pragma    subtitle("   File Print - Font Selection Function")
  90. #pragma    page( )
  91.  
  92. /* --- SetFonts    ---------------------------------------    [ Private ] ---    */
  93. /*                                    */
  94. /*     This function is    enumerate the fonts for    the selected printer    */
  95. /*     and fill    the fonts combo    box with the font names.        */
  96. /*                                    */
  97. /*     Upon Entry:                            */
  98. /*                                    */
  99. /*     HWND hWnd;       = Dialogue Window Handle            */
  100. /*     HWND hwndFontNames; = Font Names    Combo Box Handle        */
  101. /*                                    */
  102. /*     Upon Exit:                            */
  103. /*                                    */
  104. /*     Nothing                                */
  105. /*                                    */
  106. /* --------------------------------------------------------------------    */
  107.  
  108. LONG lSetFonts(HWND hwndFontNames)
  109.  
  110. {
  111. BOOL  fFonts = FALSE;           /* Fonts Found Flag            */
  112. BOOL  fSelected;           /* Font Selected Flag        */
  113. CHAR  szFacename[128];           /* Font Facename Buffer        */
  114. HDC   hdcPrinter;           /* Device Context Handle        */
  115. HPS   hPS;               /* Presentation Space Handle        */
  116. LONG  lFonts = 0L;           /* Fonts Count            */
  117. PSZ   pszFacename;           /* Facename                */
  118. SIZEL sizlPage;               /* Size Holder            */
  119. register INT i,    n;           /* Loop Counter            */
  120.  
  121. sizlPage.cx = sizlPage.cy = 0L;
  122. if ( !(hdcPrinter = PrnOpenInfoDC(&prn,    "PM_Q_STD")) )
  123.    return(1L);
  124. else
  125.    if (    !(hPS =    GpiCreatePS(hAB, hdcPrinter, &sizlPage,    PU_TWIPS |
  126.                 GPIF_DEFAULT | GPIT_NORMAL | GPIA_ASSOC)) )
  127.        {
  128.        DevCloseDC(hdcPrinter);
  129.        return(2L);
  130.        }
  131.                /* Get the number of fonts for the face name    */
  132.                /* provided                    */
  133.  
  134. cFonts = GpiQueryFonts(hPS, QF_PUBLIC, NULL, &lFonts,
  135.                sizeof(FONTMETRICS), (PFONTMETRICS)NULL);
  136.  
  137.                /* Allocate space for the font metrics for the    */
  138.                /* different font sizes and devices of the font    */
  139. if ( pfm )
  140.    DosFreeMem((PVOID)pfm);
  141. DosAllocMem((PVOID)&pfm, (ULONG)(sizeof(FONTMETRICS) * cFonts),
  142.         PAG_READ | PAG_WRITE | PAG_COMMIT);
  143.  
  144.                /* Get the font metrics for the number of fonts    */
  145.                /* for the face name provided            */
  146.  
  147. GpiQueryFonts(hPS, QF_PUBLIC, NULL, &cFonts,
  148.           sizeof(FONTMETRICS), pfm);
  149.  
  150. WinSendMsg(hwndFontNames, LM_DELETEALL,    0L, 0L);
  151.  
  152.                /* Loop through the font    metrics    returned to    */
  153.                /* and place each of the    different font names    */
  154.                /* within the fonts combo box            */
  155.  
  156. for ( i    = 0, fSelected = fFonts    = FALSE; i < (INT)cFonts; i++ )
  157.    if (    pfm[i].lMatch <    0 )
  158.        {
  159.        if ( pfm[i].fsType & FM_TYPE_FACETRUNC )
  160.        WinQueryAtomName(WinQuerySystemAtomTable( ),    (ULONG)pfm[i].FaceNameAtom, pszFacename    = szFacename, 128UL);
  161.        else
  162.        pszFacename = pfm[i].szFacename;
  163.        if ( (INT)LONGFROMMR(WinSendMsg(hwndFontNames,
  164.                        LM_SEARCHSTRING,
  165.                        MPFROM2SHORT(LSS_CASESENSITIVE, LIT_FIRST),
  166.                        MPFROMP(pszFacename))) == LIT_NONE )
  167.        {
  168.        fFonts = TRUE;
  169.  
  170.                /* Place    the font within    the combo box and set    */
  171.                /* the item handle as the font match number    */
  172.  
  173.        WinSendMsg(hwndFontNames, LM_SETITEMHANDLE,
  174.               MPFROMSHORT(n = (INT)LONGFROMMR(WinSendMsg(hwndFontNames,
  175.                                  LM_INSERTITEM,
  176.                                  MPFROMSHORT(LIT_SORTASCENDING),
  177.                                  MPFROMP(pfm[i].szFacename)))),
  178.               MPFROMLONG(pfm[i].lMatch));
  179.  
  180.                /* Check    to see if the last font    used is    the    */
  181.                /* font placed in the combo box and if so,    */
  182.                /* select it                    */
  183.  
  184.        if (    !strcmp(fsel.szFacename, pfm[i].szFacename) )
  185.            {
  186.            WinSendMsg(hwndFontNames, LM_SELECTITEM,
  187.               MPFROMSHORT(n), MPFROMSHORT(TRUE));
  188.            fSelected = TRUE;
  189.            }
  190.        }
  191.        }
  192.                /* Check    to see if any fonts selected and if    */
  193.                /* none were, get the default font for the    */
  194.                /* printer                    */
  195. if ( !fFonts )
  196.     {
  197.     GpiQueryFontMetrics(hPS, sizeof(FONTMETRICS), pfm);
  198.  
  199.                /* Place    the font within    the combo box and set    */
  200.                /* the item handle as the font match number    */
  201.  
  202.     WinSendMsg(hwndFontNames, LM_SETITEMHANDLE,
  203.            MPFROMSHORT(n = (INT)LONGFROMMR(WinSendMsg(hwndFontNames,
  204.                               LM_INSERTITEM,
  205.                               MPFROMSHORT(LIT_SORTASCENDING),
  206.                               MPFROMP(pfm[0].szFacename)))),
  207.            MPFROMLONG(pfm[0].lMatch));
  208.  
  209.     WinSendMsg(hwndFontNames, LM_SELECTITEM,
  210.            MPFROMSHORT(n), MPFROMSHORT(TRUE));
  211.     fSelected =    TRUE;
  212.     cFonts = 1L;
  213.     }
  214.  
  215. if ( !fSelected    )
  216.     WinSendMsg(hwndFontNames, LM_SELECTITEM,
  217.            MPFROMSHORT(0), MPFROMSHORT(TRUE));
  218.  
  219. GpiAssociate(hPS, (HDC)NULL);
  220. GpiDestroyPS(hPS);
  221. DevCloseDC(hdcPrinter);
  222.  
  223. return(0L);
  224. }
  225. #pragma    subtitle("   File Print -  File Print Dialogue Procedure")
  226. #pragma    page( )
  227.  
  228. /* --- SetFontSize ------------------------------------- [ Public ] ---    */
  229. /*                                    */
  230. /*     This function is    used to    set the    font sizes within the font    */
  231. /*     sizes combo box for a font selected.                */
  232. /*                                    */
  233. /*     Upon Entry:                            */
  234. /*                                    */
  235. /*     HWND hwndFont;      = Font Combo Box Handle            */
  236. /*     HWND hwndFontSize; = Font Size Combo Box    Handle            */
  237. /*                                    */
  238. /*     Upon Exit:                            */
  239. /*                                    */
  240. /*     Nothing                                */
  241. /*                                    */
  242. /* --------------------------------------------------------------------    */
  243.  
  244. VOID SetFontSize(HWND hwndFont,    HWND hwndFontSize)
  245.  
  246. {
  247. CHAR     szStrBuf[CCHMAXPATH];       /* String Buffer            */
  248. LONG     lMatch;           /* Font Match            */
  249. register INT i,    k, n;           /* Indices                */
  250.  
  251.                /* Check    to see that a valid entry has been    */
  252.                /* selected within the combo box            */
  253.  
  254. if ( (i    = (INT)LONGFROMMR(WinSendMsg(hwndFont,
  255.             LM_QUERYSELECTION,
  256.             0L,    0L))) != LIT_NONE )
  257.    {
  258.    WinSetPointer(HWND_DESKTOP, hptrWait);
  259.  
  260.                /* Get the font match number for    the font    */
  261.                /* selected from    the selected item handle    */
  262.  
  263.    lMatch = (LONG)LONGFROMMR(WinSendMsg(hwndFont,
  264.                            LM_QUERYITEMHANDLE,
  265.                            MPFROMSHORT(i), 0L));
  266.  
  267.                /* Clear    the entries within the font sizes box    */
  268.  
  269.    WinSendMsg(hwndFontSize, LM_DELETEALL, 0L, 0L);
  270.  
  271.                /* Find the font    metric for the selected    font    */
  272.  
  273.    for ( i = 0;    i < (INT)cFonts; i++ )
  274.        if ( pfm[i].lMatch == lMatch )
  275.        break;
  276.                /* Check    to see if the font is an outline font    */
  277.                /* and if the case, place the outline font sizes    */
  278.                /* within the font sizes    combo box        */
  279.  
  280.    if (    pfm[i].fsDefn &    FM_DEFN_OUTLINE    )
  281.        for ( n = 0; n <    12; n++    )
  282.        WinSendMsg(hwndFontSize,
  283.               LM_INSERTITEM,
  284.               MPFROMSHORT(LIT_END),
  285.               MPFROMP(afsiz[n].pszSize));
  286.    else
  287.  
  288.                /* Device font selected,    locate all the fonts    */
  289.                /* that match the selected font within the    */
  290.                /* font metrics array for each of the different    */
  291.                /* sizes    supported by the printer and place each    */
  292.                /* size within the combo    box            */
  293.  
  294.        for ( n = k = 0;    n < (INT)cFonts; n++ )
  295.        if (    (pfm[n].lMatch < 0) &&
  296.         !strcmp(pfm[i].szFacename,
  297.             pfm[n].szFacename) &&
  298.         !(pfm[n].fsDefn    & FM_DEFN_OUTLINE) )
  299.            {
  300.  
  301.                /* Check    to see if the device font is the HP    */
  302.                /* line printer font size which is a half size    */
  303.  
  304.            if ( pfm[n].sNominalPointSize ==    85 )
  305.            memcpy(szStrBuf, "8.5", 4);
  306.            else
  307.            _ltoa(pfm[n].sNominalPointSize / 10,
  308.              szStrBuf, 10);
  309.  
  310.                /* Place    the font size within the combo box    */
  311.  
  312.            if ( (INT)LONGFROMMR(WinSendMsg(hwndFontSize,
  313.                   LM_SEARCHSTRING,
  314.                   MPFROM2SHORT(LSS_CASESENSITIVE, LIT_FIRST),
  315.                   MPFROMP(szStrBuf))) ==
  316.                   LIT_NONE )
  317.            {
  318.            WinSendMsg(hwndFontSize,
  319.                   LM_INSERTITEM,
  320.                   MPFROMSHORT(LIT_END),
  321.                   MPFROMP(szStrBuf));
  322.            WinSendMsg(hwndFontSize,
  323.                   LM_SETITEMHANDLE,
  324.                   MPFROMSHORT(k++),
  325.                   MPFROMLONG(pfm[n].lMatch));
  326.            }
  327.            }
  328.                /* Search the list of font sizes    for the    font    */
  329.                /* size last selected and select    the size    */
  330.  
  331.    if (    (i = (INT)LONGFROMMR(WinSendMsg(hwndFontSize,
  332.                   LM_SEARCHSTRING,
  333.                   MPFROM2SHORT(LSS_CASESENSITIVE, LIT_FIRST),
  334.                   MPFROMP(_ltoa(fsel.lPointSize, szStrBuf, 10))))) ==
  335.                   LIT_NONE )
  336.        i = 0;
  337.  
  338.    WinSendMsg(hwndFontSize, LM_SELECTITEM,
  339.           MPFROMSHORT(i),
  340.           MPFROMSHORT(TRUE));
  341.    WinSetPointer(HWND_DESKTOP, hptrArrow);
  342.    }
  343. }
  344. #pragma    subtitle("   Fonts -  Font Selection Query Procedure")
  345. #pragma    page( )
  346.  
  347. /* --- fQuerySelectedFont ------------------------------ [ Public ] ---    */
  348. /*                                    */
  349. /*     This function is    used to    retrieve the necessary information for    */
  350. /*     the font    selected within    the font combo boxes.            */
  351. /*                                    */
  352. /*     Upon Entry:                            */
  353. /*                                    */
  354. /*     HWND    hwndFont;     =    Font Combo Box Handle            */
  355. /*     HWND    hwndFontSize; =    Font Size Combo    Box Handle        */
  356. /*     PFONTSEL    pfsel;          =    Font Selected Pointer            */
  357. /*                                    */
  358. /*     Upon Exit:                            */
  359. /*                                    */
  360. /*     fQuerySelectedFont =  TRUE : Font Selected            */
  361. /*              = FALSE : No font Selected            */
  362. /*                                    */
  363. /* --------------------------------------------------------------------    */
  364.  
  365. BOOL fQuerySelectedFont(HWND hwndFont, HWND hwndFontSize, PFONTSEL pfsel)
  366.  
  367. {
  368. register INT i,    n;           /* Index                */
  369.  
  370.                /* Get the font selected                */
  371.  
  372. if ( (i    = (INT)LONGFROMMR(WinSendMsg(hwndFont, LM_QUERYSELECTION,
  373.                      0L, 0L))) != LIT_NONE )
  374.    {
  375.                /* Get the font match number of the font        */
  376.                /* selected                    */
  377.  
  378.    pfsel->lMatch = (LONG)LONGFROMMR(WinSendMsg(hwndFont, LM_QUERYITEMHANDLE,
  379.                            MPFROMSHORT(i), 0L));
  380.  
  381.                /* Locate the font metrics for the font selected    */
  382.  
  383.    for ( i = 0;    i < (INT)cFonts; i++ )
  384.        if ( pfm[i].lMatch == pfsel->lMatch )
  385.        break;
  386.                /* Check    to see if the font selected is a    */
  387.                /* scalable font                    */
  388.  
  389.    if (    pfm[i].fsDefn &    FM_DEFN_OUTLINE    )
  390.        {
  391.                /* Scalable font, get the index of the font size    */
  392.                /* selected                    */
  393.  
  394.        n = (INT)LONGFROMMR(WinSendMsg(hwndFontSize,
  395.                       LM_QUERYSELECTION,
  396.                       0L, 0L));
  397.        pfsel->fFixed = FALSE;
  398.  
  399.                /* Save the point size and facename        */
  400.  
  401.        pfsel->lPointSize = afsiz[n].lPointSize;
  402.        pfsel->lNominalPointSize    = afsiz[n].lPointSize *    10;
  403.        strcpy(pfsel->szFacename, pfm[i].szFacename);
  404.        }
  405.    else
  406.        {
  407.                /* Get the font match number for    the size    */
  408.                /* selected                    */
  409.  
  410.        pfsel->lMatch = (LONG)LONGFROMMR(WinSendMsg(hwndFontSize,
  411.                            LM_QUERYITEMHANDLE,
  412.                            MPFROMSHORT(WinSendMsg(hwndFontSize,
  413.                                       LM_QUERYSELECTION,
  414.                                       0L, 0L)),
  415.                            0L));
  416.        pfsel->fFixed = TRUE;
  417.  
  418.                /* Locate the font metrics for the font selected    */
  419.  
  420.        for ( i = 0; i <    (INT)cFonts; i++ )
  421.        if (    pfm[i].lMatch == pfsel->lMatch )
  422.            break;
  423.                /* Save the point size and facename        */
  424.  
  425.        pfsel->lNominalPointSize    = pfm[i].sNominalPointSize;
  426.        strcpy(pfsel->szFacename, pfm[i].szFacename);
  427.        }
  428.    return(TRUE);
  429.    }
  430. else
  431.    return(FALSE);
  432. }
  433. #pragma    subtitle("   Client Window - Client Window Procedure")
  434. #pragma    page( )
  435.  
  436. /* --- lSelectFont ------------------------------------- [ Public ] ---    */
  437. /*                                    */
  438. /*     This function is    used select the    requested font.     An image font    */
  439. /*     is first    searched for and if one    is not found that matches the    */
  440. /*     the font    face and size, a scalable font is then searched    for    */
  441. /*     and selected.                            */
  442. /*                                    */
  443. /*     Upon Entry:                            */
  444. /*                                    */
  445. /*     HPS hPS;               = Presentation Space Handle        */
  446. /*     PSZ pszFacename;           = Font Facename                */
  447. /*     LONG lNominalPointSize; = Nominal Font Size (Decipoints)        */
  448. /*                                    */
  449. /*     Upon Exit:                            */
  450. /*                                    */
  451. /*     lSelectFont = Logical Font ID                    */
  452. /*                                    */
  453. /* --------------------------------------------------------------------    */
  454.  
  455. LONG lSelectFont(HPS hPS, HDC hDC, PSZ pszFacename, LONG lNominalPointSize,
  456.          ULONG fl, PBOOL pfScalable, PSIZEF psizfxBox)
  457.  
  458. {
  459. LONG         cFont;           /* Fonts Count            */
  460. LONG         lFontsTotal = 0L;       /* Fonts Total Count            */
  461. LONG         lXDeviceRes;       /* x    Device Resolution        */
  462. LONG         lYDeviceRes;       /* y    Device Resolution        */
  463. PFONTMETRICS pfmSelect;           /* Font Metrics Pointer        */
  464. FATTRS         fat;           /* Font Attributes            */
  465. register INT i;               /* Loop Counter            */
  466.  
  467.                /* Get the height of the    screen in pels        */
  468.  
  469. DevQueryCaps(hDC, CAPS_HORIZONTAL_FONT_RES, 1L,    &lXDeviceRes);
  470. DevQueryCaps(hDC, CAPS_VERTICAL_FONT_RES,   1L,    &lYDeviceRes);
  471.  
  472.                /* Get the number of fonts for the face name    */
  473.                /* provided                    */
  474.  
  475. if ( (cFont = GpiQueryFonts(hPS, QF_PUBLIC, pszFacename, &lFontsTotal,
  476.                sizeof(FONTMETRICS),    (PFONTMETRICS)NULL)) !=    0L )
  477.    {
  478.                /* Allocate space for the font metrics for the    */
  479.                /* different font sizes and devices of the font    */
  480.  
  481.    DosAllocMem((PPVOID)(PVOID)&pfmSelect, (ULONG)(sizeof(FONTMETRICS) *    cFont),
  482.            PAG_READ    | PAG_WRITE | PAG_COMMIT);
  483.  
  484.                /* Make a pointer for the memory    allocated for    */
  485.                /* the font metrics and get the font metrics for    */
  486.                /* the number of    fonts for the face name        */
  487.                /* provided                    */
  488.  
  489.    GpiQueryFonts(hPS, QF_PUBLIC, pszFacename, &cFont,
  490.          sizeof(FONTMETRICS), pfmSelect);
  491.  
  492.                /* Loop through the font    metrics    returned to    */
  493.                /* locate the desired font by matching the x and    */
  494.                /* y device resolution of the font and the point    */
  495.                /* size                        */
  496.  
  497.    for ( i = 0;    i < (INT)cFont;    i++ )
  498.        if ( (pfmSelect[i].sXDeviceRes == (SHORT)lXDeviceRes) &&
  499.         (pfmSelect[i].sYDeviceRes == (SHORT)lYDeviceRes) &&
  500.         ((LONG)pfmSelect[i].sNominalPointSize == lNominalPointSize)    )
  501.        {
  502.                /* Font found, get the match value to allow the    */
  503.                /* exact    font to    be selected by the calling    */
  504.                /* application                    */
  505.  
  506.        memset(&fat,    0, sizeof(FATTRS));
  507.        fat.usRecordLength  = sizeof(FATTRS);
  508.        strcpy(fat.szFacename, pszFacename);
  509.        fat.lMatch           = pfmSelect[i].lMatch;
  510.        fat.fsSelection     = (USHORT)fl;
  511.  
  512.        DosFreeMem((PVOID)pfmSelect);
  513.        for ( i = 1;    i < 255; i++ )
  514.            if ( !afLCID[i] )
  515.            {
  516.            *pfScalable = FALSE;
  517.            afLCID[i] = TRUE;
  518.            GpiCreateLogFont(hPS, (PSTR8)NULL, (LONG)i, &fat);
  519.            GpiSetCharSet(hPS, (LONG)i);
  520.            return((LONG)i);
  521.            }
  522.        return(0);
  523.        }
  524.                /* Loop through the font    metrics    returned to    */
  525.                /* locate the desired font by matching the x and    */
  526.                /* y device resolution of the font and the point    */
  527.                /* size                        */
  528.  
  529.    for ( i = 0;    i < (INT)cFont;    i++ )
  530.        if ( (pfmSelect[i].sXDeviceRes == 1000) && (pfmSelect[i].sYDeviceRes == 1000) )
  531.        {
  532.                /* Font found, get the match value to allow the    */
  533.                /* exact    font to    be selected by the calling    */
  534.                /* application                    */
  535.  
  536.        memset(&fat,    0, sizeof(FATTRS));
  537.        fat.usRecordLength  = sizeof(FATTRS);
  538.        strcpy(fat.szFacename, pszFacename);
  539.        fat.lMatch           = pfmSelect[i].lMatch;
  540.        fat.usCodePage      = 850;
  541.        fat.fsFontUse       = FATTR_FONTUSE_OUTLINE | FATTR_FONTUSE_TRANSFORMABLE;
  542.        fat.fsSelection     = (USHORT)fl;
  543.  
  544.        DosFreeMem((PVOID)pfmSelect);
  545.  
  546.        for ( i = 1;    i < 255; i++ )
  547.            if ( !afLCID[i] )
  548.            {
  549.            *pfScalable = TRUE;
  550.            afLCID[i] = TRUE;
  551.            GpiCreateLogFont(hPS, (PSTR8)NULL, (LONG)i, &fat);
  552.            GpiSetCharSet(hPS, (LONG)i);
  553.  
  554.            psizfxBox->cx = psizfxBox->cy = MAKEFIXED(lNominalPointSize * 2, 0);
  555.  
  556.            GpiSetCharBox(hPS, psizfxBox);
  557.            return((LONG)i);
  558.            }
  559.        return(0);
  560.        }
  561.                /* Release the memory allocated for the font    */
  562.                /* metrics array                    */
  563.  
  564.    DosFreeMem((PVOID)pfmSelect);
  565.    }
  566.                /* Return the match value to the    calling        */
  567.                /* application                    */
  568. return(0);
  569. }
  570. #pragma    subtitle("   Client Window - Client Window Procedure")
  571. #pragma    page( )
  572.  
  573. /* --- DeSelectFont ------------------------------------ [ Public ] ---    */
  574. /*                                    */
  575. /*     This function is    used deselect the specified font.        */
  576. /*                                    */
  577. /*     Upon Entry:                            */
  578. /*                                    */
  579. /*     HPS hPS;      = Presentation Space Handle                */
  580. /*     LONG lcid; = Logical Font ID                    */
  581. /*                                    */
  582. /*     Upon Exit:                            */
  583. /*                                    */
  584. /*     Nothing                                */
  585. /*                                    */
  586. /* --------------------------------------------------------------------    */
  587.  
  588. VOID DeSelectFont(HPS hPS, LONG    lcid)
  589.  
  590. {
  591. if ( lcid )
  592.    {
  593.                /* Reset    the character set back to the default    */
  594.    GpiSetCharSet(hPS, 0L);
  595.    GpiDeleteSetId(hPS, lcid);
  596.  
  597.                /* Clear    the usage flag within the logical ID    */
  598.                /* table                        */
  599.    afLCID[lcid]    = FALSE;
  600.    }
  601. }
  602. #pragma    subtitle("   Client Window - Client Window Procedure")
  603. #pragma    page( )
  604.  
  605. /* --- BuildFontCache ---------------------------------- [ Public ] ---    */
  606. /*                                    */
  607. /*     This function is    used build the font cache for the selected    */
  608. /*     font.                                */
  609. /*                                    */
  610. /*     Upon Entry:                            */
  611. /*                                    */
  612. /*     HPS  hpsTarget;           = Target    Presentation Space Handle    */
  613. /*     HPS  hpsPrinter;           = Printer Presentation Space Handle    */
  614. /*     HDC  hdcPrinter;           = Print Device Context Handle        */
  615. /*     PSZ  pszFacename;       = Font Facename                */
  616. /*     LONG lNominalPointSize; = Font Nominal Size            */
  617. /*                                    */
  618. /*     Upon Exit:                            */
  619. /*                                    */
  620. /*     Nothing                                */
  621. /*                                    */
  622. /* --------------------------------------------------------------------    */
  623.  
  624. VOID BuildFontCache(HPS    hpsTarget, HPS hpsPrinter, HDC hdcPrinter,
  625.             PSZ    pszFacename, LONG lNominalPointSize,
  626.             PFONTCACHE pfcache)
  627.  
  628. {
  629. HDC  hDC;               /* Display Device Context Handle    */
  630. LONG lcid;               /* Logical Font ID            */
  631.  
  632. lcid = lSelectFont(hpsPrinter, hdcPrinter, pszFacename,    lNominalPointSize,
  633.            0UL,    &pfcache->lfontNormal.fScalable,
  634.            &pfcache->lfontNormal.sizfxBox);
  635. GpiQueryWidthTable(hpsPrinter, 0L, 255L, pfcache->lfontNormal.alWidths);
  636.  
  637. if ( hpsTarget )
  638.    {
  639.    DeSelectFont(hpsPrinter, lcid);
  640.  
  641.    pfcache->lfontNormal.lcid = lSelectFont(hpsTarget, hDC = GpiQueryDevice(hpsTarget),
  642.                         pszFacename, lNominalPointSize, 0UL,
  643.                         &pfcache->lfontNormal.fScalable,
  644.                         &pfcache->lfontNormal.sizfxBox);
  645.    }
  646. else
  647.    pfcache->lfontNormal.lcid = lcid;
  648.  
  649. lcid = lSelectFont(hpsPrinter, hdcPrinter, pszFacename,    lNominalPointSize,
  650.            FATTR_SEL_BOLD, &pfcache->lfontBold.fScalable,
  651.            &pfcache->lfontBold.sizfxBox);
  652. GpiQueryWidthTable(hpsPrinter, 0L, 255L, pfcache->lfontBold.alWidths);
  653.  
  654. if ( hpsTarget )
  655.    {
  656.    DeSelectFont(hpsPrinter, lcid);
  657.  
  658.    pfcache->lfontBold.lcid = lSelectFont(hpsTarget, hDC,
  659.                      pszFacename, lNominalPointSize, FATTR_SEL_BOLD,
  660.                      &pfcache->lfontBold.fScalable,
  661.                      &pfcache->lfontBold.sizfxBox);
  662.    }
  663. else
  664.    pfcache->lfontBold.lcid = lcid;
  665.  
  666. lcid = lSelectFont(hpsPrinter, hdcPrinter, pszFacename,    lNominalPointSize,
  667.            FATTR_SEL_ITALIC, &pfcache->lfontItalic.fScalable,
  668.            &pfcache->lfontItalic.sizfxBox);
  669. GpiQueryWidthTable(hpsPrinter, 0L, 255L, pfcache->lfontItalic.alWidths);
  670.  
  671. if ( hpsTarget )
  672.    {
  673.    DeSelectFont(hpsPrinter, lcid);
  674.  
  675.    pfcache->lfontItalic.lcid = lSelectFont(hpsTarget, hDC,
  676.                        pszFacename,    lNominalPointSize, FATTR_SEL_ITALIC,
  677.                        &pfcache->lfontItalic.fScalable,
  678.                        &pfcache->lfontItalic.sizfxBox);
  679.    }
  680. else
  681.    pfcache->lfontItalic.lcid = lcid;
  682. }
  683. #pragma    subtitle("   Client Window - Client Window Procedure")
  684. #pragma    page( )
  685.  
  686. /* --- DeleteFontCache --------------------------------- [ Public ] ---    */
  687. /*                                    */
  688. /*     This function is    used delete the    font current cache.        */
  689. /*                                    */
  690. /*     Upon Entry:                            */
  691. /*                                    */
  692. /*     HPS  hpsTarget;    = Target Presentation Space Handle        */
  693. /*     HPS  hpsPrinter;    = Printer Presentation Space Handle        */
  694. /*                                    */
  695. /*     Upon Exit:                            */
  696. /*                                    */
  697. /*     Nothing                                */
  698. /*                                    */
  699. /* --------------------------------------------------------------------    */
  700.  
  701. VOID DeleteFontCache(HPS hpsTarget, PFONTCACHE pfcache)
  702.  
  703. {
  704. DeSelectFont(hpsTarget,    pfcache->lfontNormal.lcid);
  705. DeSelectFont(hpsTarget,    pfcache->lfontBold.lcid);
  706. DeSelectFont(hpsTarget,    pfcache->lfontItalic.lcid);
  707. }
  708.