home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d179 / tsnip.lha / TSnip / tsnipgen.c < prev    next >
C/C++ Source or Header  |  1989-02-25  |  4KB  |  190 lines

  1.  
  2. #include "intuition/intuitionbase.h"
  3. #include "libraries/dosextens.h"
  4. #include "libraries/diskfont.h"
  5.  
  6. #define Wr(fh,string)       Write(fh,string,(long)sizeof(string))
  7. #define Wrlen(fh,string)    Write(fh,string,(long)strlen(string))
  8.  
  9. #define FBUFSIZE 40
  10.  
  11. long DiskfontBase = 0;
  12.  
  13. struct TextAttr ta =
  14. {
  15.     0,   /* name must be installed manually */
  16.     8,
  17.     0,
  18.     FPF_DISKFONT
  19. };
  20.  
  21. struct NewWindow nwindow =
  22. {
  23.     0,0,30,30,
  24.     0,0,
  25.     NULL,
  26.     RMBTRAP | SMART_REFRESH | NOCAREREFRESH | BORDERLESS,
  27.     NULL, NULL,
  28.     NULL,
  29.     NULL, NULL, -1, -1, -1, -1, WBENCHSCREEN
  30. };
  31.  
  32. char plea[] = "Please use Kickstart/Workbench 1.2 for latest ";
  33.  
  34. struct IntuitionBase *IntuitionBase=NULL;
  35. struct GfxBase *GfxBase=NULL;
  36.  
  37. char charcodes[] = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`~!@#$%^&*()-=\\_+|[{]};:'\",<.>/?";
  38.  
  39. void _wb_parse() {}
  40.  
  41. main(argc,argv)
  42. int argc;
  43. char *argv[];
  44. {
  45.     register struct RastPort *rp;
  46.     register int count, x;
  47.  
  48.     UBYTE buffer[8];
  49.     register UBYTE *buf = buffer;
  50.     register char *charcode = charcodes;
  51.  
  52.     struct FileHandle *fp=NULL;
  53.     struct Window *w = NULL;        /* this is the one I open */
  54.  
  55.     struct FileHandle *Output();
  56.     struct FileHandle *out = Output();
  57.  
  58.     char filename[128];
  59.  
  60.     struct TextFont *oldfont,*font=NULL;
  61.     UBYTE fontname[40];
  62.  
  63.     if (argc == 2)
  64.     {
  65.        strncpy(fontname, argv[1], FBUFSIZE);
  66.        strncat(fontname, ".font", FBUFSIZE);
  67.     }
  68.     else
  69.     {
  70.         Wr(out,"\nUsage: snipgen <fontname>\nYou must have the font present in FONTS:\nPut the output file in current directory or in S: for SNIP to use.\n");
  71.         goto breakpoint;
  72.     }
  73.  
  74.     if (!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",33L)))
  75.     {
  76.         Wrlen(out,plea);
  77.         Wr(out,"Intuition.\n");
  78.         goto breakpoint;
  79.     }
  80.  
  81.     if (!(GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",33L)))
  82.     {
  83.         Wrlen(out,plea);
  84.         Wr(out,"Graphics.\n");
  85.         goto breakpoint;
  86.     }
  87.  
  88.     if (!(DiskfontBase = (long)OpenLibrary("diskfont.library", 33L)))
  89.     {
  90.         Wrlen(out,plea);
  91.         Wr(out,"Fonts.\n");
  92.         goto breakpoint;
  93.     }
  94.  
  95.     ta.ta_Name = fontname;
  96.  
  97.     if (!(font = OpenDiskFont(&ta)))
  98.     {
  99.         Wr(out,"Can't open font\n");
  100.         goto breakpoint;
  101.     }
  102.  
  103.     strcpy(filename,argv[1]);
  104.     strcat(filename,".fontdef");
  105.  
  106.     if (!(fp = Open(filename,MODE_NEWFILE)))
  107.     {
  108.         Wr(out, "Unable to open output file\n");
  109.         goto breakpoint;
  110.     }
  111.  
  112.     if (!(w = OpenWindow(&nwindow)))
  113.     {
  114.         Wr(out,"Can't open window\n");
  115.         goto breakpoint;
  116.     }
  117.  
  118.     rp = w->RPort;
  119.  
  120.     oldfont = rp->Font;
  121.  
  122.     /* If the SetFont() works, on cleanup, CloseFont(oldfont) */
  123.  
  124.     if (SetFont(rp, font))
  125.         font = oldfont;
  126.  
  127.     Wr(out,"Encoding 95 characters (should be 760 bytes)\n");
  128.     Wr(out,"Saving in file ");
  129.     Wrlen(out,filename);
  130.     Wr(out,"\n");
  131.  
  132.     for (count = 0; count < 95; count++)
  133.     {
  134.         SetAPen(rp,0L);
  135.         SetDrMd(rp,JAM1);
  136.         RectFill(rp,10L,10L,18L,18L);
  137.         SetAPen(rp,1L);
  138.         Move(rp,10L,16L);
  139.         Text(rp,&charcode[count],1L);
  140.         get_byte(rp,10,10,buf);
  141.         for (x = 0; x < 8; x++)
  142.         {
  143.             Write(fp,&buf[x],1L);
  144.         }
  145.     }
  146.  
  147. breakpoint:
  148.     if (fp)             Close(fp);
  149.     if (w)              CloseWindow(w);
  150.     if (IntuitionBase)  CloseLibrary(IntuitionBase);
  151.     if (GfxBase)        CloseLibrary(GfxBase);
  152.     if (font)           CloseFont(font);
  153.     if (DiskfontBase)   CloseLibrary(DiskfontBase);
  154.     exit(0);
  155. }
  156.  
  157. /*
  158.  *  Given the (x,y) coordinate of the upper left of an 8x8 character position
  159.  *  within a window, this fills the 8-byte buffer with the bitmap of the
  160.  *  character at that position.
  161.  *
  162.  */
  163.  
  164. get_byte(rp, xstart, ystart, buf)
  165. register struct RastPort *rp;
  166. register int xstart, ystart;
  167. register UBYTE buf[8];
  168. {
  169.     register int x,y;
  170.     register UBYTE tx_byte;
  171.  
  172.     for (y=0; y<8; y++)
  173.     {
  174.         tx_byte = 0;
  175.  
  176.         for (x=0; x<8; x++)
  177.         {
  178.             /* NB: I match _any_ colour here */
  179.  
  180.             if (ReadPixel(rp, (long)(xstart+x), (long)(ystart+y)))
  181.             {
  182.                 tx_byte |= (1 << (7-x));
  183.             }
  184.         }
  185.  
  186.         buf[y] = tx_byte;
  187.     }
  188. }
  189.  
  190.