Back to index

tetex-bin  3.0
Classes | Defines | Functions | Variables
pdfdev.c File Reference
#include "config.h"
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "system.h"
#include "mem.h"
#include "error.h"
#include "mfileio.h"
#include "numbers.h"
#include "dvi.h"
#include "tfm.h"
#include "pdfdev.h"
#include "pdfdoc.h"
#include "pdfobj.h"
#include "type1.h"
#include "ttf.h"
#include "pkfont.h"
#include "pdfspecial.h"
#include "pdfparse.h"
#include "tpic.h"
#include "htex.h"
#include "mpost.h"
#include "psspecial.h"
#include "colorsp.h"
#include "pdflimits.h"
#include "twiddle.h"
#include "encodings.h"
#include "colors.h"

Go to the source code of this file.

Classes

struct  dev_font
struct  map_record
struct  color

Defines

#define GRAPHICS_MODE   1
#define TEXT_MODE   2
#define STRING_MODE   3
#define FORMAT_BUF_SIZE   4096
#define PDF_U   65800L /* Number of DVI units in a PDF unit */
#define CENTI_PDF_U   658 /* Number of DVI units in a centi PDF unit */
#define PHYSICAL   1
#define VIRTUAL   2
#define TYPE1   1
#define PK   2
#define TRUETYPE   3
#define DEFAULT_MAP_FILE   "dvipdfm.map"
#define GRAY   1
#define RGB   2
#define CMYK   3

Functions

static void dev_clear_color_stack (void)
static void dev_clear_xform_stack (void)
void dev_set_page_size (double width, double height)
double dev_page_width (void)
double dev_page_height (void)
void dev_set_verbose (void)
void dev_set_debug (void)
double pdf_dev_scale (void)
void dev_fonts_need (unsigned n)
static void font_maps_need (int n)
static void init_map_record (struct map_record *r)
static void release_map_record (struct map_record *r)
static void fill_in_defaults (struct map_record *this_map_record)
void dev_read_mapfile (char *filename)
struct map_recordget_map_record (const char *tex_name)
static void reset_text_state (void)
static void text_mode (void)
void graphics_mode (void)
static void string_mode (spt_t xpos, spt_t ypos, double slant, double extend)
static void dev_set_font (int font_id)
void dev_set_string (spt_t xpos, spt_t ypos, unsigned char *s, int length, spt_t width, int font_id)
void dev_init (double scale, double x_offset, double y_offset)
void dev_close (void)
void dev_add_comment (char *comment)
struct color color_by_name (char *s)
static void fill_page (void)
void dev_bg_rgb_color (double r, double g, double b)
void dev_bg_cmyk_color (double c, double m, double y, double k)
void dev_bg_gray (double value)
void dev_bg_named_color (char *s)
static void dev_set_color (struct color color)
void dev_do_color (void)
void dev_set_def_rgb_color (double r, double g, double b)
void dev_set_def_gray (double g)
void dev_set_def_named_color (char *s)
void dev_set_def_cmyk_color (double c, double m, double y, double k)
void dev_begin_named_color (char *s)
void dev_begin_rgb_color (double r, double g, double b)
void dev_begin_cmyk_color (double c, double m, double y, double k)
void dev_begin_gray (double value)
void dev_end_color (void)
void dev_begin_xform (double xscale, double yscale, double rotate, double x_user, double y_user)
void dev_end_xform (void)
int dev_xform_depth (void)
void dev_close_all_xforms (int depth)
void dev_reselect_font (void)
static void bop_font_reset (void)
void dev_bop (void)
void dev_eop (void)
int dev_locate_font (const char *tex_name, spt_t ptsize)
void dev_close_all_fonts (void)
void dev_rule (spt_t xpos, spt_t ypos, spt_t width, spt_t height)
double dev_phys_x (void)
double dev_phys_y (void)
static int src_special (char *buffer, UNSIGNED_QUAD size)
void dev_do_special (void *buffer, UNSIGNED_QUAD size, spt_t x_user, spt_t y_user)
void dev_link_annot (unsigned char flag)
void dev_stack_depth (unsigned int depth)
void dev_tag_depth (void)
void dev_untag_depth (void)
void dev_expand_box (spt_t width, spt_t height, spt_t depth)

Variables

double hoffset = 72.0
double voffset = 72.0
static double dvi2pts = 0.0
static double page_width = 612.0
static double page_height = 792.0
int page_size_readonly = 0
static int debug = 0
static int verbose = 0
int motion_state = GRAPHICS_MODE
static char format_buffer [FORMAT_BUF_SIZE]
static spt_t text_xorigin = 0
static spt_t text_yorigin = 0
static spt_t text_offset = 0
double text_slant = 0.0
double text_extend = 1.0
unsigned num_dev_fonts = 0
unsigned num_phys_fonts = 0
int current_font = -1
static struct dev_fontdev_font
static unsigned max_device_fonts = 0
struct map_recordfont_map
unsigned int num_font_map = 0
unsigned int max_font_map = 0
struct color colorstack [MAX_COLORS]
struct color background [MAX_COLORS]
struct color default_color [MAX_COLORS]
static int num_colors = 0
static int num_transforms = 0
static unsigned dvi_stack_depth = 0
static int dvi_tagged_depth = -1
static unsigned char link_annot = 1

Class Documentation

struct dev_font

Definition at line 170 of file pdfdev.c.

Collaboration diagram for dev_font:
Class Members
double extend
pdf_obj * font_resource
unsigned char format
int remap
char short_name
double slant
spt_t sptsize
char * tex_name
char * used_chars
unsigned char used_on_this_page
struct map_record

Definition at line 192 of file pdfdev.c.

Class Members
char * enc_name
double extend
char * font_name
int remap
double slant
char * tex_name
struct color

Definition at line 612 of file pdfdev.c.

Class Members
double c1
double c2
double c3
double c4
int colortype

Define Documentation

#define CENTI_PDF_U   658 /* Number of DVI units in a centi PDF unit */

Definition at line 136 of file pdfdev.c.

#define CMYK   3

Definition at line 611 of file pdfdev.c.

#define DEFAULT_MAP_FILE   "dvipdfm.map"

Definition at line 168 of file pdfdev.c.

#define FORMAT_BUF_SIZE   4096

Definition at line 110 of file pdfdev.c.

#define GRAPHICS_MODE   1

Definition at line 104 of file pdfdev.c.

#define GRAY   1

Definition at line 609 of file pdfdev.c.

#define PDF_U   65800L /* Number of DVI units in a PDF unit */

Definition at line 135 of file pdfdev.c.

#define PHYSICAL   1

Definition at line 161 of file pdfdev.c.

#define PK   2

Definition at line 165 of file pdfdev.c.

#define RGB   2

Definition at line 610 of file pdfdev.c.

#define STRING_MODE   3

Definition at line 106 of file pdfdev.c.

#define TEXT_MODE   2

Definition at line 105 of file pdfdev.c.

#define TRUETYPE   3

Definition at line 166 of file pdfdev.c.

#define TYPE1   1

Definition at line 164 of file pdfdev.c.

#define VIRTUAL   2

Definition at line 162 of file pdfdev.c.


Function Documentation

static void bop_font_reset ( void  ) [static]

Definition at line 961 of file pdfdev.c.

Here is the call graph for this function:

Here is the caller graph for this function:

struct color color_by_name ( char *  s) [read]

Definition at line 620 of file pdfdev.c.

{
  int i;
  struct color result;
  for (i=0; i<sizeof(colors_by_name)/sizeof(colors_by_name[0]); i++) {
    if (!strcmp (s, colors_by_name[i].name)) {
      break;
    }
  }
  if (i == sizeof(colors_by_name)/sizeof(colors_by_name[0])) {
    fprintf (stderr, "Color \"%s\" no known.  Using \"Black\" instead.\n", s);
    result = default_color;
  } else {
    result = colors_by_name[i].color;
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_add_comment ( char *  comment)

Definition at line 599 of file pdfdev.c.

{
  pdf_doc_creator (comment);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_begin_cmyk_color ( double  c,
double  m,
double  y,
double  k 
)

Definition at line 844 of file pdfdev.c.

{
  if (num_colors >= MAX_COLORS) {
    fprintf (stderr, "\ndev_set_color:  Exceeded depth of color stack\n");
    return;
  }
  colorstack[num_colors].c1 = c;
  colorstack[num_colors].c2 = m;
  colorstack[num_colors].c3 = y;
  colorstack[num_colors].c4 = k;
  colorstack[num_colors].colortype = CMYK;
  num_colors+= 1;
  dev_do_color();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_begin_gray ( double  value)

Definition at line 859 of file pdfdev.c.

{
  if (num_colors >= MAX_COLORS) {
    fprintf (stderr, "\ndev_begin_gray:  Exceeded depth of color stack\n");
    return;
  }
  colorstack[num_colors].c1 = value;
  colorstack[num_colors].colortype = GRAY;
  num_colors+= 1;
  dev_do_color();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_begin_named_color ( char *  s)

Definition at line 813 of file pdfdev.c.

{
  struct color color = color_by_name (s);
  switch (color.colortype) {
  case GRAY:
    dev_begin_gray (color.c1);
    break;
  case RGB:
    dev_begin_rgb_color (color.c1, color.c2, color.c3);
    break;
  case CMYK:
    dev_begin_cmyk_color (color.c1, color.c2, color.c3, color.c4);
    break;
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_begin_rgb_color ( double  r,
double  g,
double  b 
)

Definition at line 830 of file pdfdev.c.

{
  if (num_colors >= MAX_COLORS) {
    fprintf (stderr, "\ndev_set_color:  Exceeded depth of color stack\n");
    return;
  }
  colorstack[num_colors].c1 = r;
  colorstack[num_colors].c2 = g;
  colorstack[num_colors].c3 = b;
  colorstack[num_colors].colortype = RGB;
  num_colors+= 1;
  dev_do_color();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_begin_xform ( double  xscale,
double  yscale,
double  rotate,
double  x_user,
double  y_user 
)

Definition at line 889 of file pdfdev.c.

{
  double c, s;
  if (num_transforms >= MAX_TRANSFORMS) {
    fprintf (stderr, "\ndev_begin_xform:  Exceeded depth of transformation stack\n");
    return;
  }
  c = ROUND (cos(rotate),1e-5);
  s = ROUND (sin(rotate),1e-5);
  sprintf (work_buffer, " q %g %g %g %g %.2f %.2f cm",
          xscale*c, xscale*s, -yscale*s, yscale*c,
          (1.0-xscale*c)*x_user+yscale*s*y_user,
          -xscale*s*x_user+(1.0-yscale*c)*y_user);
  pdf_doc_add_to_page (work_buffer, strlen(work_buffer));
  num_transforms += 1;
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_bg_cmyk_color ( double  c,
double  m,
double  y,
double  k 
)

Definition at line 677 of file pdfdev.c.

{
  background.colortype = CMYK;
  background.c1 = c;
  background.c2 = m;
  background.c3 = y;
  background.c4 = k;
  return;
}

Here is the caller graph for this function:

void dev_bg_gray ( double  value)

Definition at line 687 of file pdfdev.c.

{
  background.colortype = GRAY;
  background.c1 = value;
  return;
}

Here is the caller graph for this function:

void dev_bg_named_color ( char *  s)

Definition at line 694 of file pdfdev.c.

{
  struct color color = color_by_name (s);
  switch (color.colortype) {
  case GRAY:
    dev_bg_gray (color.c1);
    break;
  case RGB:
    dev_bg_rgb_color (color.c1, color.c2, color.c3);
    break;
  case CMYK:
    dev_bg_cmyk_color (color.c1, color.c2, color.c3, color.c4);
    break;
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_bg_rgb_color ( double  r,
double  g,
double  b 
)

Definition at line 668 of file pdfdev.c.

{
  background.colortype = RGB;
  background.c1 = r;
  background.c2 = g;
  background.c3 = b;
  return;
}

Here is the caller graph for this function:

void dev_bop ( void  )

Definition at line 966 of file pdfdev.c.

{
#ifdef MEM_DEBUG
MEM_START
#endif
  if (debug) {
    fprintf (stderr, "dev_bop:\n");
  }
  pdf_doc_new_page ();
  graphics_mode();
  {
    text_slant = 0.0;
    text_extend = 1.0;
  }
  bop_font_reset();
  /* This shouldn't be necessary because line widths are now
     explicitly set for each rule */
  /*  pdf_doc_add_to_page ("0 w", 3); */
  dev_do_color(); /* Set text color since new page loses color state */
#ifdef MEM_DEBUG
MEM_END
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void dev_clear_color_stack ( void  ) [static]

Definition at line 711 of file pdfdev.c.

{
  num_colors = 0;
  return;
}

Here is the caller graph for this function:

static void dev_clear_xform_stack ( void  ) [static]

Definition at line 883 of file pdfdev.c.

{
  num_transforms = 0;
  return;
}

Here is the caller graph for this function:

Definition at line 591 of file pdfdev.c.

{
  /* Set page origin now that user has had plenty of time
     to set page size */
  pdf_doc_set_origin((double) hoffset, (double)
                   dev_page_height()-voffset);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1161 of file pdfdev.c.

{
  int i;
  for (i=0; i<num_dev_fonts; i++) {
    pdf_release_obj (dev_font[i].font_resource);
    RELEASE (dev_font[i].tex_name);
  }
  if (dev_font)
    RELEASE (dev_font);

  /* Release all map entries */
  for (i=0; i<num_font_map; i++) {
    release_map_record (font_map+i);
  }

  if (font_map)
    RELEASE (font_map);
  /* Close the various font handlers */
  type1_close_all();
  pk_close_all();
#ifdef HAVE_TTF_FORMATS   
  ttf_close_all();
#endif   

  /* Now do encodings. */
  encoding_flush_all();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 930 of file pdfdev.c.

{
  if (num_transforms > depth) {
    fprintf (stderr, "\nspecial: Closing pending transformations at end of page/XObject\n");
    while (num_transforms > depth) {
      num_transforms -= 1;
      pdf_doc_add_to_page (" Q", 2);
    }
    dev_reselect_font();
    dev_do_color();
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 757 of file pdfdev.c.

{
  if (num_colors == 0) {
    dev_set_color (default_color);
  } else {
    dev_set_color (colorstack[num_colors-1]);
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_do_special ( void buffer,
UNSIGNED_QUAD  size,
spt_t  x_user,
spt_t  y_user 
)

Definition at line 1259 of file pdfdev.c.

{
  double dev_xuser, dev_yuser;
  dev_xuser = ((double) x_user) / ((double) PDF_U);
  dev_yuser = ((double) -y_user) / ((double) PDF_U);
  graphics_mode();
  if (!pdf_parse_special (buffer, size, dev_xuser, dev_yuser) &&
      !tpic_parse_special (buffer, size, dev_xuser, dev_yuser) &&
      !htex_parse_special (buffer, size) &&
      !color_special (buffer, size) &&
      !ps_parse_special (buffer, size, dev_xuser, dev_yuser) &&
      !src_special (buffer, size)) {
    fprintf (stderr, "\nUnrecognized special ignored");
    dump (buffer, ((char *)buffer)+size);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 871 of file pdfdev.c.

{
  if (num_colors <= 0) {
    fprintf (stderr, "\ndev_set_color:  End color with no corresponding begin color\n");
    return;
  }
  num_colors -= 1;
  dev_do_color();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 908 of file pdfdev.c.

{
  if (num_transforms <= 0) {
    fprintf (stderr, "\ndev_end_xform:  End transform with no corresponding begin\n");
    return;
  }
  pdf_doc_add_to_page (" Q", 2);
  num_transforms -= 1;
  /* Unfortunately, the following two lines are necessary in case of a font or color
     change inside of the save/restore pair.  Anything that was done
     there must be redone, so in effect, we make no assumptions about
     what fonts. We act like we are starting a new page */
  dev_reselect_font();
  dev_do_color();
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_eop ( void  )

Definition at line 990 of file pdfdev.c.

{
#ifdef MEM_DEBUG
MEM_START
#endif
  if (debug) {
    fprintf (stderr, "dev_eop:\n");
  }
  graphics_mode();
  dev_close_all_xforms(0);
  fill_page();
  pdf_doc_finish_page ();
  /* Finish any pending PS specials */
  mp_eop_cleanup();
#ifdef MEM_DEBUG
MEM_END
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_expand_box ( spt_t  width,
spt_t  height,
spt_t  depth 
)

Definition at line 1318 of file pdfdev.c.

{
  double phys_width, phys_height, phys_depth, scale;
  if (link_annot && dvi_stack_depth >= dvi_tagged_depth) {
    scale = dvi2pts*dvi_tell_mag();
    phys_width = scale*width;
    phys_height = scale*height;
    phys_depth = scale*depth;
    pdf_doc_expand_box (dev_phys_x(), dev_phys_y()-phys_depth,
                     dev_phys_x()+phys_width,
                     dev_phys_y()+phys_height);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_fonts_need ( unsigned  n)

Definition at line 184 of file pdfdev.c.

Here is the caller graph for this function:

void dev_init ( double  scale,
double  x_offset,
double  y_offset 
)

Definition at line 580 of file pdfdev.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_link_annot ( unsigned char  flag)

Definition at line 1281 of file pdfdev.c.

Here is the caller graph for this function:

int dev_locate_font ( const char *  tex_name,
spt_t  ptsize 
)

Definition at line 1009 of file pdfdev.c.

{
  int i;
  int this_font;

  if (ptsize == 0) {
    ERROR ("locate_dev_font() called with ptsize = 0");
  }
  /* Make sure we have room for a new one, even though we
     may not actually create one */
  dev_fonts_need (num_dev_fonts+1);
  this_font = num_dev_fonts;
  
  for (i=0; i<this_font; i++) {
    /* PK must match in name and size to resolve to the same device
       font */
    if (dev_font[i].tex_name &&
       strcmp (tex_name, dev_font[i].tex_name) == 0 &&
       dev_font[i].sptsize == ptsize &&
       dev_font[i].format == PK)
      break;
    /* Scaleable fonts must match in name; however, this routine
       must return a different id if the ptsize is different */
    if (dev_font[i].tex_name &&
       strcmp (tex_name, dev_font[i].tex_name) == 0 &&
       dev_font[i].format != PK)
      break;
  }
  if (i == this_font) { /* There is no physical font we can use */
    struct map_record *map_record;
    int font_id = -1, font_format = -1, tfm_id = -1, encoding_id = -1;
    int remap = 0;
    double extend= 1.0, slant = 0.0;
    const char *font_name;
    char short_name[7];
    /* Get appropriate info from map file (yes, PK fonts at two
       different point sizes would be looked up twice unecessarily) */
    if ((map_record = get_map_record (tex_name))) {
      remap = map_record -> remap;
      slant = map_record -> slant;
      extend = map_record -> extend;
      font_name = map_record -> font_name;
    } else {
      font_name = tex_name;
    }
    if (verbose>1){
      if (map_record) {
       fprintf (stderr, "\nfontmap: %s -> %s", tex_name,
               map_record->font_name);
       if (map_record->enc_name)
         fprintf (stderr, "(%s)", map_record->enc_name);
       if (map_record->slant)
         fprintf (stderr, "[slant=%g]", map_record->slant);
       if (map_record->extend != 1.0)
         fprintf (stderr, "[extend=%g]", map_record->extend);
       if (map_record->remap)
         fprintf (stderr, "[remap]");
       fprintf (stderr, "\n");
      } else {
       fprintf (stderr, "\nfontmap: %s (no map)\n", tex_name);
      }
    }
    /* If this font has an encoding specified on the record, get its id */
    if (map_record && map_record -> enc_name != NULL) {
      encoding_id = get_encoding (map_record -> enc_name);
    } else { /* Otherwise set the encoding_id to -1 */
      encoding_id = -1;
    }
    tfm_id = tfm_open (tex_name);
    /* We assume, for now that we will find this as a physical font,
       as opposed to a vf, so we need a device name to tell the
       lower-level routines what we want this to be called.  We'll
       blast this name away later if we don't need it. */
    short_name[0] = 'F';
    inttoa (short_name+1, num_phys_fonts+1);
    if ((font_id = type1_font (font_name, tfm_id,
                            short_name, encoding_id, remap))>=0) {
      font_format = TYPE1;
#ifdef HAVE_TTF_FORMATS
    } else if ((font_id = ttf_font (font_name, tfm_id,
                                short_name, encoding_id, remap))>=0) {
      font_format = TRUETYPE;
#endif /* HAVE_TTF_FORMATS */
    } else if ((font_id = pk_font (font_name, ptsize*dvi2pts,
                               tfm_id,
                               short_name))>=0) {
      font_format = PK;
    }
    if (font_format >= 0) { /* This is a new physical font and we found a physical
                            font we can use */
      strcpy (dev_font[this_font].short_name, short_name);
      dev_font[this_font].tex_name = NEW (strlen (tex_name)+1, char);
      strcpy (dev_font[this_font].tex_name, tex_name);
      dev_font[this_font].sptsize = ptsize;
      dev_font[this_font].format = font_format;
      dev_font[this_font].slant = slant;
      dev_font[this_font].extend = extend;
      dev_font[this_font].remap = remap;
      dev_font[this_font].used_on_this_page = 0;
      switch (font_format) {
      case TYPE1:
       dev_font[this_font].font_resource =
         type1_font_resource(font_id);
       dev_font[this_font].used_chars = type1_font_used(font_id);
       break;
#ifdef HAVE_TTF_FORMATS
      case TRUETYPE:
       dev_font[this_font].font_resource =
         ttf_font_resource(font_id);
       dev_font[this_font].used_chars = ttf_font_used(font_id);
       break;
#endif /* HAVE_TTF_FORMATS */
      case PK:
       dev_font[this_font].font_resource = pk_font_resource (font_id);
       dev_font[this_font].used_chars = pk_font_used(font_id);
       break;
      default:
       ERROR ("Impossible font format in dev_locate_font()");
      }
      num_phys_fonts += 1;
    } else { /* No appropriate physical font exists */
      this_font = -1; /* A flag indicating no physical font */
    }
  } else { /* A previously existing physical font can be used;
             however, this routine must return a distinct ID if the
             ptsizes are different.  Copy the information from the
             previous record to the new record */
    strcpy (dev_font[this_font].short_name, dev_font[i].short_name);
    dev_font[this_font].tex_name = NEW (strlen (tex_name)+1, char);
    strcpy (dev_font[this_font].tex_name, tex_name);
    dev_font[this_font].sptsize = ptsize;
    dev_font[this_font].format = dev_font[i].format;
    dev_font[this_font].used_chars = dev_font[i].used_chars;
    dev_font[this_font].slant = dev_font[i].slant;
    dev_font[this_font].extend = dev_font[i].extend;
    dev_font[this_font].remap = dev_font[i].remap;
    /* The value in useD_on_this_page will be incorrect if the font
       has already been used on a page in a different point size.
       It's too hard to do right.  The only negative consequence is
       that there will be an attempt to add the resource to the page
       resource dict.  However, the second attempt will do nothing */
    dev_font[this_font].used_on_this_page = 0;
    dev_font[this_font].font_resource = pdf_link_obj(dev_font[i].font_resource);
    /* These two fonts are treated as having the same physical
       "used_chars" */
    dev_font[this_font].used_chars = dev_font[i].used_chars;
  }
  if (this_font >= 0)
    num_dev_fonts += 1;
  return this_font;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double dev_page_height ( void  )

Definition at line 87 of file pdfdev.c.

Here is the caller graph for this function:

double dev_page_width ( void  )

Definition at line 81 of file pdfdev.c.

{
  page_size_readonly = 1;
  return page_width;
}

Here is the caller graph for this function:

double dev_phys_x ( void  )

Definition at line 1238 of file pdfdev.c.

{
  return dvi_dev_xpos()*dvi_tell_mag() + hoffset;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double dev_phys_y ( void  )

Definition at line 1243 of file pdfdev.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_read_mapfile ( char *  filename)

Definition at line 254 of file pdfdev.c.

{
  FILE *mapfile;
  char *full_map_filename, *start = NULL, *end, *tex_name;
  if (verbose > 0)
    fprintf (stderr, "<%s", filename);
  full_map_filename = kpse_find_file (filename, kpse_fontmap_format,
                                  0);
  if (full_map_filename == NULL || 
      (mapfile = MFOPEN (full_map_filename, FOPEN_R_MODE)) == NULL) {
    fprintf (stderr, "Warning:  Couldn't open font map file %s\n", filename);
    mapfile = NULL;
  }
  if (mapfile) {
    while ((start = mfgets (work_buffer, WORK_BUFFER_SIZE, mapfile)) !=
          NULL) {
      end = work_buffer + strlen(work_buffer);
      skip_white (&start, end);
      if (start >= end)
       continue;
      if (*start == '%')
       continue;
      if ((tex_name = parse_ident (&start, end)) == NULL)
       continue;
      /* Parse record line in map file.  First two fields (after TeX font
        name) are position specific.  Arguments start at the first token
        beginning with a  '-' */
      font_maps_need (num_font_map+1);
      init_map_record(font_map+num_font_map);
      font_map[num_font_map].tex_name = tex_name;
      skip_white (&start, end);
      if (*start != '-') {
       font_map[num_font_map].enc_name = parse_ident (&start, end); /* May be null */  
       skip_white (&start, end);
      }
      if (*start != '-') {
       font_map[num_font_map].font_name = parse_ident (&start, end); /* May be null */
       skip_white (&start, end);
      }
      /* Parse any remaining arguments */ 
      while (start+1 < end && *start == '-') {
       char *number;
       switch (*(start+1)) {
       case 's': /* Slant option */
         start += 2;
         skip_white (&start, end);
         if (start < end && 
             (number = parse_number(&start, end))) {
           font_map[num_font_map].slant = atof (number);
           RELEASE (number);
         } else {
           fprintf (stderr, "\n\nMissing slant value in map file for %s\n\n",
                   tex_name);
         }
         break;
       case 'e': /* Extend option */
         start += 2;
         skip_white (&start, end);
         if (start < end && 
             (number = parse_number(&start, end))) {
           font_map[num_font_map].extend = atof (number);
           RELEASE (number);
         } else {
           fprintf (stderr, "\n\nMissing extend value in map file for %s\n\n",
                   tex_name);
         }
         break;
       case 'r': /* Remap option */
         start += 2;
         skip_white (&start, end);
         font_map[num_font_map].remap = 1;
         break;
       default: 
         fprintf (stderr, "\n\nWarning: Unrecognized option in map file %s: -->%s<--\n\n",
                 tex_name, start);
         start = end;
       }
       skip_white (&start, end);
      }
      fill_in_defaults (font_map+num_font_map);
      num_font_map += 1;
    }
    MFCLOSE (mapfile);
    if (verbose > 0)
      fprintf (stderr, ">");
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 950 of file pdfdev.c.

{
  int i;
  current_font = -1;
  for (i=0; i<num_dev_fonts; i++) {
    dev_font[i].used_on_this_page = 0;
  }
  text_slant = 0.0;
  text_extend = 1.0;
}

Here is the caller graph for this function:

void dev_rule ( spt_t  xpos,
spt_t  ypos,
spt_t  width,
spt_t  height 
)

Definition at line 1189 of file pdfdev.c.

{
  int len = 0;
  long w, p1, p2, p3, p4;
  graphics_mode();
   /* Is using a real stroke the right thing to do?  It seems to preserve
      the logical meaning of a "rule" as opposed to a filled rectangle.
      I am assume the reader can more intelligently render a rule than a filled rectangle */
  if (width> height) {  /* Horizontal stroke? */
    w = IDIVRND(height, CENTI_PDF_U);
    p1 = IDIVRND(xpos, CENTI_PDF_U);
    p2 = IDIVRND (2*ypos+height, 2*CENTI_PDF_U);
    p3 = IDIVRND(xpos+width,CENTI_PDF_U);
    p4 = IDIVRND (2*ypos+height, 2*CENTI_PDF_U);
  } else { /* Vertical stroke */
    w = IDIVRND(width,CENTI_PDF_U);
    p1 = IDIVRND (2*xpos+width, 2*CENTI_PDF_U);
    p2 = IDIVRND(ypos, CENTI_PDF_U);
    p3 = IDIVRND (2*xpos+width, 2*CENTI_PDF_U);
    p4 = IDIVRND(ypos+height,CENTI_PDF_U);
  }
  /* This needs to be quick */
  {
    format_buffer[len++] = ' ';
    len += centi_u_to_a (format_buffer+len, w);
    format_buffer[len++] = ' ';
    format_buffer[len++] = 'w';
    format_buffer[len++] = ' ';
    len += centi_u_to_a (format_buffer+len, p1);
    format_buffer[len++] = ' ';
    len += centi_u_to_a (format_buffer+len, p2);
    format_buffer[len++] = ' ';
    format_buffer[len++] = 'm';
    format_buffer[len++] = ' ';
    len += centi_u_to_a (format_buffer+len, p3);
    format_buffer[len++] = ' ';
    len += centi_u_to_a (format_buffer+len, p4);
    format_buffer[len++] = ' ';
    format_buffer[len++] = 'l';
    format_buffer[len++] = ' ';
    format_buffer[len++] = 'S';
  }
  pdf_doc_add_to_page (format_buffer, len);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void dev_set_color ( struct color  color) [static]

Definition at line 716 of file pdfdev.c.

{
  switch (color.colortype) {
    int len;
  case RGB:
    sprintf (format_buffer, " %.2f %.2f %.2f",
            color.c1,
            color.c2,
            color.c3);
    len = strlen (format_buffer);
    pdf_doc_add_to_page (format_buffer, len);
    pdf_doc_add_to_page (" rg", 3);
    pdf_doc_add_to_page (format_buffer, len);
    pdf_doc_add_to_page (" RG", 3);
    break;
  case CMYK:
    sprintf (format_buffer, " %.2f %.2f %.2f %.2f",
            color.c1,
            color.c2,
            color.c3,
            color.c4);
    len = strlen (format_buffer);
    pdf_doc_add_to_page (format_buffer, len);
    pdf_doc_add_to_page (" k", 2);
    pdf_doc_add_to_page (format_buffer, len);
    pdf_doc_add_to_page (" K ", 3);
    break;
  case GRAY:
    sprintf (format_buffer, " %.2f", color.c1);
    len = strlen (format_buffer);
    pdf_doc_add_to_page (format_buffer, len);
    pdf_doc_add_to_page (" g", 2);
    pdf_doc_add_to_page (format_buffer, len);
    pdf_doc_add_to_page (" G", 2);
    break;
  default:
    ERROR ("Internal error: Invalid default color item");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 99 of file pdfdev.c.

{
  debug = 1;
}
void dev_set_def_cmyk_color ( double  c,
double  m,
double  y,
double  k 
)

Definition at line 802 of file pdfdev.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_set_def_gray ( double  g)

Definition at line 777 of file pdfdev.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 785 of file pdfdev.c.

{
  struct color color = color_by_name (s);
  switch (color.colortype) {
  case GRAY:
    dev_set_def_gray (color.c1);
    break;
  case RGB:
    dev_set_def_rgb_color (color.c1, color.c2, color.c3);
    break;
  case CMYK:
    dev_set_def_cmyk_color (color.c1, color.c2, color.c3, color.c4);
    break;
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_set_def_rgb_color ( double  r,
double  g,
double  b 
)

Definition at line 767 of file pdfdev.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void dev_set_font ( int  font_id) [static]

Definition at line 484 of file pdfdev.c.

{
  int len = 0;
  text_mode();
  sprintf (format_buffer, "/%s ", dev_font[font_id].short_name);
  len = strlen (format_buffer);
  len += centi_u_to_a (format_buffer+len, IDIVRND(dev_font[font_id].sptsize, CENTI_PDF_U));
  format_buffer[len++] = ' ';
  format_buffer[len++] = 'T';
  format_buffer[len++] = 'f';
  if (dev_font[font_id].slant != text_slant ||
      dev_font[font_id].extend != text_extend) {
    sprintf (format_buffer+len, " %.7g 0 %.3g 1 ",
            dev_font[font_id].extend,
            dev_font[font_id].slant);
    len += strlen (format_buffer+len);
    len += centi_u_to_a (format_buffer+len, IDIVRND(text_xorigin, CENTI_PDF_U));
    format_buffer[len++] = ' ';
    len += centi_u_to_a (format_buffer+len, IDIVRND(text_yorigin, CENTI_PDF_U));
    format_buffer[len++] = ' ';
    format_buffer[len++] = 'T';
    format_buffer[len++] = 'm';
     /* There's no longer any uncertainty about where we are */
    text_slant = dev_font[font_id].slant;
    text_extend = dev_font[font_id].extend;
  }
  pdf_doc_add_to_page (format_buffer, len);
  /* Add to Font list in Resource dictionary for this page */
  if (!dev_font[font_id].used_on_this_page) { 
    pdf_doc_add_to_page_fonts (dev_font[font_id].short_name,
                            pdf_link_obj(dev_font[font_id].font_resource));
    dev_font[font_id].used_on_this_page = 1;
  }
  current_font = font_id;
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_set_page_size ( double  width,
double  height 
)

Definition at line 71 of file pdfdev.c.

{
  if (page_size_readonly) {
    fprintf (stderr, "\nSorry.  Too late to change page size\n");
  } else {
    page_width = width;
    page_height = height;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dev_set_string ( spt_t  xpos,
spt_t  ypos,
unsigned char *  s,
int  length,
spt_t  width,
int  font_id 
)

Definition at line 521 of file pdfdev.c.

{
  int len = 0;
  long kern;
  
  if (font_id != current_font)
    dev_set_font(font_id); /* Force a Tf since we are actually trying
                            to write a character */
  /* Kern is in units of character units, i.e., 1000 = 1 em. */
  /* The following formula is of the form a*x/b where a, x, and b are
     long integers.  Since in integer arithmetic (a*x) could overflow
     and a*(x/b) would not be accurate, we use floating point
     arithmetic rather than trying to do this all with integer
     arithmetic. */
  kern =
    (1000.0/dev_font[font_id].extend*(text_xorigin+text_offset-xpos))/dev_font[font_id].sptsize;
  
  if (labs(ypos-text_yorigin) > CENTI_PDF_U || /* CENTI_PDF_U is smallest resolvable dimension */
      abs(kern) > 32000) { /* Some PDF Readers fail on large kerns */
    text_mode();
    kern = 0;
  }
  if (motion_state != STRING_MODE)
    string_mode(xpos, ypos, dev_font[font_id].slant, dev_font[font_id].extend);
  else if (kern != 0) {
    text_offset -=
      kern*dev_font[font_id].extend*(dev_font[font_id].sptsize/1000.0);
    /* Same issues as earlier.  Use floating point for simplicity */
    /* This routine needs to be fast, so we don't call sprintf() or
       strcpy() */
    format_buffer[len++] = ')';
    len += inttoa (format_buffer+len, kern);
    format_buffer[len++] = '(';
    pdf_doc_add_to_page (format_buffer, len);
    len = 0;
  }
  len += pdfobj_escape_str (format_buffer+len, FORMAT_BUF_SIZE-len, s,
                         length,
                         dev_font[font_id].remap);
  pdf_doc_add_to_page (format_buffer, len);

  /* Record characters used for partial font embedding */
  /* Fonts without pfbs don't get counted and have used_chars set to
     null */
  if (dev_font[font_id].used_chars != NULL) {
    int i;
    if (dev_font[font_id].remap)
      for (i=0; i<length; i++){
       (dev_font[font_id].used_chars)[twiddle(s[i])] = 1;
      }
    else 
      for (i=0; i<length; i++){
       (dev_font[font_id].used_chars)[s[i]] = 1;
      }
  }
  text_offset += width;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 95 of file pdfdev.c.

{
  verbose += 1;
}

Here is the caller graph for this function:

void dev_stack_depth ( unsigned int  depth)

Definition at line 1286 of file pdfdev.c.

{
  /* If decreasing below tagged_depth */
  if (link_annot && 
      dvi_stack_depth == dvi_tagged_depth &&
      depth == dvi_tagged_depth - 1) {
  /* See if this appears to be the end of a "logical unit"
     that's been broken.  If so, flush the logical unit */
    pdf_doc_flush_annot();
  }
  dvi_stack_depth = depth;
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1304 of file pdfdev.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1311 of file pdfdev.c.

{
  dvi_tagged_depth = -1;
  dvi_compute_boxes (0);
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 925 of file pdfdev.c.

{
  return num_transforms;
}

Here is the caller graph for this function:

static void fill_in_defaults ( struct map_record this_map_record) [static]

Definition at line 231 of file pdfdev.c.

{
  if (this_map_record -> enc_name != NULL && 
      (!strcmp (this_map_record->enc_name, "default") ||
       !strcmp (this_map_record->enc_name, "none"))) {
    RELEASE(this_map_record->enc_name);
    this_map_record -> enc_name = NULL;
  }
  if (this_map_record -> font_name != NULL && 
      (!strcmp (this_map_record->font_name, "default") ||
       !strcmp (this_map_record->font_name, "none"))) {
    RELEASE(this_map_record->font_name);
    this_map_record -> font_name = NULL;
  }
  /* We *must* fill in a font_name either explicitly or by default
     (the tex_name) */
  if (this_map_record -> font_name == NULL) {
    this_map_record -> font_name = NEW (strlen(this_map_record->tex_name)+1, char);
    strcpy (this_map_record->font_name, this_map_record->tex_name);
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void fill_page ( void  ) [static]

Definition at line 640 of file pdfdev.c.

{
  if (background.colortype == GRAY && background.c1 == 1.0)
    return;
  switch (background.colortype) {
  case GRAY:
    sprintf (format_buffer, " q 0 w %.3f g %.3f G", background.c1, background.c1);
    break;
  case RGB:
    sprintf (format_buffer, " q 0 w %.3f %.3f %.3f rg %.3f %.3f %.3f RG",
            background.c1, background.c2, background.c3,
            background.c1, background.c2, background.c3);
    break;
  case CMYK:
    sprintf (format_buffer, " q 0 w %.3f %.3f %.3f %.3f k %.3f %.3f %.3f %.3f K ",
            background.c1, background.c2, background.c3, background.c4,
            background.c1, background.c2, background.c3, background.c4);
    break;
  }
  pdf_doc_this_bop (format_buffer, strlen(format_buffer));
  sprintf (format_buffer,
          " 0 0 m %.2f 0 l %.2f %.2f l 0 %.2f l b Q ",
          dev_page_width(), dev_page_width(), dev_page_height(),
          dev_page_height());
  pdf_doc_this_bop (format_buffer, strlen(format_buffer));
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void font_maps_need ( int  n) [static]

Definition at line 200 of file pdfdev.c.

Here is the caller graph for this function:

struct map_record* get_map_record ( const char *  tex_name) [read]

Definition at line 343 of file pdfdev.c.

{
  struct map_record *result = NULL;
  int tried_default = 0;
  unsigned int i;
  if (!font_map && !tried_default) {
    dev_read_mapfile (DEFAULT_MAP_FILE);
    tried_default = 1;
  }
  if (!font_map)
    return result;
  for (i=0; i<num_font_map; i++) {
    if (!strcmp (font_map[i].tex_name, tex_name)) {
      result = font_map+i;
      break;
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 413 of file pdfdev.c.

{
  switch (motion_state) {
  case GRAPHICS_MODE:
    break;
  case STRING_MODE:
    pdf_doc_add_to_page (")]TJ", 4);
  case TEXT_MODE:
    pdf_doc_add_to_page (" ET", 3);
    break;
  }
  motion_state = GRAPHICS_MODE;
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_map_record ( struct map_record r) [static]

Definition at line 209 of file pdfdev.c.

{
  r->tex_name = NULL;
  r->enc_name = NULL;
  r->font_name = NULL;
  r->slant = 0.0;
  r->extend = 1.0;
  r->remap = 0.0;
  return;
}

Here is the caller graph for this function:

double pdf_dev_scale ( void  )

Definition at line 141 of file pdfdev.c.

{
  return 65800.0*dvi2pts;
}

Here is the caller graph for this function:

static void release_map_record ( struct map_record r) [static]

Definition at line 220 of file pdfdev.c.

{
  if (r && r->tex_name)
    RELEASE (r->tex_name);
  if (r && r->enc_name)
    RELEASE (r->enc_name);
  if (r && r->font_name)
    RELEASE (r->font_name);
}

Here is the caller graph for this function:

static void reset_text_state ( void  ) [static]

Definition at line 369 of file pdfdev.c.

{
  int len;
  text_xorigin = 0;
  text_yorigin = 0;
  text_offset = 0;
  /* 
   * We need to reset the line matrix to handle slanted fonts 
   */
  sprintf (format_buffer, " BT");
  len = strlen (format_buffer);
  if (current_font >= 0 && /* If not at top of page */
      (dev_font[current_font].slant != 0.0 ||
       dev_font[current_font].extend != 1.0)) {
    sprintf (format_buffer+len, " %.7g 0 %.3g 1 ",
            dev_font[current_font].extend,
            dev_font[current_font].slant);
    len += strlen (format_buffer+len);
    len += centi_u_to_a (format_buffer+len, IDIVRND (text_xorigin, CENTI_PDF_U));
    format_buffer[len++] = ' ';
    len += centi_u_to_a (format_buffer+len, IDIVRND (text_yorigin, CENTI_PDF_U));
    format_buffer[len++] = ' ';
    format_buffer[len++] = 'T';
    format_buffer[len++] = 'm';
  }
  pdf_doc_add_to_page (format_buffer, len);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int src_special ( char *  buffer,
UNSIGNED_QUAD  size 
) [static]

Definition at line 1248 of file pdfdev.c.

                                                          {
  char *start = buffer;
  char *end = buffer + size;
  int result = 0;
  skip_white (&start, end);
  if ((start+3 < end) &&
      (!strncmp ("src:", start, 4)))
    result = 1;
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void string_mode ( spt_t  xpos,
spt_t  ypos,
double  slant,
double  extend 
) [static]

Definition at line 428 of file pdfdev.c.

{
  spt_t delx, dely;
  int len = 0;
  switch (motion_state) {
  case STRING_MODE:
    break;
  case GRAPHICS_MODE:
    reset_text_state();
    /* Fall through now... */
    /* Following may be necessary after a rule (and also after
       specials) */
  case TEXT_MODE:
    delx = xpos - text_xorigin;
    {
      spt_t rounded_delx, desired_delx;
      spt_t rounded_dely, desired_dely;
      spt_t dvi_xerror, dvi_yerror;

      /* First round dely (it is needed for delx) */
      dely = ypos - text_yorigin;
      desired_dely = dely;
      rounded_dely = IDIVRND(desired_dely, CENTI_PDF_U) * CENTI_PDF_U;
      /* Next round delx, precompensating for line transformation matrix */
      desired_delx = (delx-desired_dely*slant)/extend;
      rounded_delx = IDIVRND(desired_delx, CENTI_PDF_U) * CENTI_PDF_U;
      /* Estimate errors in DVI units */
      dvi_yerror = (desired_dely - rounded_dely);
      dvi_xerror = (extend*(desired_delx - rounded_delx)+slant*dvi_yerror);
      format_buffer[len++] = ' ';
      len += centi_u_to_a (format_buffer+len, rounded_delx/CENTI_PDF_U);
      format_buffer[len++] = ' ';
      len += centi_u_to_a (format_buffer+len, rounded_dely/CENTI_PDF_U);
      pdf_doc_add_to_page (format_buffer, len);
      len = 0;
      pdf_doc_add_to_page (" TD[(", 5);
      text_xorigin = xpos-dvi_xerror;
      text_yorigin = ypos-dvi_yerror;
    }
    text_offset = 0;
    break;
  }
  motion_state = STRING_MODE;
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void text_mode ( void  ) [static]

Definition at line 397 of file pdfdev.c.

{
  switch (motion_state) {
  case STRING_MODE:
    pdf_doc_add_to_page (")]TJ", 4);
  case TEXT_MODE:
    break;
  case GRAPHICS_MODE:
    reset_text_state();
    break;
  }
  motion_state = TEXT_MODE;
  text_offset = 0;
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 159 of file pdfdev.c.

int debug = 0 [static]

Definition at line 93 of file pdfdev.c.

struct dev_font * dev_font [static]
double dvi2pts = 0.0 [static]

Definition at line 60 of file pdfdev.c.

unsigned dvi_stack_depth = 0 [static]

Definition at line 1277 of file pdfdev.c.

int dvi_tagged_depth = -1 [static]

Definition at line 1278 of file pdfdev.c.

struct map_record * font_map

Definition at line 111 of file pdfdev.c.

double hoffset = 72.0

Definition at line 58 of file pdfdev.c.

unsigned char link_annot = 1 [static]

Definition at line 1279 of file pdfdev.c.

unsigned max_device_fonts = 0 [static]

Definition at line 182 of file pdfdev.c.

unsigned int max_font_map = 0

Definition at line 198 of file pdfdev.c.

Definition at line 108 of file pdfdev.c.

int num_colors = 0 [static]

Definition at line 638 of file pdfdev.c.

unsigned num_dev_fonts = 0

Definition at line 157 of file pdfdev.c.

unsigned int num_font_map = 0

Definition at line 198 of file pdfdev.c.

unsigned num_phys_fonts = 0

Definition at line 158 of file pdfdev.c.

int num_transforms = 0 [static]

Definition at line 881 of file pdfdev.c.

double page_height = 792.0 [static]

Definition at line 68 of file pdfdev.c.

Definition at line 69 of file pdfdev.c.

double page_width = 612.0 [static]

Definition at line 68 of file pdfdev.c.

double text_extend = 1.0

Definition at line 155 of file pdfdev.c.

spt_t text_offset = 0 [static]

Definition at line 154 of file pdfdev.c.

double text_slant = 0.0

Definition at line 155 of file pdfdev.c.

spt_t text_xorigin = 0 [static]

Definition at line 153 of file pdfdev.c.

spt_t text_yorigin = 0 [static]

Definition at line 153 of file pdfdev.c.

int verbose = 0 [static]

Definition at line 93 of file pdfdev.c.

double voffset = 72.0

Definition at line 58 of file pdfdev.c.