Back to index

tetex-bin  3.0
Defines | Functions
vf.c File Reference
#include "xdvi-config.h"
#include "dvi.h"
#include "xdvi.h"
#include "util.h"
#include "dvi-init.h"
#include "dvi-draw.h"

Go to the source code of this file.

Defines

#define LONG_CHAR   242
#define VF_PARM_1   20
#define VF_PARM_2   256

Functions

unsigned long read_VF_index (struct font *fontp, wide_bool hushcs)

Define Documentation

#define LONG_CHAR   242

Definition at line 39 of file vf.c.

#define VF_PARM_1   20

Definition at line 48 of file vf.c.

#define VF_PARM_2   256

Definition at line 51 of file vf.c.


Function Documentation

unsigned long read_VF_index ( struct font fontp,
wide_bool  hushcs 
)

Definition at line 59 of file vf.c.

{
    FILE *VF_file = fontp->file;
    ubyte cmnd;
    ubyte *avail, *availend;       /* available space for macros */
    long checksum;
    struct macro *newmacro;
    unsigned long maxcc = 0;
    Boolean dummy = False;
    
    fontp->read_char = NULL;
    fontp->flags |= FONT_VIRTUAL;
    fontp->set_char_p = set_vf_char;
    if (globals.debug & DBG_PK)
       printf("Reading VF file %s\n", fontp->filename);
    /*
     * Read preamble.
     */
    fseek(VF_file, (long)get_byte(VF_file), SEEK_CUR);  /* skip comment */
    checksum = get_bytes(VF_file, 4);
    if (checksum != fontp->checksum && checksum != 0 && fontp->checksum != 0
       && !hushcs)
       XDVI_WARNING((stderr, "Checksum mismatch (dvi = %lu, vf = %lu) in font file %s",
                    fontp->checksum, checksum, fontp->filename));
    (void)get_bytes(VF_file, 4);   /* skip design size */
    /*
     * Read the fonts.
     */
    fontp->vf_table = xmalloc(VFTABLELEN * sizeof(struct font *));
    memset((char *)fontp->vf_table, 0, VFTABLELEN * sizeof(struct font *));
    fontp->vf_chain = NULL;
    fontp->first_font = NULL;
    while ((cmnd = get_byte(VF_file)) >= FNTDEF1 && cmnd <= FNTDEF4) {
       struct font *newfontp = define_font(True,
                                       VF_file, cmnd, fontp,
                                       fontp->vf_table, VFTABLELEN,
                                       &fontp->vf_chain,
                                       &dummy);
       if (fontp->first_font == NULL)
           fontp->first_font = newfontp;
    }
    /*
     * Prepare macro array.
     */
    if (resource.omega) {
       fontp->maxchar = 65535;
       fontp->macro = xmalloc(65536 * sizeof(struct macro));
       memset((char *)fontp->macro, 0, 65536 * sizeof(struct macro));
    }
    else {
       fontp->macro = xmalloc(256 * sizeof(struct macro));
       memset((char *)fontp->macro, 0, 256 * sizeof(struct macro));
    }
    /*
     * Read macros.
     */
    avail = availend = NULL;
    for (; cmnd <= LONG_CHAR; cmnd = get_byte(VF_file)) {
       struct macro *m;
       int len;
       unsigned long cc;
       long width;

       if (cmnd == LONG_CHAR) {    /* long form packet */
           len = get_bytes(VF_file, 4);
           cc = get_bytes(VF_file, 4);
           width = get_bytes(VF_file, 4);
           if ((resource.omega && cc >= 65536)
              || (!resource.omega && cc >= 256)) {
              XDVI_WARNING((stderr, "Virtual character %lu in font %s ignored.",
                           cc, fontp->fontname));
              fseek(VF_file, (long)len, SEEK_CUR);
              continue;
           }
       }
       else { /* short form packet */
           len = cmnd;
           cc = get_byte(VF_file);
           width = get_bytes(VF_file, 3);
       }
       if (resource.omega) {
           maxcc = (cc > maxcc) ? cc : maxcc;
       }
       m = &fontp->macro[cc];
       m->dvi_adv = width * fontp->dimconv;
       if (len > 0) {
           if (len <= availend - avail) {
              m->pos = avail;
              avail += len;
           }
           else {
              m->free_me = True;
              if (len <= VF_PARM_1) {
                  m->pos = avail = xmalloc(VF_PARM_2);
                  availend = avail + VF_PARM_2;
                  avail += len;
              }
              else
                  m->pos = xmalloc((unsigned)len);
           }
           fread((char *)m->pos, 1, len, VF_file);
           m->end = m->pos + len;
       }
       if (globals.debug & DBG_PK)
            printf("Read VF macro for character %lu; dy = %ld, length = %d\n",
                  cc, m->dvi_adv, len);
    }
    if (cmnd != POST)
       XDVI_FATAL((stderr, "Wrong command byte found in VF macro list:  %d", cmnd));

    fclose(VF_file);
    fontp->file = NULL;
    if (resource.omega) {
       size_t i;
       newmacro = xmalloc((maxcc + 1) * sizeof(struct macro));
       for (i = 0; i <= maxcc; i++) {
           newmacro[i] = fontp->macro[i];
       }
       free(fontp->macro);
       fontp->macro = newmacro;
       fontp->maxchar = maxcc;
       return maxcc;
    }
    else
       return 0; /* dummy */
}

Here is the call graph for this function:

Here is the caller graph for this function: