Back to index

tetex-bin  3.0
Classes | Defines | Functions | Variables
dvi.c File Reference
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "system.h"
#include "mem.h"
#include "error.h"
#include "mfileio.h"
#include "numbers.h"
#include "dvi.h"
#include "dvicodes.h"
#include "pdflimits.h"
#include "pdfdev.h"
#include "pdfdoc.h"
#include "tfm.h"
#include "vf.h"

Go to the source code of this file.

Classes

struct  loaded_font
struct  font_def
struct  dvi_registers

Defines

#define PHYSICAL   1
#define VIRTUAL   2
#define DVI   1
#define VF   2
#define range_check_loc(loc)   {if ((loc) > dvi_file_size) invalid_signature();}
#define S_BUFFER_SIZE   1024

Functions

static void need_more_fonts (unsigned n)
void dvi_set_verbose (void)
void dvi_compute_boxes (unsigned char boxes)
void dvi_set_debug (void)
unsigned dvi_npages (void)
static void invalid_signature ()
static void find_post (void)
static void get_page_info (void)
double dvi_tell_mag (void)
static void do_scales (double mag)
static void get_dvi_info (void)
static void dump_font_info (void)
static void get_a_font_record (SIGNED_QUAD tex_id)
static void get_dvi_fonts (void)
void get_comment (void)
static void clear_state (void)
double dvi_unit_size (void)
int dvi_locate_font (char *tex_name, spt_t ptsize)
double dvi_dev_xpos (void)
double dvi_dev_ypos (void)
static void do_moveto (SIGNED_QUAD x, SIGNED_QUAD y)
void dvi_right (SIGNED_QUAD x)
void dvi_down (SIGNED_QUAD y)
static void do_string (unsigned char *s, int len)
void dvi_set (SIGNED_QUAD ch)
void dvi_put (SIGNED_QUAD ch)
void dvi_rule (SIGNED_QUAD width, SIGNED_QUAD height)
static void do_set1 (void)
static void do_set2 (void)
static void do_setrule (void)
static void do_putrule (void)
static void do_put1 (void)
static void do_put2 (void)
void dvi_push (void)
void dvi_pop (void)
static void do_right1 (void)
static void do_right2 (void)
static void do_right3 (void)
static void do_right4 (void)
void dvi_w (SIGNED_QUAD ch)
void dvi_w0 (void)
static void do_w1 (void)
static void do_w2 (void)
static void do_w3 (void)
static void do_w4 (void)
void dvi_x (SIGNED_QUAD ch)
void dvi_x0 (void)
static void do_x1 (void)
static void do_x2 (void)
static void do_x3 (void)
static void do_x4 (void)
static void do_down1 (void)
static void do_down2 (void)
static void do_down3 (void)
static void do_down4 (void)
void dvi_y (SIGNED_QUAD ch)
void dvi_y0 (void)
static void do_y1 (void)
static void do_y2 (void)
static void do_y3 (void)
static void do_y4 (void)
void dvi_z (SIGNED_QUAD ch)
void dvi_z0 (void)
static void do_z1 (void)
static void do_z2 (void)
static void do_z3 (void)
static void do_z4 (void)
static void do_fntdef (void)
static void do_fntdef1 (void)
static void do_fntdef2 (void)
static void do_fntdef3 (void)
static void do_fntdef4 (void)
void dvi_set_font (int font_id)
static void do_fnt (SIGNED_QUAD tex_id)
static void do_fnt1 (void)
static void do_fnt2 (void)
static void do_fnt3 (void)
static void do_fnt4 (void)
static void do_xxx (UNSIGNED_QUAD size)
static void do_xxx1 (void)
static void do_xxx2 (void)
static void do_xxx3 (void)
static void do_xxx4 (void)
static void do_bop (void)
static void do_eop (void)
void dvi_do_page (unsigned n)
error_t dvi_init (char *dvi_filename, char *pdf_filename, double mag, double x_offset, double y_offset)
void dvi_close (void)
void dvi_vf_init (int dev_font_id)
void dvi_vf_finish (void)

Variables

static FILEdvi_file
static char debug = 0
static unsigned num_loaded_fonts = 0
static unsigned max_loaded_fonts = 0
static unsigned stackdepth
static unsigned long * page_loc = NULL
static unsigned long post_location
static unsigned long dvi_file_size
static UNSIGNED_PAIR num_pages = 0
static UNSIGNED_QUAD media_width
static UNSIGNED_QUAD media_height
static UNSIGNED_QUAD dvi_unit_num
static UNSIGNED_QUAD dvi_unit_den
static UNSIGNED_QUAD dvi_mag
struct loaded_fontloaded_fonts
struct font_defdef_fonts
static unsigned num_def_fonts = 0
static unsigned max_def_fonts = 0
static unsigned char verbose = 0
static unsigned char compute_boxes = 0
static double dvi2pts = 0.0
static double total_mag = 1.0
static struct dvi_registers
static int current_font
static unsigned dvi_stack_depth = 0
static int processing_page = 0
static unsigned char s_buffer [S_BUFFER_SIZE]
static unsigned s_len = 0
static int saved_dvi_font [MAX_VF_NESTING]
static int num_saved_fonts = 0

Class Documentation

struct loaded_font

Definition at line 60 of file dvi.c.

Class Members
int font_id
spt_t size
int source
int tfm_id
int type
struct font_def

Definition at line 78 of file dvi.c.

Class Members
unsigned long checksum
unsigned long design_size
int dev_id
char * directory
signed long font_id
int font_id
char * name
unsigned long size
spt_t size
signed long tex_id
int tfm_id
int used
struct dvi_registers

Definition at line 332 of file dvi.c.

Class Members
SIGNED_QUAD h
SIGNED_QUAD v
SIGNED_QUAD w
SIGNED_QUAD x
SIGNED_QUAD y
SIGNED_QUAD z

Define Documentation

#define DVI   1

Definition at line 57 of file dvi.c.

#define PHYSICAL   1

Definition at line 55 of file dvi.c.

#define range_check_loc (   loc)    {if ((loc) > dvi_file_size) invalid_signature();}

Definition at line 120 of file dvi.c.

#define S_BUFFER_SIZE   1024

Definition at line 944 of file dvi.c.

#define VF   2

Definition at line 58 of file dvi.c.

#define VIRTUAL   2

Definition at line 56 of file dvi.c.


Function Documentation

static void clear_state ( void  ) [static]

Definition at line 342 of file dvi.c.

{
  dvi_state.h = 0; dvi_state.v = 0; dvi_state.w = 0;
  dvi_state.x = 0; dvi_state.y = 0; dvi_state.z = 0;
  dvi_stack_depth = 0;
  current_font = -1;
}

Here is the caller graph for this function:

static void do_bop ( void  ) [static]

Definition at line 914 of file dvi.c.

{
  int i;
  if (processing_page) 
    ERROR ("dvi_do_bop:  Got a bop inthe middle of a page");
  /* For now, ignore TeX's count registers */
  for (i=0; i<10; i++) {
    get_signed_quad (dvi_file);
  }
/*  Ignore previous page pointer since we have already saved this
    information */
  get_signed_quad (dvi_file);
  clear_state();
  processing_page = 1;
  dev_bop();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_down1 ( void  ) [static]

Definition at line 696 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_down2 ( void  ) [static]

Definition at line 701 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_down3 ( void  ) [static]

Definition at line 706 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_down4 ( void  ) [static]

Definition at line 711 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_eop ( void  ) [static]

Definition at line 931 of file dvi.c.

{
  processing_page = 0;
  if (dvi_stack_depth != 0) {
    ERROR ("do_eop:  stack_depth is not zero at end of page");
  }
  dev_eop();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_fnt ( SIGNED_QUAD  tex_id) [static]

Definition at line 821 of file dvi.c.

{
  int i;
  for (i=0; i<num_def_fonts; i++) {
    if (def_fonts[i].tex_id == tex_id)
      break;
  }
  if (i == num_def_fonts) {
    fprintf (stderr, "fontid: %ld\n", tex_id);
    ERROR ("dvi_do_fnt:  Tried to select a font that hasn't been defined");
  }
  if (!def_fonts[i].used) {
    int font_id;
    font_id = dvi_locate_font (def_fonts[i].name, def_fonts[i].size);
    loaded_fonts[font_id].source = DVI;
    def_fonts[i].used = 1;
    def_fonts[i].font_id = font_id;
  }
  current_font = def_fonts[i].font_id;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_fnt1 ( void  ) [static]

Definition at line 842 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_fnt2 ( void  ) [static]

Definition at line 849 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_fnt3 ( void  ) [static]

Definition at line 856 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_fnt4 ( void  ) [static]

Definition at line 863 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_fntdef ( void  ) [static]

Definition at line 778 of file dvi.c.

{
  int area_len, name_len, i;
  get_signed_quad(dvi_file);
  get_signed_quad(dvi_file);
  get_signed_quad(dvi_file);
  area_len = get_unsigned_byte(dvi_file);
  name_len = get_unsigned_byte(dvi_file);
  for (i=0; i<area_len+name_len; i++) {
    get_unsigned_byte (dvi_file);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_fntdef1 ( void  ) [static]

Definition at line 791 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_fntdef2 ( void  ) [static]

Definition at line 797 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_fntdef3 ( void  ) [static]

Definition at line 803 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_fntdef4 ( void  ) [static]

Definition at line 809 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_moveto ( SIGNED_QUAD  x,
SIGNED_QUAD  y 
) [static]

Definition at line 405 of file dvi.c.

{
  dvi_state.h = x;
  dvi_state.v = y;
}

Here is the caller graph for this function:

static void do_put1 ( void  ) [static]

Definition at line 577 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_put2 ( void  ) [static]

Definition at line 582 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_putrule ( void  ) [static]

Definition at line 567 of file dvi.c.

{
  SIGNED_QUAD width, height;
  height = get_signed_quad (dvi_file);
  width = get_signed_quad (dvi_file);
  if (width > 0 && height > 0) {
    dvi_rule (width, height);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_right1 ( void  ) [static]

Definition at line 614 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_right2 ( void  ) [static]

Definition at line 619 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_right3 ( void  ) [static]

Definition at line 624 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_right4 ( void  ) [static]

Definition at line 629 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_scales ( double  mag) [static]

Definition at line 193 of file dvi.c.

{
  total_mag = (double) dvi_mag / 1000.0 * mag;
  dvi2pts = (double) dvi_unit_num / (double) dvi_unit_den;
  dvi2pts *= (72.0)/(254000.0);
}

Here is the caller graph for this function:

static void do_set1 ( void  ) [static]

Definition at line 546 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_set2 ( void  ) [static]

Definition at line 551 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_setrule ( void  ) [static]

Definition at line 556 of file dvi.c.

{
  SIGNED_QUAD width, height;
  height = get_signed_quad (dvi_file);
  width = get_signed_quad (dvi_file);
  if (width > 0 && height > 0) {
    dvi_rule (width, height);
  }
  dvi_right (width);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_string ( unsigned char *  s,
int  len 
) [static]

Definition at line 421 of file dvi.c.

{
  spt_t width = 0, height = 0, depth = 0;
  int i;
  struct loaded_font *p;
  if (debug) {
    int i;
    fprintf (stderr, "do_string: (font: %d)\n", current_font);
    for (i=0; i<len; i++) fputc (s[i], stderr);
    fputc ('\n', stderr);
  }
  
  if (current_font < 0) {
    ERROR ("do_string:  No font selected");
  }
  p = loaded_fonts+current_font;
  width = tfm_string_width (p->tfm_id, s, len);
  width = sqxfw (p->size, width);
  switch (p->type) {
  case PHYSICAL:
    dev_set_string (dvi_state.h, -dvi_state.v, s, len,
                  width, p->font_id);
    if (compute_boxes) {
      height = tfm_string_height (p->tfm_id, s, len);
      depth = tfm_string_depth (p->tfm_id, s, len);
      height = sqxfw (p->size, height);
      depth = sqxfw (p->size, depth);
      dev_expand_box (width, height, depth);
    }
    break;
  case VIRTUAL:
    dvi_push();
    for (i=0; i<len; i++) {
      dvi_set (s[i]);
    }
    dvi_pop();
  }
  dvi_state.h += width;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_w1 ( void  ) [static]

Definition at line 645 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_w2 ( void  ) [static]

Definition at line 650 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_w3 ( void  ) [static]

Definition at line 655 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_w4 ( void  ) [static]

Definition at line 660 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_x1 ( void  ) [static]

Definition at line 676 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_x2 ( void  ) [static]

Definition at line 681 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_x3 ( void  ) [static]

Definition at line 686 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_x4 ( void  ) [static]

Definition at line 691 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_xxx ( UNSIGNED_QUAD  size) [static]

Definition at line 870 of file dvi.c.

{
  UNSIGNED_QUAD i;
  Ubyte *buffer;
  buffer = NEW (size+1, Ubyte);
  for (i=0; i<size; i++) {
    buffer[i] = get_unsigned_byte(dvi_file);
  }
  if (debug)
    fprintf (stderr, "Special: %s\n", buffer);
  dev_do_special (buffer, size, dvi_state.h, dvi_state.v);
  RELEASE (buffer);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_xxx1 ( void  ) [static]

Definition at line 884 of file dvi.c.

{
  SIGNED_QUAD size;
  if (debug)
    fprintf (stderr, "(xxx1)");
  size = get_unsigned_byte(dvi_file);
  do_xxx(size);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_xxx2 ( void  ) [static]

Definition at line 893 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_xxx3 ( void  ) [static]

Definition at line 900 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_xxx4 ( void  ) [static]

Definition at line 907 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_y1 ( void  ) [static]

Definition at line 727 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_y2 ( void  ) [static]

Definition at line 732 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_y3 ( void  ) [static]

Definition at line 737 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_y4 ( void  ) [static]

Definition at line 742 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_z1 ( void  ) [static]

Definition at line 758 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_z2 ( void  ) [static]

Definition at line 763 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_z3 ( void  ) [static]

Definition at line 768 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_z4 ( void  ) [static]

Definition at line 773 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void dump_font_info ( void  ) [static]

Definition at line 227 of file dvi.c.

{
  unsigned i;
  fprintf (stderr, "\nDVI file font info\n");
  for (i=0; i<num_def_fonts; i++) {
    fprintf (stderr, "name: %10s, ", def_fonts[i].name);
    fprintf (stderr, "TeX/DVI ID: %5ld, ", def_fonts[i].tex_id);
    fprintf (stderr, "size: %5.2f pt, ", def_fonts[i].size*dvi2pts);
    fprintf (stderr, "\n");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1181 of file dvi.c.

{
  int i;
  /* We add comment in dvi_close instead of dvi_init so user has
     a change to overwrite it.  The docinfo dictionary is
     treated as a write-once record */

  /* Do some house cleaning */
  MFCLOSE (dvi_file);
  for (i=0; i<num_def_fonts; i++) {
    RELEASE (def_fonts[i].name);
  }
  if (def_fonts)
    RELEASE (def_fonts);
  RELEASE (page_loc);
  num_loaded_fonts = 0;
  if (loaded_fonts)
    RELEASE (loaded_fonts);
  num_pages = 0;
  dvi_file = NULL;
  dev_close_all_fonts();
  vf_close_all_fonts();
  tfm_close_all();
  dev_close();
  pdf_doc_close();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dvi_compute_boxes ( unsigned char  boxes)

Definition at line 100 of file dvi.c.

{
  compute_boxes = boxes;
}

Here is the caller graph for this function:

double dvi_dev_xpos ( void  )

Definition at line 396 of file dvi.c.

                          {
  return dvi_state.h*dvi2pts;
}

Here is the caller graph for this function:

double dvi_dev_ypos ( void  )

Definition at line 400 of file dvi.c.

{
  return -(dvi_state.v*dvi2pts);
}

Here is the caller graph for this function:

void dvi_do_page ( unsigned  n)

Definition at line 948 of file dvi.c.

{
  unsigned char opcode;
  /* Position to beginning of page */
  if (debug) fprintf (stderr, "Seeking to page %d @ %ld\n", n,
                       page_loc[n]);
  seek_absolute (dvi_file, page_loc[n]);
  dvi_stack_depth = 0;
  for (;;) {
    /* The most likely opcodes are individual setchars.  These are
       buffered for speed */
    s_len = 0;
    while ((opcode = fgetc (dvi_file)) <= SET_CHAR_127 &&
          s_len < S_BUFFER_SIZE) {
      s_buffer[s_len++] = opcode;
    }
    if (s_len > 0) {
      do_string (s_buffer, s_len);
    }
    if (s_len == S_BUFFER_SIZE)
      continue;
    /* If we are here, we have an opcode that is something
       other than SET_CHAR */
    if (opcode >= FNT_NUM_0 && opcode <= FNT_NUM_63) {
      do_fnt (opcode - FNT_NUM_0);
      continue;
    }
    switch (opcode)
      {
      case SET1:
       do_set1();
       break;
      case SET2:
       do_set2();
       break;
      case SET3:
      case SET4:
       ERROR ("Multibyte (>16 bits) character in DVI file.  I can't handle this!");
       break;
      case SET_RULE:
       do_setrule();
       break;
      case PUT1:
       do_put1();
       break;
      case PUT2:
       do_put2();
       break;
      case PUT3:
      case PUT4:
       ERROR ("Multibyte character (>16 bits) in DVI file.  I can't handle this!");
       break;
      case PUT_RULE:
       do_putrule();
       break;
      case NOP:
       break;
      case BOP:
       do_bop();
       break;
      case EOP:
       do_eop();
       return;
      case PUSH:
       dvi_push();
       /* The following line needs to go here instead of in
          dvi_push() since logical structure of document is
          oblivous to virtual fonts. For example the last line on a
          page could be at stack level 3 and the page footer should
          be at stack level 3.  However, if the page footer contains
          virtual fonts (or other nested constructions), it could
          fool the link breaker into thinking it was a continuation
          of the link */
       dev_stack_depth (dvi_stack_depth);
       break;
      case POP:
       dvi_pop();
       /* Above explanation holds for following line too */
       dev_stack_depth (dvi_stack_depth);
       break;
      case RIGHT1:
       do_right1();
       break;
      case RIGHT2:
       do_right2();
       break;
      case RIGHT3:
       do_right3();
       break;
      case RIGHT4:
       do_right4();
       break;
      case W0:
       dvi_w0();
       break;
      case W1:
       do_w1();
       break;
      case W2:
       do_w2();
       break;
      case W3:
       do_w3();
       break;
      case W4:
       do_w4();
       break;
      case X0:
       dvi_x0();
       break;
      case X1:
       do_x1();
       break;
      case X2:
       do_x2();
       break;
      case X3:
       do_x3();
       break;
      case X4:
       do_x4();
       break;
      case DOWN1:
       do_down1();
       break;
      case DOWN2:
       do_down2();
       break;
      case DOWN3:
       do_down3();
       break;
      case DOWN4:
       do_down4();
       break;
      case Y0:
       dvi_y0();
       break;
      case Y1:
       do_y1();
       break;
      case Y2:
       do_y2();
       break;
      case Y3:
       do_y3();
       break;
      case Y4:
       do_y4();
       break;
      case Z0:
       dvi_z0();
       break;
      case Z1:
       do_z1();
       break;
      case Z2:
       do_z2();
       break;
      case Z3:
       do_z3();
       break;
      case Z4:
       do_z4();
       break;
      case FNT1:
       do_fnt1();
       break;
      case FNT2:
       do_fnt2();
       break;
      case FNT3:
       do_fnt3();
       break;
      case FNT4:
       do_fnt4();
       break;
      case XXX1:
       do_xxx1();
       break;
      case XXX2:
       do_xxx2();
       break;
      case XXX3:
       do_xxx3();
       break;
      case XXX4:
       do_xxx4();
       break;
      case FNT_DEF1:
       do_fntdef1();
       break;
      case FNT_DEF2:
       do_fntdef2();
       break;
      case FNT_DEF3:
       do_fntdef3();
       break;
      case FNT_DEF4:
       do_fntdef4();
       break;
      case PRE:
      case POST:
      case POST_POST:
       ERROR("Unexpected preamble or postamble in dvi file");
       break;
      default:
       ERROR("Unexpected opcode or DVI file ended prematurely");
      }
  }
}

Here is the caller graph for this function:

Definition at line 416 of file dvi.c.

{
  dvi_state.v += y;
}

Here is the caller graph for this function:

error_t dvi_init ( char *  dvi_filename,
char *  pdf_filename,
double  mag,
double  x_offset,
double  y_offset 
)

Definition at line 1160 of file dvi.c.

{
  if (!(dvi_file = MFOPEN (dvi_filename, FOPEN_RBIN_MODE))) {
    ERROR ("dvi_init:  Specified DVI file doesn't exist");
    return (FATAL_ERROR);
  }
  /* DVI files are most easily read backwards by searching
     for post_post and then post opcode */
  find_post ();
  get_dvi_info();
  do_scales(mag);
  dev_init(dvi2pts, x_offset, y_offset);
  get_page_info();
  pdf_doc_init (pdf_filename);
  get_comment();
  get_dvi_fonts();
  clear_state();
  return (NO_ERROR);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dvi_locate_font ( char *  tex_name,
spt_t  ptsize 
)

Definition at line 356 of file dvi.c.

{
  int thisfont;
  int font_id;
  if (debug) {
    fprintf (stderr, "dvi_locate_font: fontname: (%s) ptsize: %ld, dvi_id: %d\n",
            tex_name, ptsize, num_loaded_fonts);
  }
  if (verbose)
    fprintf (stderr, "<%s@%.2fpt", tex_name, ptsize*dvi2pts);
  need_more_fonts (1);
  /* This routine needs to be recursive/reentrant.  Load current high water
     mark into an automatic variable  */
  thisfont = num_loaded_fonts++;
  loaded_fonts[thisfont].tfm_id = tfm_open (tex_name);
  loaded_fonts[thisfont].source = VF; /* This will be reset later if 
                                 it was really generated by the
                                 dvi file */
  font_id = vf_locate_font (tex_name, ptsize);
  loaded_fonts[thisfont].font_id = font_id;
  if (loaded_fonts[thisfont].font_id >= 0) {
    if (verbose)
      fprintf (stderr, "(VF)");
    loaded_fonts[thisfont].type = VIRTUAL;
  } else {
    loaded_fonts[thisfont].type = PHYSICAL;
    font_id = dev_locate_font (tex_name, ptsize);
    loaded_fonts[thisfont].font_id = font_id;
    if (loaded_fonts[thisfont].font_id < 0) {
      fprintf (stderr, "%s: Can't locate a Type 1, TTF, PK, or virtual font file\n", tex_name);
      ERROR ("Not sure how to proceed.  For now this is fatal\n\
Maybe in the future, I'll substitute some other font.");
    }
  }
  loaded_fonts[thisfont].size = ptsize;
  if (verbose)
    fprintf (stderr, ">");
  return (thisfont);
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned dvi_npages ( void  )

Definition at line 110 of file dvi.c.

{
  return num_pages;
}

Here is the caller graph for this function:

void dvi_pop ( void  )

Definition at line 600 of file dvi.c.

{
  if (debug) {
    fprintf (stderr, "Popping off stack of depth %d\n",
            dvi_stack_depth);
  }
  if (dvi_stack_depth > 0) {
    dvi_state = dvi_stack[--dvi_stack_depth];
  } else
    ERROR ("dvi_pop: Tried to pop an empty stack");
  do_moveto (dvi_state.h, dvi_state.v);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 587 of file dvi.c.

{
  if (debug) {
    fprintf (stderr, "Pushing onto stack of depth %d\n",
            dvi_stack_depth);
  }
  if (dvi_stack_depth < DVI_MAX_STACK_DEPTH) {
    dvi_stack[dvi_stack_depth++] = dvi_state;
  }
  else
    ERROR ("DVI stack exceeded");
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 502 of file dvi.c.

{
  spt_t width, height = 0, depth = 0;
  struct loaded_font *p;
  unsigned char lch;
  if (current_font < 0) {
    ERROR ("dvi_put:  No font selected");
  }
  p = loaded_fonts+current_font;
  switch (p->type) {
  case PHYSICAL:
    width = tfm_get_fw_width (p->tfm_id, ch);
    width = sqxfw (p->size, width);
    /* Treat a single character as a one byte string and use the
       string routine.  The possibly multi-byte character must
       be converted to a single-byte string */
    if (ch > 255) {
      ERROR ("Tried to set a multibyte character in a non-virtual font");
    }
    lch = (unsigned char) ch;
    dev_set_string (dvi_state.h, -dvi_state.v, &lch, 1, width, p->font_id);
    if (compute_boxes) {
      height = tfm_get_fw_height (p->tfm_id, ch);
      depth = tfm_get_fw_depth (p->tfm_id, ch);
      height = sqxfw (p->size, height);
      depth = sqxfw (p->size, depth);
      dev_expand_box (width, height, depth);
    }
    break;
  case VIRTUAL:    
    vf_set_char (ch, p->font_id);
    break;
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 411 of file dvi.c.

{
  dvi_state.h += x;
}

Here is the caller graph for this function:

void dvi_rule ( SIGNED_QUAD  width,
SIGNED_QUAD  height 
)

Definition at line 539 of file dvi.c.

{
  do_moveto (dvi_state.h, dvi_state.v);
  dev_rule (dvi_state.h, -dvi_state.v,
           width, height);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 461 of file dvi.c.

{
  spt_t width, height = 0, depth = 0;
  struct loaded_font *p;
  unsigned char lch;
  if (current_font < 0) {
    ERROR ("dvi_set:  No font selected");
  }
  /* The division by dvi2pts seems strange since we actually know the
     "dvi" size of the fonts contained in the DVI file.  In other
     words, we converted from DVI units to pts and back again!
     The problem comes from fonts defined in VF files where we don't know the DVI
     size.  It's keeping me sane to keep *point sizes* of *all* fonts in
     the dev.c file and convert them back if necessary */ 
  p = loaded_fonts+current_font;
  width = tfm_get_fw_width (p->tfm_id, ch);
  width = sqxfw (p->size, width);
  switch (p->type) {
  case PHYSICAL:
    if (ch > 255) {
      ERROR ("Tried to set a multibyte character in a non-virtual font");
    }
    lch = (unsigned char) ch;
    dev_set_string (dvi_state.h, -dvi_state.v, &lch, 1, width, p->font_id);
    if (compute_boxes) {
      height = tfm_get_fw_height (p->tfm_id, ch);
      depth = tfm_get_fw_depth (p->tfm_id, ch);
      height = sqxfw (p->size, height);
      depth = sqxfw (p->size, depth);
      dev_expand_box (width, height, depth);
    }
    break;
  case VIRTUAL:
    {
      vf_set_char (ch, p->font_id);
      break;
    }
  }
  dvi_state.h += width;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 105 of file dvi.c.

{
  debug = 1;
}
void dvi_set_font ( int  font_id)

Definition at line 816 of file dvi.c.

Here is the caller graph for this function:

Definition at line 93 of file dvi.c.

{
  if (verbose < 255) {
  verbose += 1;
  }
}

Here is the caller graph for this function:

double dvi_tell_mag ( void  )

Definition at line 188 of file dvi.c.

{
  return total_mag;
}

Here is the caller graph for this function:

double dvi_unit_size ( void  )

Definition at line 351 of file dvi.c.

{
  return dvi2pts;
}

Here is the caller graph for this function:

Definition at line 1231 of file dvi.c.

{
  dvi_pop();
  if (num_saved_fonts > 0) 
    current_font = saved_dvi_font[--num_saved_fonts];
  else
    ERROR ("Tried to pop an empty font stack");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dvi_vf_init ( int  dev_font_id)

Definition at line 1218 of file dvi.c.

{
  dvi_push ();
  dvi_state.w = 0; dvi_state.x = 0;
  dvi_state.y = 0; dvi_state.z = 0;
  if (num_saved_fonts < MAX_VF_NESTING) {
    saved_dvi_font[num_saved_fonts++] = current_font;
  } else
    ERROR ("Virtual fonts nested too deeply!");
  current_font = dev_font_id;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 634 of file dvi.c.

{
  dvi_state.w = ch;
  dvi_right (ch);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dvi_w0 ( void  )

Definition at line 640 of file dvi.c.

{
  dvi_right (dvi_state.w);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 665 of file dvi.c.

{
  dvi_state.x = ch;
  dvi_right (ch);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dvi_x0 ( void  )

Definition at line 671 of file dvi.c.

{
  dvi_right (dvi_state.x);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 716 of file dvi.c.

{
  dvi_state.y = ch;
  dvi_down (ch);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dvi_y0 ( void  )

Definition at line 722 of file dvi.c.

{
  dvi_down (dvi_state.y);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 747 of file dvi.c.

{
  dvi_state.z = ch;
  dvi_down (ch);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dvi_z0 ( void  )

Definition at line 753 of file dvi.c.

{
  dvi_down (dvi_state.z);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void find_post ( void  ) [static]

Definition at line 123 of file dvi.c.

{
  long current;
  int read_byte;

  /* First find end of file */  
  dvi_file_size = file_size (dvi_file);
  current = dvi_file_size;
 
  /* Scan backwards through PADDING */  
  do {
     current -= 1;
     seek_absolute (dvi_file, current);

  } while ((read_byte = fgetc(dvi_file)) == PADDING &&
          current > 0);

  /* file_position now points to last non padding character or beginning of file */
  if (dvi_file_size - current < 4 ||
      current == 0 || read_byte != DVI_ID) {
    fprintf (stderr, "DVI ID = %d\n", read_byte);
    invalid_signature();
  } 

  /* Make sure post_post is really there */
  current = current - 5;
  seek_absolute (dvi_file, current);
  if ((read_byte = fgetc(dvi_file)) != POST_POST) {
     fprintf (stderr, "Found %d where post_post opcode should be\n", read_byte);
     invalid_signature();
  }
  current = get_signed_quad (dvi_file);
  seek_absolute (dvi_file, current);
  if ((read_byte = fgetc(dvi_file)) != POST) {
     fprintf (stderr, "Found %d where post_post opcode should be\n", read_byte);
     invalid_signature();
  }
  post_location = current;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void get_a_font_record ( SIGNED_QUAD  tex_id) [static]

Definition at line 239 of file dvi.c.

{
  UNSIGNED_BYTE dir_length, name_length;
  UNSIGNED_QUAD checksum, size, design_size;
  char *directory, *name;
  if (debug) {
    fprintf (stderr, "get_a_font_record: tex_id = %ld\n", tex_id);
  }
  if (num_def_fonts >= max_def_fonts) {
    max_def_fonts += MAX_FONTS;
    def_fonts = RENEW (def_fonts, max_def_fonts, struct font_def);
  }
  checksum = get_unsigned_quad (dvi_file);
  size = get_unsigned_quad (dvi_file);
  design_size = get_unsigned_quad (dvi_file);
  dir_length = get_unsigned_byte (dvi_file);
  name_length = get_unsigned_byte (dvi_file);
  directory = NEW (dir_length+1, char);
  if (fread (directory, 1, dir_length, dvi_file) !=
      dir_length) {
    invalid_signature();
  }
  name = NEW (name_length+1, char);
  if (fread (name, 1, name_length, dvi_file) !=
      name_length) {
    invalid_signature();
  }
  directory[dir_length] = 0;
  RELEASE (directory);
  name[name_length] = 0;
  def_fonts[num_def_fonts].name = name;
  def_fonts[num_def_fonts].size = size;
  def_fonts[num_def_fonts].tex_id = tex_id;
  def_fonts[num_def_fonts].used = 0;
  num_def_fonts +=1;
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 309 of file dvi.c.

{
  UNSIGNED_BYTE length;
  static char dvi_comment[257];
  seek_absolute (dvi_file, 14);
  length = get_unsigned_byte(dvi_file);
  if (fread (dvi_comment, 1, length, dvi_file) != length) {
    invalid_signature();
  }
  dvi_comment[length] = 0;
  if (verbose) {
    fprintf (stderr, "DVI Comment: %s\n", dvi_comment);
  }
  dev_add_comment (dvi_comment);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void get_dvi_fonts ( void  ) [static]

Definition at line 277 of file dvi.c.

{
  UNSIGNED_BYTE code;
  SIGNED_QUAD tex_id;
  seek_absolute (dvi_file, post_location+29);
  while ((code = get_unsigned_byte(dvi_file)) != POST_POST) {
    switch (code)
      {
      case FNT_DEF1:
       tex_id = get_unsigned_byte (dvi_file);
       break;
      case FNT_DEF2:
       tex_id = get_unsigned_pair (dvi_file);
       break;
      case FNT_DEF3:
       tex_id = get_unsigned_triple (dvi_file);
       break;
      case FNT_DEF4:
       tex_id = get_signed_quad (dvi_file);
       break;
      default:
       fprintf (stderr, "Unexpected op code: %3d\n", code);
       invalid_signature();
      }
    get_a_font_record(tex_id);
  }
  if (verbose>2) {
    dump_font_info();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void get_dvi_info ( void  ) [static]

Definition at line 201 of file dvi.c.

{
  seek_absolute (dvi_file, post_location+5);
  dvi_unit_num = get_unsigned_quad(dvi_file);
  dvi_unit_den = get_unsigned_quad(dvi_file);
  dvi_mag = get_unsigned_quad(dvi_file);
  media_height = get_unsigned_quad(dvi_file);
  media_width = get_unsigned_quad(dvi_file);
  stackdepth = get_unsigned_pair(dvi_file);
  if (stackdepth > DVI_MAX_STACK_DEPTH) {
    fprintf (stderr, "DVI needs stack depth of %d,", stackdepth);
    fprintf (stderr, "but MAX_DVI_STACK_DEPTH is %d", DVI_MAX_STACK_DEPTH);
    ERROR ("Capacity exceeded.");
  }

  if (verbose > 2) {
    fprintf (stderr, "DVI File Info\n");
    fprintf (stderr, "Unit: %ld / %ld\n", dvi_unit_num, dvi_unit_den);
    fprintf (stderr, "Mag: %ld\n", dvi_mag);
    fprintf (stderr, "Media Height: %ld\n", media_height);
    fprintf (stderr, "Media Width: %ld\n", media_width);
    fprintf (stderr, "Stack Depth: %d\n", stackdepth);
  }
  
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void get_page_info ( void  ) [static]

Definition at line 163 of file dvi.c.

{
  int i;
  seek_absolute (dvi_file, post_location+27);
  num_pages = get_unsigned_pair (dvi_file);
  if (verbose > 2) {
    fprintf (stderr, "Page count:\t %4d\n", num_pages);
  }
  if (num_pages == 0) {
    ERROR ("dvi_init:  Page count is 0!");
  }
  page_loc = NEW (num_pages, unsigned long);
  seek_absolute (dvi_file, post_location+1);
  page_loc[num_pages-1] = get_unsigned_quad(dvi_file);
  range_check_loc(page_loc[num_pages-1]+41);
  for (i=num_pages-2; i>=0; i--) {
    seek_absolute (dvi_file, page_loc[i+1]+41);
    page_loc[i] = get_unsigned_quad(dvi_file);
    range_check_loc(page_loc[num_pages-1]+41);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void invalid_signature ( ) [static]

Definition at line 115 of file dvi.c.

{
  ERROR ("dvi_init:  Something is wrong.  Are you sure this is a DVI file?\n");
}

Here is the caller graph for this function:

static void need_more_fonts ( unsigned  n) [static]

Definition at line 69 of file dvi.c.

Here is the caller graph for this function:


Variable Documentation

unsigned char compute_boxes = 0 [static]

Definition at line 91 of file dvi.c.

int current_font [static]

Definition at line 338 of file dvi.c.

char debug = 0 [static]

Definition at line 46 of file dvi.c.

struct font_def * def_fonts
double dvi2pts = 0.0 [static]

Definition at line 186 of file dvi.c.

FILE* dvi_file [static]

Definition at line 45 of file dvi.c.

unsigned long dvi_file_size [static]

Definition at line 49 of file dvi.c.

Definition at line 52 of file dvi.c.

static struct dvi_registers [static]

Definition at line 336 of file dvi.c.

unsigned dvi_stack_depth = 0 [static]

Definition at line 339 of file dvi.c.

Definition at line 52 of file dvi.c.

Definition at line 52 of file dvi.c.

unsigned max_def_fonts = 0 [static]

Definition at line 87 of file dvi.c.

unsigned max_loaded_fonts = 0 [static]

Definition at line 47 of file dvi.c.

Definition at line 51 of file dvi.c.

Definition at line 51 of file dvi.c.

unsigned num_def_fonts = 0 [static]

Definition at line 87 of file dvi.c.

unsigned num_loaded_fonts = 0 [static]

Definition at line 47 of file dvi.c.

UNSIGNED_PAIR num_pages = 0 [static]

Definition at line 50 of file dvi.c.

int num_saved_fonts = 0 [static]

Definition at line 1216 of file dvi.c.

unsigned long* page_loc = NULL [static]

Definition at line 48 of file dvi.c.

unsigned long post_location [static]

Definition at line 49 of file dvi.c.

int processing_page = 0 [static]

Definition at line 340 of file dvi.c.

unsigned char s_buffer[S_BUFFER_SIZE] [static]

Definition at line 945 of file dvi.c.

unsigned s_len = 0 [static]

Definition at line 946 of file dvi.c.

Definition at line 1215 of file dvi.c.

unsigned stackdepth [static]

Definition at line 47 of file dvi.c.

double total_mag = 1.0 [static]

Definition at line 186 of file dvi.c.

unsigned char verbose = 0 [static]

Definition at line 89 of file dvi.c.