home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / S12219.ZIP / VF05.C < prev    next >
C/C++ Source or Header  |  1988-11-29  |  3KB  |  76 lines

  1. /*--------------------------------------------
  2.    VF05.C -- Display "Hello, world" in circle
  3.   --------------------------------------------*/
  4.  
  5. #define INCL_GPI
  6. #include <os2.h>
  7. #include <math.h>
  8. #include <stdlib.h>
  9. #include "vectfont.h"
  10.  
  11. VOID Display_Rotate (HPS hps, LONG cxClient, LONG cyClient)
  12.      {
  13.      static CHAR szText[] = "Hello, world! " ;
  14.      static LONG cbText = sizeof szText - 1L ;
  15.      static LONG alWidthTable[256] ;
  16.      double      ang, angCharWidth, angChar ;
  17.      FONTMETRICS fm ;
  18.      GRADIENTL   gradl ;
  19.      INT         iChar ;
  20.      LONG        lCircum, lRadius, lTotWidth, lCharRadius, cyChar ;
  21.      POINTL      ptl ;
  22.  
  23.                          // Create the font and get font metrics
  24.  
  25.      CreateVectorFont (hps, LCID_MYFONT, "Tms Rmn") ;
  26.      GpiSetCharSet (hps, LCID_MYFONT) ;
  27.  
  28.      GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ;
  29.  
  30.                          // Find circle dimensions and scale font
  31.  
  32.      lRadius = min (cxClient / 4, cyClient / 4) ;
  33.      lCircum = (LONG) (2 * PI * lRadius) ;
  34.      cyChar  = fm.lMaxBaselineExt * lRadius / fm.lMaxAscender ;
  35.  
  36.      ScaleFontToBox (hps, cbText, szText, lCircum, cyChar) ;
  37.  
  38.                          // Obtain width table and total width
  39.  
  40.      GpiQueryWidthTable (hps, 0L, 256L, alWidthTable) ;
  41.  
  42.      for (lTotWidth = 0, iChar = 0 ; iChar < (INT) cbText ; iChar ++)
  43.           lTotWidth += alWidthTable [szText [iChar]] ;
  44.  
  45.      ang = PI / 2 ;      // Initial angle for first character
  46.  
  47.      for (iChar = 0 ; iChar < (INT) cbText ; iChar++)
  48.           {
  49.                               // Set character angle
  50.  
  51.           angCharWidth = 2 * PI * alWidthTable [szText [iChar]] / lTotWidth ;
  52.  
  53.           gradl.x = (LONG) (lRadius * cos (ang - angCharWidth / 2 - PI / 2)) ;
  54.           gradl.y = (LONG) (lRadius * sin (ang - angCharWidth / 2 - PI / 2)) ;
  55.  
  56.           GpiSetCharAngle (hps, &gradl) ;
  57.  
  58.                               // Find position for character and display it
  59.  
  60.           angChar = atan2 ((double) alWidthTable [szText [iChar]] / 2,
  61.                            (double) lRadius) ;
  62.  
  63.           lCharRadius = (LONG) (lRadius / cos (angChar)) ;
  64.           angChar += ang - angCharWidth / 2 ;
  65.  
  66.           ptl.x = (LONG) (cxClient / 2 + lCharRadius * cos (angChar)) ;
  67.           ptl.y = (LONG) (cyClient / 2 + lCharRadius * sin (angChar)) ;
  68.  
  69.           GpiCharStringAt (hps, &ptl, 1L, szText + iChar) ;
  70.  
  71.           ang -= angCharWidth ;
  72.           }
  73.      GpiSetCharSet (hps, LCID_DEFAULT) ;          // Clean up
  74.      GpiDeleteSetId (hps, LCID_MYFONT) ;
  75.      }
  76.