home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbcs.zip / FONTS.C < prev    next >
C/C++ Source or Header  |  1996-01-19  |  24KB  |  699 lines

  1. #pragma    title("DBCS Driver  --  Version 1  --  (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:   1996-01-19                        */
  25. /*  Revised:   1996-01-19                        */
  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., 1996.        */
  60. /* Copyright ╕ 1996  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),    PAG_READ | PAG_WRITE | PAG_COMMIT);
  142.  
  143.                /* Get the font metrics for the number of fonts    */
  144.                /* for the face name provided            */
  145.  
  146. GpiQueryFonts(hPS, QF_PUBLIC, NULL, &cFonts,
  147.           sizeof(FONTMETRICS), pfm);
  148.  
  149. WinSendMsg(hwndFontNames, LM_DELETEALL,    0L, 0L);
  150.  
  151.                /* Loop through the font    metrics    returned to    */
  152.                /* and place each of the    different font names    */
  153.                /* within the fonts combo box            */
  154.  
  155. for ( i    = 0, fSelected = fFonts    = FALSE; i < (INT)cFonts; i++ )
  156.    if (    pfm[i].lMatch <    0 )
  157.        {
  158.        if ( pfm[i].fsType & FM_TYPE_FACETRUNC )
  159.        WinQueryAtomName(WinQuerySystemAtomTable( ),    (ULONG)pfm[i].FaceNameAtom, pszFacename    = szFacename, 128UL);
  160.        else
  161.        pszFacename = pfm[i].szFacename;
  162.        if ( (INT)LONGFROMMR(WinSendMsg(hwndFontNames, LM_SEARCHSTRING,
  163.                        MPFROM2SHORT(LSS_CASESENSITIVE, LIT_FIRST),
  164.                        MPFROMP(pszFacename))) == LIT_NONE )
  165.        {
  166.        fFonts = TRUE;
  167.  
  168.                /* Place    the font within    the combo box and set    */
  169.                /* the item handle as the font match number    */
  170.  
  171.        WinSendMsg(hwndFontNames, LM_SETITEMHANDLE,
  172.               MPFROMSHORT(n = (INT)LONGFROMMR(WinSendMsg(hwndFontNames,    LM_INSERTITEM,
  173.                                  MPFROMSHORT(LIT_SORTASCENDING),
  174.                                  MPFROMP(pfm[i].szFacename)))),
  175.               MPFROMLONG(pfm[i].lMatch));
  176.  
  177.                /* Check    to see if the last font    used is    the    */
  178.                /* font placed in the combo box and if so,    */
  179.                /* select it                    */
  180.  
  181.        if (    !strcmp(fsel.szFacename, pfm[i].szFacename) )
  182.            {
  183.            WinSendMsg(hwndFontNames, LM_SELECTITEM,
  184.               MPFROMSHORT(n), MPFROMSHORT(TRUE));
  185.            fSelected = TRUE;
  186.            }
  187.        }
  188.        }
  189.                /* Check    to see if any fonts selected and if    */
  190.                /* none were, get the default font for the    */
  191.                /* printer                    */
  192. if ( !fFonts )
  193.     {
  194.     GpiQueryFontMetrics(hPS, sizeof(FONTMETRICS), pfm);
  195.  
  196.                /* Place    the font within    the combo box and set    */
  197.                /* the item handle as the font match number    */
  198.  
  199.     WinSendMsg(hwndFontNames, LM_SETITEMHANDLE,
  200.            MPFROMSHORT(n = (INT)LONGFROMMR(WinSendMsg(hwndFontNames, LM_INSERTITEM,
  201.                               MPFROMSHORT(LIT_SORTASCENDING), MPFROMP(pfm[0].szFacename)))),
  202.            MPFROMLONG(pfm[0].lMatch));
  203.  
  204.     WinSendMsg(hwndFontNames, LM_SELECTITEM, MPFROMSHORT(n), MPFROMSHORT(TRUE));
  205.     fSelected =    TRUE;
  206.     cFonts = 1L;
  207.     }
  208.  
  209. if ( !fSelected    )
  210.     WinSendMsg(hwndFontNames, LM_SELECTITEM,
  211.            MPFROMSHORT(0), MPFROMSHORT(TRUE));
  212.  
  213. GpiAssociate(hPS, (HDC)NULL);
  214. GpiDestroyPS(hPS);
  215. DevCloseDC(hdcPrinter);
  216.  
  217. return(0L);
  218. }
  219. #pragma    subtitle("   File Print -  File Print Dialogue Procedure")
  220. #pragma    page( )
  221.  
  222. /* --- SetFontSize ------------------------------------- [ Public ] ---    */
  223. /*                                    */
  224. /*     This function is    used to    set the    font sizes within the font    */
  225. /*     sizes combo box for a font selected.                */
  226. /*                                    */
  227. /*     Upon Entry:                            */
  228. /*                                    */
  229. /*     HWND hwndFont;      = Font Combo Box Handle            */
  230. /*     HWND hwndFontSize; = Font Size Combo Box    Handle            */
  231. /*                                    */
  232. /*     Upon Exit:                            */
  233. /*                                    */
  234. /*     Nothing                                */
  235. /*                                    */
  236. /* --------------------------------------------------------------------    */
  237.  
  238. VOID SetFontSize(HWND hwndFont,    HWND hwndFontSize)
  239.  
  240. {
  241. CHAR     szStrBuf[CCHMAXPATH];       /* String Buffer            */
  242. LONG     lMatch;           /* Font Match            */
  243. register INT i,    k, n;           /* Indices                */
  244.  
  245.                /* Check    to see that a valid entry has been    */
  246.                /* selected within the combo box            */
  247.  
  248. if ( (i    = (INT)LONGFROMMR(WinSendMsg(hwndFont,
  249.             LM_QUERYSELECTION,
  250.             0L,    0L))) != LIT_NONE )
  251.    {
  252.    WinSetPointer(HWND_DESKTOP, hptrWait);
  253.  
  254.                /* Get the font match number for    the font    */
  255.                /* selected from    the selected item handle    */
  256.  
  257.    lMatch = (LONG)LONGFROMMR(WinSendMsg(hwndFont,
  258.                            LM_QUERYITEMHANDLE,
  259.                            MPFROMSHORT(i), 0L));
  260.  
  261.                /* Clear    the entries within the font sizes box    */
  262.  
  263.    WinSendMsg(hwndFontSize, LM_DELETEALL, 0L, 0L);
  264.  
  265.                /* Find the font    metric for the selected    font    */
  266.  
  267.    for ( i = 0;    i < (INT)cFonts; i++ )
  268.        if ( pfm[i].lMatch == lMatch )
  269.        break;
  270.                /* Check    to see if the font is an outline font    */
  271.                /* and if the case, place the outline font sizes    */
  272.                /* within the font sizes    combo box        */
  273.  
  274.    if (    pfm[i].fsDefn &    FM_DEFN_OUTLINE    )
  275.        for ( n = 0; n <    12; n++    )
  276.        WinSendMsg(hwndFontSize,
  277.               LM_INSERTITEM,
  278.               MPFROMSHORT(LIT_END),
  279.               MPFROMP(afsiz[n].pszSize));
  280.    else
  281.  
  282.                /* Device font selected,    locate all the fonts    */
  283.                /* that match the selected font within the    */
  284.                /* font metrics array for each of the different    */
  285.                /* sizes    supported by the printer and place each    */
  286.                /* size within the combo    box            */
  287.  
  288.        for ( n = k = 0;    n < (INT)cFonts; n++ )
  289.        if (    (pfm[n].lMatch < 0) &&
  290.         !strcmp(pfm[i].szFacename,
  291.             pfm[n].szFacename) &&
  292.         !(pfm[n].fsDefn    & FM_DEFN_OUTLINE) )
  293.            {
  294.  
  295.                /* Check    to see if the device font is the HP    */
  296.                /* line printer font size which is a half size    */
  297.  
  298.            if ( pfm[n].sNominalPointSize ==    85 )
  299.            memcpy(szStrBuf, "8.5", 4);
  300.            else
  301.            _ltoa(pfm[n].sNominalPointSize / 10,
  302.              szStrBuf, 10);
  303.  
  304.                /* Place    the font size within the combo box    */
  305.  
  306.            if ( (INT)LONGFROMMR(WinSendMsg(hwndFontSize,
  307.                   LM_SEARCHSTRING,
  308.                   MPFROM2SHORT(LSS_CASESENSITIVE, LIT_FIRST),
  309.                   MPFROMP(szStrBuf))) ==
  310.                   LIT_NONE )
  311.            {
  312.            WinSendMsg(hwndFontSize,
  313.                   LM_INSERTITEM,
  314.                   MPFROMSHORT(LIT_END),
  315.                   MPFROMP(szStrBuf));
  316.            WinSendMsg(hwndFontSize,
  317.                   LM_SETITEMHANDLE,
  318.                   MPFROMSHORT(k++),
  319.                   MPFROMLONG(pfm[n].lMatch));
  320.            }
  321.            }
  322.                /* Search the list of font sizes    for the    font    */
  323.                /* size last selected and select    the size    */
  324.  
  325.    if (    (i = (INT)LONGFROMMR(WinSendMsg(hwndFontSize,
  326.                   LM_SEARCHSTRING,
  327.                   MPFROM2SHORT(LSS_CASESENSITIVE, LIT_FIRST),
  328.                   MPFROMP(_ltoa(fsel.lPointSize, szStrBuf, 10))))) ==
  329.                   LIT_NONE )
  330.        i = 0;
  331.  
  332.    WinSendMsg(hwndFontSize, LM_SELECTITEM,
  333.           MPFROMSHORT(i),
  334.           MPFROMSHORT(TRUE));
  335.    WinSetPointer(HWND_DESKTOP, hptrArrow);
  336.    }
  337. }
  338. #pragma    subtitle("   Fonts -  Font Selection Query Procedure")
  339. #pragma    page( )
  340.  
  341. /* --- fQuerySelectedFont ------------------------------ [ Public ] ---    */
  342. /*                                    */
  343. /*     This function is    used to    retrieve the necessary information for    */
  344. /*     the font    selected within    the font combo boxes.            */
  345. /*                                    */
  346. /*     Upon Entry:                            */
  347. /*                                    */
  348. /*     HWND    hwndFont;     =    Font Combo Box Handle            */
  349. /*     HWND    hwndFontSize; =    Font Size Combo    Box Handle        */
  350. /*     PFONTSEL    pfsel;          =    Font Selected Pointer            */
  351. /*                                    */
  352. /*     Upon Exit:                            */
  353. /*                                    */
  354. /*     fQuerySelectedFont =  TRUE : Font Selected            */
  355. /*              = FALSE : No font Selected            */
  356. /*                                    */
  357. /* --------------------------------------------------------------------    */
  358.  
  359. BOOL fQuerySelectedFont(HWND hwndFont, HWND hwndFontSize, PFONTSEL pfsel)
  360.  
  361. {
  362. register INT i,    n;           /* Index                */
  363.  
  364.                /* Get the font selected                */
  365.  
  366. if ( (i    = (INT)LONGFROMMR(WinSendMsg(hwndFont, LM_QUERYSELECTION, 0L, 0L))) != LIT_NONE    )
  367.    {
  368.                /* Get the font match number of the font        */
  369.                /* selected                    */
  370.  
  371.    pfsel->lMatch = (LONG)LONGFROMMR(WinSendMsg(hwndFont, LM_QUERYITEMHANDLE, MPFROMSHORT(i), 0L));
  372.  
  373.                /* Locate the font metrics for the font selected    */
  374.  
  375.    for ( i = 0;    i < (INT)cFonts; i++ )
  376.        if ( pfm[i].lMatch == pfsel->lMatch )
  377.        break;
  378.                /* Check    to see if the font selected is a    */
  379.                /* scalable font                    */
  380.  
  381.    if (    pfm[i].fsDefn &    FM_DEFN_OUTLINE    )
  382.        {
  383.                /* Scalable font, get the index of the font size    */
  384.                /* selected                    */
  385.  
  386.        n = (INT)LONGFROMMR(WinSendMsg(hwndFontSize,
  387.                       LM_QUERYSELECTION,
  388.                       0L, 0L));
  389.        pfsel->fFixed = FALSE;
  390.  
  391.                /* Save the point size and facename        */
  392.  
  393.        pfsel->lPointSize = afsiz[n].lPointSize;
  394.        pfsel->lNominalPointSize    = afsiz[n].lPointSize *    10;
  395.        strcpy(pfsel->szFacename, pfm[i].szFacename);
  396.        }
  397.    else
  398.        {
  399.                /* Get the font match number for    the size    */
  400.                /* selected                    */
  401.  
  402.        pfsel->lMatch = (LONG)LONGFROMMR(WinSendMsg(hwndFontSize,
  403.                            LM_QUERYITEMHANDLE,
  404.                            MPFROMSHORT(WinSendMsg(hwndFontSize,
  405.                                       LM_QUERYSELECTION,
  406.                                       0L, 0L)),
  407.                            0L));
  408.        pfsel->fFixed = TRUE;
  409.  
  410.                /* Locate the font metrics for the font selected    */
  411.  
  412.        for ( i = 0; i <    (INT)cFonts; i++ )
  413.        if (    pfm[i].lMatch == pfsel->lMatch )
  414.            break;
  415.                /* Save the point size and facename        */
  416.  
  417.        pfsel->lNominalPointSize    = pfm[i].sNominalPointSize;
  418.        strcpy(pfsel->szFacename, pfm[i].szFacename);
  419.        }
  420.    return(TRUE);
  421.    }
  422. else
  423.    return(FALSE);
  424. }
  425. #pragma    subtitle("   Client Window - Client Window Procedure")
  426. #pragma    page( )
  427.  
  428. /* --- lSelectFont ------------------------------------- [ Public ] ---    */
  429. /*                                    */
  430. /*     This function is    used select the    requested font.     An image font    */
  431. /*     is first    searched for and if one    is not found that matches the    */
  432. /*     the font    face and size, a scalable font is then searched    for    */
  433. /*     and selected.                            */
  434. /*                                    */
  435. /*     Upon Entry:                            */
  436. /*                                    */
  437. /*     HPS hPS;               = Presentation Space Handle        */
  438. /*     PSZ pszFacename;           = Font Facename                */
  439. /*     LONG lNominalPointSize; = Nominal Font Size (Decipoints)        */
  440. /*                                    */
  441. /*     Upon Exit:                            */
  442. /*                                    */
  443. /*     lSelectFont = Logical Font ID                    */
  444. /*                                    */
  445. /* --------------------------------------------------------------------    */
  446.  
  447. LONG lSelectFont(HPS hPS, HDC hDC, PSZ pszFacename, LONG lNominalPointSize,
  448.          ULONG fl, PBOOL pfScalable, PSIZEF psizfxBox)
  449.  
  450. {
  451. LONG         cFont;           /* Fonts Count            */
  452. LONG         lFontsTotal = 0L;       /* Fonts Total Count            */
  453. LONG         lXDeviceRes;       /* x    Device Resolution        */
  454. LONG         lYDeviceRes;       /* y    Device Resolution        */
  455. PFONTMETRICS pfmSelect;           /* Font Metrics Pointer        */
  456. FATTRS         fat;           /* Font Attributes            */
  457. register INT i;               /* Loop Counter            */
  458.  
  459.                /* Get the height of the    screen in pels        */
  460.  
  461. DevQueryCaps(hDC, CAPS_HORIZONTAL_FONT_RES, 1L,    &lXDeviceRes);
  462. DevQueryCaps(hDC, CAPS_VERTICAL_FONT_RES,   1L,    &lYDeviceRes);
  463.  
  464.                /* Get the number of fonts for the face name    */
  465.                /* provided                    */
  466.  
  467. if ( (cFont = GpiQueryFonts(hPS, QF_PUBLIC, pszFacename, &lFontsTotal,
  468.                sizeof(FONTMETRICS),    (PFONTMETRICS)NULL)) !=    0L )
  469.    {
  470.                /* Allocate space for the font metrics for the    */
  471.                /* different font sizes and devices of the font    */
  472.  
  473.    DosAllocMem((PPVOID)(PVOID)&pfmSelect, (ULONG)(sizeof(FONTMETRICS) *    cFont),
  474.            PAG_READ    | PAG_WRITE | PAG_COMMIT);
  475.  
  476.                /* Make a pointer for the memory    allocated for    */
  477.                /* the font metrics and get the font metrics for    */
  478.                /* the number of    fonts for the face name        */
  479.                /* provided                    */
  480.  
  481.    GpiQueryFonts(hPS, QF_PUBLIC, pszFacename, &cFont,
  482.          sizeof(FONTMETRICS), pfmSelect);
  483.  
  484.                /* Loop through the font    metrics    returned to    */
  485.                /* locate the desired font by matching the x and    */
  486.                /* y device resolution of the font and the point    */
  487.                /* size                        */
  488.  
  489.    for ( i = 0;    i < (INT)cFont;    i++ )
  490.        if ( (pfmSelect[i].sXDeviceRes == (SHORT)lXDeviceRes) &&
  491.         (pfmSelect[i].sYDeviceRes == (SHORT)lYDeviceRes) &&
  492.         ((LONG)pfmSelect[i].sNominalPointSize == lNominalPointSize)    )
  493.        {
  494.                /* Font found, get the match value to allow the    */
  495.                /* exact    font to    be selected by the calling    */
  496.                /* application                    */
  497.  
  498.        memset(&fat,    0, sizeof(FATTRS));
  499.        fat.usRecordLength  = (USHORT)sizeof(FATTRS);
  500.        strcpy(fat.szFacename, pszFacename);
  501.        fat.lMatch           = pfmSelect[i].lMatch;
  502.        fat.fsSelection     = (USHORT)fl;
  503.  
  504.        DosFreeMem((PVOID)pfmSelect);
  505.        for ( i = 1;    i < 255; i++ )
  506.            if ( !afLCID[i] )
  507.            {
  508.            *pfScalable = FALSE;
  509.            afLCID[i] = TRUE;
  510.            GpiCreateLogFont(hPS, (PSTR8)NULL, (LONG)i, &fat);
  511.            GpiSetCharSet(hPS, (LONG)i);
  512.            return((LONG)i);
  513.            }
  514.        return(0);
  515.        }
  516.                /* Loop through the font    metrics    returned to    */
  517.                /* locate the desired font by matching the x and    */
  518.                /* y device resolution of the font and the point    */
  519.                /* size                        */
  520.  
  521.    for ( i = 0;    i < (INT)cFont;    i++ )
  522.        if ( (pfmSelect[i].sXDeviceRes == 1000) && (pfmSelect[i].sYDeviceRes == 1000) )
  523.        {
  524.                /* Font found, get the match value to allow the    */
  525.                /* exact    font to    be selected by the calling    */
  526.                /* application                    */
  527.  
  528.        memset(&fat,    0, sizeof(FATTRS));
  529.        fat.usRecordLength  = (USHORT)sizeof(FATTRS);
  530.        strcpy(fat.szFacename, pszFacename);
  531.        fat.lMatch           = pfmSelect[i].lMatch;
  532.        fat.fsFontUse       = (USHORT)(FATTR_FONTUSE_OUTLINE    | FATTR_FONTUSE_TRANSFORMABLE);
  533.        fat.fsSelection     = (USHORT)fl;
  534.  
  535.        DosFreeMem((PVOID)pfmSelect);
  536.  
  537.        for ( i = 1;    i < 255; i++ )
  538.            if ( !afLCID[i] )
  539.            {
  540.            *pfScalable = TRUE;
  541.            afLCID[i] = TRUE;
  542.            GpiCreateLogFont(hPS, (PSTR8)NULL, (LONG)i, &fat);
  543.            GpiSetCharSet(hPS, (LONG)i);
  544.  
  545.            psizfxBox->cx = psizfxBox->cy = MAKEFIXED(lNominalPointSize * 2, 0);
  546.  
  547.            GpiSetCharBox(hPS, psizfxBox);
  548.            return((LONG)i);
  549.            }
  550.        return(0);
  551.        }
  552.                /* Release the memory allocated for the font    */
  553.                /* metrics array                    */
  554.  
  555.    DosFreeMem((PVOID)pfmSelect);
  556.    }
  557.                /* Return the match value to the    calling        */
  558.                /* application                    */
  559. return(0);
  560. }
  561. #pragma    subtitle("   Client Window - Client Window Procedure")
  562. #pragma    page( )
  563.  
  564. /* --- DeSelectFont ------------------------------------ [ Public ] ---    */
  565. /*                                    */
  566. /*     This function is    used deselect the specified font.        */
  567. /*                                    */
  568. /*     Upon Entry:                            */
  569. /*                                    */
  570. /*     HPS hPS;      = Presentation Space Handle                */
  571. /*     LONG lcid; = Logical Font ID                    */
  572. /*                                    */
  573. /*     Upon Exit:                            */
  574. /*                                    */
  575. /*     Nothing                                */
  576. /*                                    */
  577. /* --------------------------------------------------------------------    */
  578.  
  579. VOID DeSelectFont(HPS hPS, LONG    lcid)
  580.  
  581. {
  582. if ( lcid )
  583.    {
  584.                /* Reset    the character set back to the default    */
  585.    GpiSetCharSet(hPS, 0L);
  586.    GpiDeleteSetId(hPS, lcid);
  587.  
  588.                /* Clear    the usage flag within the logical ID    */
  589.                /* table                        */
  590.    afLCID[lcid]    = FALSE;
  591.    }
  592. }
  593. #pragma    subtitle("   Client Window - Client Window Procedure")
  594. #pragma    page( )
  595.  
  596. /* --- BuildFontCache ---------------------------------- [ Public ] ---    */
  597. /*                                    */
  598. /*     This function is    used build the font cache for the selected    */
  599. /*     font.                                */
  600. /*                                    */
  601. /*     Upon Entry:                            */
  602. /*                                    */
  603. /*     HPS  hpsTarget;           = Target    Presentation Space Handle    */
  604. /*     HPS  hpsPrinter;           = Printer Presentation Space Handle    */
  605. /*     HDC  hdcPrinter;           = Print Device Context Handle        */
  606. /*     PSZ  pszFacename;       = Font Facename                */
  607. /*     LONG lNominalPointSize; = Font Nominal Size            */
  608. /*                                    */
  609. /*     Upon Exit:                            */
  610. /*                                    */
  611. /*     Nothing                                */
  612. /*                                    */
  613. /* --------------------------------------------------------------------    */
  614.  
  615. VOID BuildFontCache(HPS    hpsTarget, HPS hpsPrinter, HDC hdcPrinter,
  616.             PSZ    pszFacename, LONG lNominalPointSize,
  617.             PFONTCACHE pfcache)
  618.  
  619. {
  620. HDC  hDC;               /* Display Device Context Handle    */
  621. LONG lcid;               /* Logical Font ID            */
  622.  
  623. lcid = lSelectFont(hpsPrinter, hdcPrinter, pszFacename,    lNominalPointSize,
  624.            0UL,    &pfcache->lfontNormal.fScalable,
  625.            &pfcache->lfontNormal.sizfxBox);
  626. GpiQueryWidthTable(hpsPrinter, 0L, 255L, pfcache->lfontNormal.alWidths);
  627.  
  628. if ( hpsTarget )
  629.    {
  630.    DeSelectFont(hpsPrinter, lcid);
  631.  
  632.    pfcache->lfontNormal.lcid = lSelectFont(hpsTarget, hDC = GpiQueryDevice(hpsTarget),
  633.                         pszFacename, lNominalPointSize, 0UL,
  634.                         &pfcache->lfontNormal.fScalable,
  635.                         &pfcache->lfontNormal.sizfxBox);
  636.    }
  637. else
  638.    pfcache->lfontNormal.lcid = lcid;
  639.  
  640. lcid = lSelectFont(hpsPrinter, hdcPrinter, pszFacename,    lNominalPointSize,
  641.            FATTR_SEL_BOLD, &pfcache->lfontBold.fScalable,
  642.            &pfcache->lfontBold.sizfxBox);
  643. GpiQueryWidthTable(hpsPrinter, 0L, 255L, pfcache->lfontBold.alWidths);
  644.  
  645. if ( hpsTarget )
  646.    {
  647.    DeSelectFont(hpsPrinter, lcid);
  648.  
  649.    pfcache->lfontBold.lcid = lSelectFont(hpsTarget, hDC,
  650.                      pszFacename, lNominalPointSize, FATTR_SEL_BOLD,
  651.                      &pfcache->lfontBold.fScalable,
  652.                      &pfcache->lfontBold.sizfxBox);
  653.    }
  654. else
  655.    pfcache->lfontBold.lcid = lcid;
  656.  
  657. lcid = lSelectFont(hpsPrinter, hdcPrinter, pszFacename,    lNominalPointSize,
  658.            FATTR_SEL_ITALIC, &pfcache->lfontItalic.fScalable,
  659.            &pfcache->lfontItalic.sizfxBox);
  660. GpiQueryWidthTable(hpsPrinter, 0L, 255L, pfcache->lfontItalic.alWidths);
  661.  
  662. if ( hpsTarget )
  663.    {
  664.    DeSelectFont(hpsPrinter, lcid);
  665.  
  666.    pfcache->lfontItalic.lcid = lSelectFont(hpsTarget, hDC,
  667.                        pszFacename,    lNominalPointSize, FATTR_SEL_ITALIC,
  668.                        &pfcache->lfontItalic.fScalable,
  669.                        &pfcache->lfontItalic.sizfxBox);
  670.    }
  671. else
  672.    pfcache->lfontItalic.lcid = lcid;
  673. }
  674. #pragma    subtitle("   Client Window - Client Window Procedure")
  675. #pragma    page( )
  676.  
  677. /* --- DeleteFontCache --------------------------------- [ Public ] ---    */
  678. /*                                    */
  679. /*     This function is    used delete the    font current cache.        */
  680. /*                                    */
  681. /*     Upon Entry:                            */
  682. /*                                    */
  683. /*     HPS  hpsTarget;    = Target Presentation Space Handle        */
  684. /*     HPS  hpsPrinter;    = Printer Presentation Space Handle        */
  685. /*                                    */
  686. /*     Upon Exit:                            */
  687. /*                                    */
  688. /*     Nothing                                */
  689. /*                                    */
  690. /* --------------------------------------------------------------------    */
  691.  
  692. VOID DeleteFontCache(HPS hpsTarget, PFONTCACHE pfcache)
  693.  
  694. {
  695. DeSelectFont(hpsTarget,    pfcache->lfontNormal.lcid);
  696. DeSelectFont(hpsTarget,    pfcache->lfontBold.lcid);
  697. DeSelectFont(hpsTarget,    pfcache->lfontItalic.lcid);
  698. }
  699.