home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-src.tgz / tar.out / contrib / unixtex / xdvik / vf.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  5KB  |  161 lines

  1. /*
  2.  * Copyright (c) 1994 Paul Vojta.  All rights reserved.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  * 1. Redistributions of source code must retain the above copyright
  8.  *    notice, this list of conditions and the following disclaimer.
  9.  * 2. Redistributions in binary form must reproduce the above copyright
  10.  *    notice, this list of conditions and the following disclaimer in the
  11.  *    documentation and/or other materials provided with the distribution.
  12.  *
  13.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  14.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  17.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  19.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  20.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  23.  * SUCH DAMAGE.
  24.  */
  25.  
  26. #include "config.h"
  27. #include "dvi.h"
  28.  
  29.  
  30. /***
  31.  ***    VF font reading routines.
  32.  ***    Public routine is read_index---because virtual characters are presumed
  33.  ***    to be short, we read the whole virtual font in at once, instead of
  34.  ***    faulting in characters as needed.
  35.  ***/
  36.  
  37. #define    LONG_CHAR    242
  38.  
  39. /*
  40.  *    These are parameters which determine whether macros are combined for
  41.  *    storage allocation purposes.  Small macros ( <= VF_PARM_1 bytes) are
  42.  *    combined into chunks of size VF_PARM_2.
  43.  */
  44.  
  45. #ifndef    VF_PARM_1
  46. #define    VF_PARM_1    20
  47. #endif
  48. #ifndef    VF_PARM_2
  49. #define    VF_PARM_2    256
  50. #endif
  51.  
  52. /*
  53.  *    The main routine
  54.  */
  55.  
  56. void
  57. read_VF_index(fontp, hushcs)
  58.     register struct font    *fontp;
  59.     wide_bool        hushcs;
  60. {
  61.     FILE    *VF_file = fontp->file;
  62.     ubyte    cmnd;
  63.     ubyte    *avail, *availend;    /* available space for macros */
  64.     long    checksum;
  65.  
  66.     fontp->read_char = NULL;
  67.     fontp->flags |= FONT_VIRTUAL;
  68.     fontp->set_char_p = set_vf_char;
  69.     if (debug & DBG_PK)
  70.         Printf("Reading VF pixel file %s\n", fontp->filename);
  71. /*
  72.  *    Read preamble.
  73.  */
  74.     Fseek(VF_file, (long) one(VF_file), 1);    /* skip comment */
  75.     checksum = four(VF_file);
  76.     if (!hushcs && checksum && fontp->checksum
  77.         && checksum != fontp->checksum)
  78.         Fprintf(stderr,
  79.         "Checksum mismatch (dvi = %lu, vf = %lu) in font file %s\n",
  80.         fontp->checksum, checksum, fontp->filename);
  81.     (void) four(VF_file);        /* skip design size */
  82. /*
  83.  *    Read the fonts.
  84.  */
  85.     fontp->vf_table = (struct font **)
  86.         xmalloc(VFTABLELEN * sizeof(struct font *),
  87.         "table of VF TeXnumbers");
  88.     bzero((char *) fontp->vf_table, VFTABLELEN * sizeof(struct font *));
  89.     fontp->vf_chain = NULL;
  90.     fontp->first_font = NULL;
  91.     while ((cmnd = one(VF_file)) >= FNTDEF1 && cmnd <= FNTDEF4) {
  92.         struct font *newfontp = define_font(VF_file, cmnd, fontp,
  93.         fontp->vf_table, VFTABLELEN, &fontp->vf_chain);
  94.         if (fontp->first_font == NULL) fontp->first_font = newfontp;
  95.     }
  96. /*
  97.  *    Prepare macro array.
  98.  */
  99.     fontp->macro = (struct macro *) xmalloc(256 * sizeof(struct macro),
  100.         "macro array");
  101.     bzero((char *) fontp->macro, 256 * sizeof(struct macro));
  102. /*
  103.  *    Read macros.
  104.  */
  105.     avail = availend = NULL;
  106.     for (; cmnd <= LONG_CHAR; cmnd = one(VF_file)) {
  107.         register struct macro *m;
  108.         int len;
  109.         unsigned long cc;
  110.         long width;
  111.  
  112.         if (cmnd == LONG_CHAR) {    /* long form packet */
  113.         len = four(VF_file);
  114.         cc = four(VF_file);
  115.         width = four(VF_file);
  116.         if (cc >= 256) {
  117.             Fprintf(stderr,
  118.             "Virtual character %lu in font %s ignored.\n",
  119.             cc, fontp->fontname);
  120.             Fseek(VF_file, (long) len, 1);
  121.             continue;
  122.         }
  123.         }
  124.         else {    /* short form packet */
  125.         len = cmnd;
  126.         cc = one(VF_file);
  127.         width = num(VF_file, 3);
  128.         }
  129.         m = &fontp->macro[cc];
  130.         m->dvi_adv = width * fontp->dimconv;
  131.         if (len > 0) {
  132.         if (len <= availend - avail) {
  133.             m->pos = avail;
  134.             avail += len;
  135.         }
  136.         else {
  137.             m->free_me = True;
  138.             if (len <= VF_PARM_1) {
  139.             m->pos = avail = (ubyte *) xmalloc(VF_PARM_2,
  140.                 "macro array");
  141.             availend = avail + VF_PARM_2;
  142.             avail += len;
  143.             }
  144.             else m->pos = (ubyte *) xmalloc((unsigned) len,
  145.             "macro array");
  146.         }
  147.         Fread((char *) m->pos, 1, len, VF_file);
  148.         m->end = m->pos + len;
  149.         }
  150.         if (debug & DBG_PK)
  151.         Printf("Read VF macro for character %lu; dy = %ld, length = %d\n",
  152.             cc, m->dvi_adv, len);
  153.     }
  154.     if (cmnd != POST)
  155.         oops("Wrong command byte found in VF macro list:  %d", cmnd);
  156.     
  157.     Fclose (VF_file);
  158.     n_files_left++;
  159.     fontp->file = NULL;
  160. }
  161.