home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 299.lha / FontWide.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-12-02  |  3.4 KB  |  178 lines

  1. #include <exec/types.h>
  2. #include <graphics/gfx.h>
  3. #include <graphics/text.h>
  4. #include <intuition/intuition.h>
  5. #include <libraries/diskfont.h>
  6. #include <functions.h>
  7.  
  8. struct GfxBase       *GfxBase;
  9. struct IntuitionBase *IntuitionBase;
  10. ULONG                *DiskfontBase;
  11. struct Window        *Window;
  12. struct TextFont      *TextFont;
  13.  
  14. #define INTUITION_REV 33L
  15.  
  16. struct TextAttr TA =
  17. { NULL,
  18.   NULL,
  19.   FS_NORMAL,
  20.   FPF_DISKFONT
  21. };
  22.  
  23. struct NewWindow NewWindow =
  24. { 0, 0, 640, 30,
  25.   0, 1,
  26.   CLOSEWINDOW,
  27.   NULL,
  28.   NULL,
  29.   NULL,
  30.   (UBYTE *)"FontSize",
  31.   NULL,
  32.   NULL,
  33.   0, 0, 640, 30,
  34.   WBENCHSCREEN
  35. };
  36.  
  37. main()
  38. {
  39.  
  40.  char strng[80];
  41.  char Fname[30];
  42.  char *s, *e;
  43.  struct RastPort *Rport;
  44.  struct TextFont *Fptr;
  45.  USHORT          *Sptr;
  46.  
  47.  USHORT Pixels, Length, Size, i, j;
  48.  USHORT Offset;
  49.  
  50.  OpenAll();
  51.  
  52.  Rport = (struct RastPort *) (*Window).RPort;
  53.  
  54.  FOREVER
  55.   {
  56.    for(i=0; i != 80; strng[i++] = NULL);
  57.  
  58.    printf("input your Scan Line :\n");
  59.  
  60.    gets(strng);
  61.    if(strng[0] == '/')
  62.    {
  63.     switch ((char) (strng[1]))
  64.     {
  65.      case 'i':
  66.      case 'I':
  67.       {
  68.        AskFont(Rport, &TA);
  69.        printf("%s, %d\n", TA.ta_Name, TA.ta_YSize);
  70.        break;
  71.       }
  72.      case 'f':
  73.      case 'F':
  74.       {
  75.        s = strng + 3;
  76.        while(*(s++) != ' ');
  77.        s--;
  78.        *(s++) = NULL;
  79.        strcpy(Fname, &strng[3]);
  80.        Size = atoi(s);
  81.        TA.ta_YSize = Size;
  82.        TA.ta_Name = Fname;
  83.        printf("%s\n  %d\n",Fname, Size);
  84.        TextFont = (struct TextFont *)
  85.                    OpenDiskFont(&TA);
  86.        if (TextFont == NULL)
  87.         printf("Font not found.\n");
  88.        else
  89.         SetFont(Rport, TextFont);
  90.        break;
  91.       }
  92.      case 'q':
  93.      case 'Q':
  94.       {
  95.        CloseAll();
  96.        exit(TRUE);
  97.        break;
  98.       }
  99.      default:
  100.      { 
  101.       printf("Unrecognized command!\n");
  102.       break;
  103.      }
  104.     }
  105.    }
  106.    else
  107.    {
  108.     Length = strlen(strng);
  109.     printf("%d\n", Length);
  110.     Fptr = (*(*Window).RPort).Font;
  111.     Sptr = (*Fptr).tf_CharSpace;
  112.  
  113.     if ( Sptr == NULL )
  114.       Pixels = ((*Fptr).tf_XSize) * Length;
  115.     else
  116.     {
  117.       for(i=0; !(i == Length) ; i++)
  118.         if((strng[i] < (*Fptr).tf_LoChar) || (strng[i] > (*Fptr).tf_HiChar))
  119.         {
  120.           printf("Character \"%s\" is not a member of the font!\n", strng[i]);
  121.           goto Stop;
  122.           break;
  123.         }
  124.       Pixels = 0;
  125.       for(i=0; !(i == Length) ; i++)
  126.       {
  127.         Offset = strng[i] - (*Fptr).tf_LoChar;
  128.         Pixels = Pixels + (*Sptr + Offset);
  129.       }
  130.     }
  131.     printf("Text \"%s\" is %d letters, %d pixels wide.\n", strng, Length, Pixels);
  132.    }
  133. Stop:;             /* Who says Gotos are evil? */
  134.   }
  135. }
  136.  
  137. CloseAll()
  138. {
  139. if(TextFont)      CloseFont(TextFont);
  140. if(Window)        CloseWindow(Window);
  141. if(DiskfontBase)  CloseLibrary(DiskfontBase);
  142. if(IntuitionBase) CloseLibrary(IntuitionBase);
  143. if(GfxBase)       CloseLibrary(GfxBase);
  144. }
  145.  
  146. OpenAll()
  147. {
  148.  if ((GfxBase = (struct GfxBase *)
  149.       OpenLibrary("graphics.library", INTUITION_REV)) == NULL )
  150.   { printf("graphics\n");
  151.     CloseAll();
  152.     exit(FALSE); }
  153.  
  154. printf("1");
  155.  
  156.  if ((IntuitionBase = (struct IntuitionBase *)
  157.       OpenLibrary("intuition.library", INTUITION_REV)) == NULL )
  158.   { printf("intuition\n");
  159.     CloseAll();
  160.     exit(FALSE); }
  161.  
  162. printf("2");
  163.  
  164.  if ((DiskfontBase =
  165.       OpenLibrary("diskfont.library",INTUITION_REV)) == NULL )
  166.   { printf("diskfont\n");
  167.     CloseAll();
  168.     exit(FALSE); }
  169.  
  170. printf("3");
  171.  
  172.  if ((Window = OpenWindow(&NewWindow)) == NULL )
  173.   { printf("window\n");
  174.     CloseAll();
  175.     exit(FALSE); }
  176. }
  177.  
  178.