home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / FNTFIG.ZIP / VECTOR.C < prev    next >
C/C++ Source or Header  |  1989-10-11  |  5KB  |  149 lines

  1. /*------------------------------
  2.    VECTOR.C -- Vector Font Demo
  3.   ------------------------------*/
  4.  
  5. #define INCL_WIN
  6. #define INCL_GPI
  7. #include <os2.h>
  8. #include <string.h>
  9. #include "text.h"
  10. #include "easyfont.h"
  11. #define LCID_RASTFONT 1L
  12. #define LCID_VECTFONT 2L
  13.  
  14. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  15.  
  16. HAB  hab ;
  17.  
  18. int main (void)
  19.      {
  20.      static CHAR    szClientClass [] = "Vector" ;
  21.      static ULONG   flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
  22.                                    FCF_SIZEBORDER    | FCF_MINMAX  |
  23.                                    FCF_SHELLPOSITION | FCF_TASKLIST ;
  24.      HMQ            hmq ;
  25.      HWND           hwndFrame, hwndClient ;
  26.      QMSG           qmsg ;
  27.  
  28.      hab = WinInitialize (0) ;
  29.      hmq = WinCreateMsgQueue (hab, 0) ;
  30.  
  31.      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
  32.  
  33.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
  34.                                      &flFrameFlags, szClientClass, NULL,
  35.                                      0L, NULL, 0, &hwndClient) ;
  36.  
  37.      WinSendMsg (hwndFrame, WM_SETICON,
  38.                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
  39.                  NULL) ;
  40.  
  41.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  42.           WinDispatchMsg (hab, &qmsg) ;
  43.  
  44.      WinDestroyWindow (hwndFrame) ;
  45.      WinDestroyMsgQueue (hmq) ;
  46.      WinTerminate (hab) ;
  47.      return 0 ;
  48.      }
  49.  
  50. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  51.      {
  52.      static HPS    hps ;
  53.      static SHORT  sNumLines = sizeof aszText / sizeof aszText[0] ;
  54.      static SIZEL  sizlClient ;
  55.      FATTRS        fat ;
  56.      FONTMETRICS   fmRast, fmVect ;
  57.      HDC           hdc ;
  58.      POINTL        ptl ;
  59.      SHORT         i ;
  60.      SIZEF         sizfxBox ;
  61.      SIZEL         sizlBox, sizlPage ;
  62.  
  63.      switch (msg)
  64.           {
  65.           case WM_CREATE:
  66.                hdc = WinOpenWindowDC (hwnd) ;
  67.                sizlPage.cx = 0 ;
  68.                sizlPage.cy = 0 ;
  69.                hps = GpiCreatePS (hab, hdc, &sizlPage,
  70.                                   PU_PELS    | GPIF_DEFAULT |
  71.                                   GPIT_MICRO | GPIA_ASSOC) ;
  72.  
  73.                EzfQueryFonts (hps) ;
  74.                return 0 ;
  75.  
  76.           case WM_SIZE:
  77.                sizlClient.cx = SHORT1FROMMP (mp2) ;
  78.                sizlClient.cy = SHORT2FROMMP (mp2) ;
  79.                return 0 ;
  80.  
  81.           case WM_PAINT:
  82.                WinBeginPaint (hwnd, hps, NULL) ;
  83.                GpiErase (hps) ;
  84.  
  85.                          // Raster Font
  86.  
  87.                EzfCreateLogFont (hps, LCID_RASTFONT, FONTFACE_TIMES,
  88.                                  FONTSIZE_10, 0) ;
  89.  
  90.                GpiSetCharSet (hps, LCID_RASTFONT) ;
  91.                GpiQueryFontMetrics (hps, (LONG) sizeof fmRast, &fmRast) ;
  92.  
  93.                GpiSetCharSet (hps, LCID_DEFAULT) ;
  94.                GpiDeleteSetId (hps, LCID_RASTFONT) ;
  95.  
  96.                          // Vector Font
  97.  
  98.                fat.usRecordLength  = sizeof (fat) ;
  99.                fat.fsSelection     = 0 ;
  100.                fat.lMatch          = 0 ;
  101.                fat.idRegistry      = 0 ;
  102.                fat.usCodePage      = GpiQueryCp (hps) ;
  103.                fat.lMaxBaselineExt = 0 ;
  104.                fat.lAveCharWidth   = 0 ;
  105.                fat.fsType          = 0 ;
  106.                fat.fsFontUse       = FATTR_FONTUSE_OUTLINE ;
  107.  
  108.                strcpy (fat.szFacename, "Tms Rmn") ;
  109.  
  110.                GpiCreateLogFont (hps, NULL, LCID_VECTFONT, &fat) ;
  111.                GpiSetCharSet (hps, LCID_VECTFONT) ;
  112.  
  113.                GpiQueryDefCharBox (hps, &sizlBox) ;
  114.                sizfxBox.cx = MAKEFIXED (sizlBox.cx, 0) ;
  115.                sizfxBox.cy = MAKEFIXED (sizlBox.cy, 0) ;
  116.                GpiSetCharBox (hps, &sizfxBox) ;
  117.  
  118.                GpiQueryFontMetrics (hps, (LONG) sizeof fmVect, &fmVect) ;
  119.  
  120.                sizfxBox.cx = fmRast.lAveCharWidth   * sizfxBox.cx / fmVect.lAveCharWidth ;
  121.                sizfxBox.cy = fmRast.lMaxBaselineExt * sizfxBox.cy / fmVect.lMaxBaselineExt ;
  122.                GpiSetCharBox (hps, &sizfxBox) ;
  123.  
  124.                GpiQueryFontMetrics (hps, (LONG) sizeof fmVect, &fmVect) ;
  125.  
  126.                ptl.x = fmVect.lAveCharWidth ;
  127.                ptl.y = sizlClient.cy - fmVect.lMaxBaselineExt + fmVect.lMaxDescender ;
  128.  
  129.                for (i = 0 ; i < sNumLines ; i++)
  130.                     {
  131.                     GpiCharStringAt (hps, &ptl, (LONG) strlen (aszText[i]),
  132.                                      aszText[i]) ;
  133.  
  134.                     ptl.y -= fmVect.lMaxBaselineExt ;
  135.                     }
  136.  
  137.                GpiSetCharSet (hps, LCID_DEFAULT) ;
  138.                GpiDeleteSetId (hps, LCID_VECTFONT) ;
  139.  
  140.                WinEndPaint (hps) ;
  141.                return 0 ;
  142.  
  143.           case WM_DESTROY:
  144.                GpiDestroyPS (hps) ;
  145.                return 0 ;
  146.           }
  147.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  148.      }
  149.