home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / bdftools / part01 / dumpvfont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-07  |  1.4 KB  |  66 lines

  1. #include    <stdio.h>
  2. #include    <vfont.h>
  3. #include    <sys/types.h>
  4.  
  5. #define        NCHARS    256
  6.  
  7. struct header    vhdr;
  8. struct dispatch    vd[NCHARS];
  9.  
  10. initialize(argc, argv)
  11.     int        argc;
  12.     char        *argv[];
  13. {
  14.     if (argc < 2)
  15.         fatal("Usage: bdf2vf vf");
  16.  
  17.     if (freopen(argv[1], "w", stdout) == NULL)
  18.         fatal("Cannot open output file");
  19. }
  20.  
  21. storeglyph(n, bbx, bby, offx, offy)
  22.     int        n, bbx, bby, offx, offy;
  23. {
  24.     register struct dispatch    *d;
  25.  
  26.     d = &vd[n];
  27.     d->nbytes = (bbx + 7) / 8 * bby;
  28.     d->right = bbx + offx;
  29.     d->left = -offx;
  30.     d->up = bby + offy;
  31.     d->down = -offy;
  32.     d->width = bbx;
  33.     if (bbx > vhdr.maxx)
  34.         vhdr.maxx = bbx;
  35.     if (bby > vhdr.maxy)
  36.         vhdr.maxy = bby;
  37. }
  38.  
  39. dumpfont(bitmaps)
  40.     u_char    *bitmaps[NCHARS];
  41. {
  42.     register int    c, bitbytes = 0;
  43.     register struct dispatch    *d;
  44.  
  45.     if (fseek(stdout, (long)(sizeof(vhdr) + sizeof(vd)), 0) < 0)
  46.         fatal("Cannot seek on output");
  47.     for (c = 0; c < NCHARS; ++c)
  48.     {
  49.         if (bitmaps[c] != NULL && (d = &vd[c])->nbytes > 0)
  50.         {
  51.             d->addr = bitbytes;
  52.             if (fwrite((char *)bitmaps[c], d->nbytes, 1, stdout) != 1)
  53.                 fatal("Cannot write glyph");
  54.             bitbytes += d->nbytes;
  55.         }
  56.     }
  57.     vhdr.magic = VFONT_MAGIC;
  58.     vhdr.size = bitbytes;
  59.     if (fseek(stdout, 0L, 0) < 0)
  60.         fatal("Cannot seek to beginning on output");
  61.     if (fwrite((char *)&vhdr, sizeof(vhdr), 1, stdout) != 1)
  62.         fatal("Cannot write header");
  63.     if (fwrite((char *)vd, sizeof(vd), 1, stdout) != 1)
  64.         fatal("Cannot write dispatch table");
  65. }
  66.