home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d174 / titlepage.lha / TitlePage / lilpage.c < prev    next >
C/C++ Source or Header  |  1989-02-04  |  3KB  |  147 lines

  1. /*
  2.  * lilpage.c : title page printing program. Create a banner page
  3.  *               for listing heading. (test version)
  4.  *
  5.  *       by Joel Swank 9-23-88
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <graphics/text.h>
  10. #include <libraries/diskfont.h>
  11. #include <functions.h>
  12.  
  13. #ifdef NULL
  14. #undef NULL
  15. #endif
  16. #define NULL ((void *)0)
  17.  
  18. char printbuf[1000];   /* byffer for output line */
  19. char *pbptr;           /* pointer into printbuf  */
  20. char *printstring;     /* pointer to printstring */
  21.  
  22. int maxline = 80;      /* max output line size */
  23. int i,j;
  24. unsigned short *chardata;    /* pointer to array of character patterns */
  25. unsigned short *charspace;   /* pointer to array of character widths   */
  26.  
  27. struct charDef {       /* from RKM Devices & Libraries page 207  */
  28.     WORD charOffset;   /* bit offset to character in chardata    */
  29.     WORD charBitWidth; /* bit width of character data            */
  30.     };
  31.  
  32. struct charDef *charloc; /* pointer to array of chardefs */
  33. struct TextFont *myfont = NULL; /* pointer to open font  */
  34. struct GfxBase *GfxBase = NULL;
  35. FILE *out;
  36.  
  37.  
  38. struct    TextAttr myattr = {
  39.     (STRPTR)("opal.font"),
  40.     12,
  41.     0,
  42.     FPB_DISKFONT};
  43.  
  44. struct Library *DiskfontBase = NULL;
  45.  
  46. main(argc,argv)
  47. int argc;
  48. char *argv[];
  49. {
  50.     printstring = "XYZAdgq";
  51.     out = stdout;
  52.  
  53.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", NULL);
  54.     if (GfxBase == NULL) done(22);
  55.  
  56.     DiskfontBase = (struct Library *)OpenLibrary("diskfont.library", NULL);
  57.     if (DiskfontBase == NULL) {
  58.         fprintf(stderr,"titlep:cannot open font library\n");
  59.         exit(1);
  60.         }
  61.  
  62.     if (DiskfontBase != NULL) {
  63.         if ((myfont = (struct TextFont *)OpenDiskFont(&myattr)) == NULL) {
  64.             fprintf(stderr,"titlep:cannot find puny font\n");
  65.             done(2);
  66.         }
  67.     }
  68.  
  69.     charspace = (unsigned short *) myfont->tf_CharSpace;
  70.     charloc = (struct charDef *) myfont->tf_CharLoc;
  71.  
  72.     /* do a string */
  73.     for (i=0; i<myfont->tf_YSize; i++)
  74.         {
  75.         for (j=0; j<maxline; j++) printbuf[j] =' ';
  76.         do_row(i);
  77.         printbuf[maxline] ='\0';
  78.         fputs(printbuf,out);
  79.         aputc('\n',out);
  80.         }
  81.  
  82. done(0);
  83. }
  84.  
  85.  
  86. /*
  87.  * do_row : build one row of printdata.
  88.  */
  89.  
  90. do_row(row)
  91. int row;   /* which row to do */
  92. {
  93.     int i;
  94.     register unsigned short next16;
  95.     char *pstrptr;
  96.  
  97.     pbptr = printbuf;
  98.     pstrptr = printstring;
  99.     chardata = (unsigned short *) myfont->tf_CharData + 
  100.                     (myfont->tf_Modulo * row)/2;
  101.  
  102.     /* do a charcter  */
  103.     while (*pstrptr != '\0')
  104.         {
  105.         long bitoff, wordoff, bitnum, bitcnt, charoff;
  106.         charoff = (unsigned char) *pstrptr - myfont->tf_LoChar;
  107.         bitoff = charloc[charoff].charOffset;
  108.         bitcnt = charloc[charoff].charBitWidth;
  109.         wordoff = bitoff/16;
  110.         bitnum = bitoff%16;
  111.  
  112.         while (bitcnt > 0)    /* do up to 16 bits */
  113.             {
  114.             char *cptr;
  115.             /* construct dot info in next16 */
  116.             next16 = chardata[wordoff];
  117.             if (bitnum != 0) next16 = (next16 << bitnum) 
  118.                 | (chardata[wordoff+1] >> (16-bitnum));
  119.             cptr = pbptr;
  120.             for (i=0; i<16; i++)
  121.                 {
  122.                 *cptr = (next16 & 0x08000) ? *pstrptr : ' ';
  123.                 cptr++;
  124.                 if (--bitcnt < 1) break;
  125.                 next16 = next16 << 1;
  126.                 }
  127.             wordoff++;
  128.             }
  129.         pbptr += charspace[charoff]; /* bump output ptr */
  130.         pstrptr++;                   /* bump input ptr */
  131.         if (pbptr > printbuf + maxline) break;
  132.         }
  133. }
  134.  
  135. /*
  136.  * done - just clean up that which is open, and then leave.
  137.  */
  138. done(how)
  139. int how;
  140.     {
  141.     if (GfxBase) CloseLibrary(GfxBase) ;
  142.     if (DiskfontBase) CloseLibrary(DiskfontBase) ;
  143.     if (myfont   != NULL) CloseFont( myfont );
  144.     exit(how) ;
  145.     }
  146.  
  147.