Back to index

texmacs  1.0.7.15
Classes | Defines | Typedefs | Functions
pdfdev.h File Reference
#include "numbers.h"
#include "pdfobj.h"
#include "pdfcolor.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pdf_tmatrix
struct  pdf_rect
struct  pdf_coord
struct  transform_info

Defines

#define INFO_HAS_USER_BBOX   (1 << 0)
#define INFO_HAS_WIDTH   (1 << 1)
#define INFO_HAS_HEIGHT   (1 << 2)
#define INFO_DO_CLIP   (1 << 3)
#define INFO_DO_HIDE   (1 << 4)
#define PDF_DEV_PARAM_AUTOROTATE   1
#define PDF_DEV_PARAM_COLORMODE   2
#define pdf_dev_set_autorotate(v)   pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, (v))
#define pdf_dev_set_colormode(v)   pdf_dev_set_param(PDF_DEV_PARAM_COLORMODE, (v))

Typedefs

typedef signed long spt_t
typedef struct pdf_tmatrix pdf_tmatrix
typedef struct pdf_rect pdf_rect
typedef struct pdf_coord pdf_coord

Functions

void transform_info_clear (transform_info *info)
void pdf_dev_set_verbose (void)
int pdf_sprint_matrix (char *buf, const pdf_tmatrix *p)
int pdf_sprint_rect (char *buf, const pdf_rect *p)
int pdf_sprint_coord (char *buf, const pdf_coord *p)
int pdf_sprint_length (char *buf, double value)
int pdf_sprint_number (char *buf, double value)
void pdf_init_device (double unit_conv, int precision, int is_bw)
void pdf_close_device (void)
double dev_unit_dviunit (void)
void pdf_dev_set_string (spt_t xpos, spt_t ypos, const void *instr_ptr, int instr_len, spt_t text_width, int font_id, int ctype)
spt_t pdf_dev_string_width (int font_id, unsigned char *str, unsigned len)
void pdf_dev_set_raw_glyph (spt_t xpos, spt_t ypos, unsigned char glyph, int font_id)
void pdf_dev_set_rule (spt_t xpos, spt_t ypos, spt_t width, spt_t height)
int pdf_dev_put_image (int xobj_id, transform_info *p, double ref_x, double ref_y)
int pdf_dev_locate_font (const char *font_name, spt_t ptsize)
int pdf_dev_physical_font (const char *font_name, spt_t ptsize, const char *font_file, const char *tfm_file)
int pdf_dev_setfont (const char *font_name, spt_t ptsize)
double pdf_dev_scale (void)
int pdf_dev_get_font_wmode (int font_id)
int pdf_dev_get_dirmode (void)
void pdf_dev_set_dirmode (int dir_mode)
void pdf_dev_set_rect (pdf_rect *rect, spt_t x_pos, spt_t y_pos, spt_t width, spt_t height, spt_t depth)
int pdf_dev_get_param (int param_type)
void pdf_dev_set_param (int param_type, int value)
void pdf_dev_reset_fonts (void)
void pdf_dev_bop (const pdf_tmatrix *M)
void pdf_dev_eop (void)
void graphics_mode (void)
void pdf_dev_get_coord (double *xpos, double *ypos)
void pdf_dev_push_coord (double xpos, double ypos)
void pdf_dev_pop_coord (void)

Class Documentation

struct pdf_tmatrix

Definition at line 34 of file pdfdev.h.

Class Members
double a
double b
double c
double d
double e
double f
struct pdf_rect

Definition at line 39 of file pdfdev.h.

Class Members
double llx
double lly
double urx
double ury
struct pdf_coord

Definition at line 44 of file pdfdev.h.

Class Members
double x
double y
struct transform_info

Definition at line 52 of file pdfdev.h.

Collaboration diagram for transform_info:
Class Members
pdf_rect bbox
double depth
int flags
double height
pdf_tmatrix matrix
double width

Define Documentation

#define INFO_DO_CLIP   (1 << 3)

Definition at line 72 of file pdfdev.h.

#define INFO_DO_HIDE   (1 << 4)

Definition at line 73 of file pdfdev.h.

#define INFO_HAS_HEIGHT   (1 << 2)

Definition at line 71 of file pdfdev.h.

#define INFO_HAS_USER_BBOX   (1 << 0)

Definition at line 69 of file pdfdev.h.

#define INFO_HAS_WIDTH   (1 << 1)

Definition at line 70 of file pdfdev.h.

#define PDF_DEV_PARAM_AUTOROTATE   1

Definition at line 199 of file pdfdev.h.

#define PDF_DEV_PARAM_COLORMODE   2

Definition at line 200 of file pdfdev.h.

Definition at line 209 of file pdfdev.h.

Definition at line 210 of file pdfdev.h.


Typedef Documentation

typedef struct pdf_coord pdf_coord
typedef struct pdf_rect pdf_rect
typedef struct pdf_tmatrix pdf_tmatrix
typedef signed long spt_t

Definition at line 32 of file pdfdev.h.


Function Documentation

double dev_unit_dviunit ( void  )

Definition at line 87 of file pdfdev.c.

{
  return (1.0/dev_unit.dvi2pts);
}
void graphics_mode ( void  )

Definition at line 600 of file pdfdev.c.

{
  switch (motion_state) {
  case GRAPHICS_MODE:
    break;
  case STRING_MODE:
    pdf_doc_add_page_content(text_state.is_mb ? ">]TJ" : ")]TJ", 4);  /* op: TJ */
    /* continue */
  case TEXT_MODE:
    pdf_doc_add_page_content(" ET", 3);  /* op: ET */
    text_state.force_reset =  0;
    text_state.font_id     = -1;
    break;
  }
  motion_state = GRAPHICS_MODE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_close_device ( void  )

Definition at line 1333 of file pdfdev.c.

{
  if (dev_fonts) {
    int    i;

    for (i = 0; i < num_dev_fonts; i++) {
      if (dev_fonts[i].tex_name)
        RELEASE(dev_fonts[i].tex_name);
      if (dev_fonts[i].resource)
        pdf_release_obj(dev_fonts[i].resource);
      dev_fonts[i].tex_name = NULL;
      dev_fonts[i].resource = NULL;
    }
    RELEASE(dev_fonts);
  }
  if (dev_coords) RELEASE(dev_coords);
  pdf_dev_clear_gstates();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_dev_bop ( const pdf_tmatrix M)

Definition at line 1395 of file pdfdev.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_dev_eop ( void  )

Definition at line 1409 of file pdfdev.c.

{
  int  depth;

  graphics_mode();

  depth = pdf_dev_current_depth();
  if (depth != 1) {
    WARN("Unbalenced q/Q nesting...: %d", depth);
    pdf_dev_grestore_to(0);
  } else {
    pdf_dev_grestore();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_dev_get_coord ( double *  xpos,
double *  ypos 
)

Definition at line 983 of file pdfdev.c.

{
  if (num_dev_coords > 0) {
    *xpos = dev_coords[num_dev_coords-1].x;
    *ypos = dev_coords[num_dev_coords-1].y;
  } else {
    *xpos = *ypos = 0.0;
  }
}

Here is the caller graph for this function:

int pdf_dev_get_dirmode ( void  )

Definition at line 1848 of file pdfdev.c.

{
  return text_state.dir_mode;
}
int pdf_dev_get_font_wmode ( int  font_id)

Definition at line 878 of file pdfdev.c.

{
  struct dev_font *font;

  font = GET_FONT(font_id);
  if (font) {
    return font->wmode;
  }

  return 0;
}
int pdf_dev_get_param ( int  param_type)

Definition at line 1903 of file pdfdev.c.

{
  int value = 0;

  switch (param_type) {
  case PDF_DEV_PARAM_AUTOROTATE:
    value = dev_param.autorotate;
    break;
  case PDF_DEV_PARAM_COLORMODE:
    value = dev_param.colormode;
    break;
  default:
    ERROR("Unknown device parameter: %d", param_type);
  }

  return value;
}

Here is the caller graph for this function:

int pdf_dev_locate_font ( const char *  font_name,
spt_t  ptsize 
)

Definition at line 1471 of file pdfdev.c.

{
  int              i;
  fontmap_rec     *mrec;
  struct dev_font *font;

  if (!font_name)
    return  -1;

  if (ptsize == 0) {
    ERROR("pdf_dev_locate_font() called with the zero ptsize.");
    return -1;
  }

  for (i = 0; i < num_dev_fonts; i++) {
    if (!strcmp(font_name, dev_fonts[i].tex_name) && ptsize == dev_fonts[i].sptsize) {
      return  i;
    }
  }

  /*
   * Make sure we have room for a new one, even though we may not
   * actually create one.
   */
  if (num_dev_fonts >= max_dev_fonts) {
    max_dev_fonts += 16;
    dev_fonts      = RENEW(dev_fonts, max_dev_fonts, struct dev_font);
  }

  font = &dev_fonts[num_dev_fonts];

  /* New font */
  mrec = pdf_lookup_fontmap_record(font_name);

  if (verbose > 1)
    print_fontmap(font_name, mrec);

  font->font_id = pdf_font_findresource(font_name, ptsize * dev_unit.dvi2pts, mrec);
  if (font->font_id < 0)
    return  -1;

  /* We found device font here. */
  font->short_name[0] = 'F';
  p_itoa(num_phys_fonts + 1, &font->short_name[1]); /* NULL terminated here */
  num_phys_fonts++;

  font->used_on_this_page = 0;

  font->tex_name = NEW(strlen(font_name) + 1, char);
  strcpy(font->tex_name, font_name);
  font->sptsize  = ptsize;

  switch (pdf_get_font_subtype(font->font_id)) {
  case PDF_FONT_FONTTYPE_TYPE3:
    font->format = PDF_FONTTYPE_BITMAP;
    break;
  case PDF_FONT_FONTTYPE_TYPE0:
    font->format = PDF_FONTTYPE_COMPOSITE;
    break;
  default:
    font->format = PDF_FONTTYPE_SIMPLE;
    break;
  }

  font->wmode      = pdf_get_font_wmode   (font->font_id);
  font->enc_id     = pdf_get_font_encoding(font->font_id);

  font->resource   = NULL; /* Don't ref obj until font is actually used. */  
  font->used_chars = NULL;

  font->extend     = 1.0;
  font->slant      = 0.0;
  font->bold       = 0.0;
  font->mapc       = -1;
  font->is_unicode = 0;
  font->ucs_group  = 0;
  font->ucs_plane  = 0;

  if (mrec) {
    font->extend = mrec->opt.extend;
    font->slant  = mrec->opt.slant;
    font->bold   = mrec->opt.bold;
    if (mrec->opt.mapc >= 0)
      font->mapc = (mrec->opt.mapc >> 8) & 0xff;
    else {
      font->mapc = -1;
    }
    if (mrec->enc_name &&
        !strcmp(mrec->enc_name, "unicode")) {
      font->is_unicode   = 1;
      if (mrec->opt.mapc >= 0) {
        font->ucs_group  = (mrec->opt.mapc >> 24) & 0xff;
        font->ucs_plane  = (mrec->opt.mapc >> 16) & 0xff;
      } else {
        font->ucs_group  = 0;
        font->ucs_plane  = 0;
      }
    } else {
      font->is_unicode   = 0;
    }
  }

  return  num_dev_fonts++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pdf_dev_physical_font ( const char *  font_name,
spt_t  ptsize,
const char *  font_file,
const char *  tfm_file 
)

Definition at line 1577 of file pdfdev.c.

{
  int              i;
  fontmap_rec     *mrec = NULL;
  struct dev_font *font;
  
  if (!font_name)
    return  -1;
  
  if (ptsize == 0) {
    ERROR("pdf_dev_physical_font() called with the zero ptsize.");
    return -1;
  }
  
  for (i = 0; i < num_dev_fonts; i++) {
    if (!strcmp(font_name, dev_fonts[i].tex_name) && ptsize == dev_fonts[i].sptsize) {
      return  i;
    }
  }
  
  /*
   * Make sure we have room for a new one, even though we may not
   * actually create one.
   */
  if (num_dev_fonts >= max_dev_fonts) {
    max_dev_fonts += 16;
    dev_fonts      = RENEW(dev_fonts, max_dev_fonts, struct dev_font);
  }
  
  font = &dev_fonts[num_dev_fonts];
  
  /* New font */
//  mrec = pdf_lookup_fontmap_record(font_name);
  
  if (verbose > 1)
    print_fontmap(font_name, mrec);
  
  font->font_id = pdf_font_physical(font_name, ptsize * dev_unit.dvi2pts, font_file, tfm_file);
  if (font->font_id < 0)
    return  -1;
  
  /* We found device font here. */
  font->short_name[0] = 'F';
  p_itoa(num_phys_fonts + 1, &font->short_name[1]); /* NULL terminated here */
  num_phys_fonts++;
  
  font->used_on_this_page = 0;
  
  font->tex_name = NEW(strlen(font_name) + 1, char);
  strcpy(font->tex_name, font_name);
  font->sptsize  = ptsize;
  
  switch (pdf_get_font_subtype(font->font_id)) {
    case PDF_FONT_FONTTYPE_TYPE3:
      font->format = PDF_FONTTYPE_BITMAP;
      break;
    case PDF_FONT_FONTTYPE_TYPE0:
      font->format = PDF_FONTTYPE_COMPOSITE;
      break;
    default:
      font->format = PDF_FONTTYPE_SIMPLE;
      break;
  }
  
  font->wmode      = pdf_get_font_wmode   (font->font_id);
  font->enc_id     = pdf_get_font_encoding(font->font_id);
  
  font->resource   = NULL; /* Don't ref obj until font is actually used. */  
  font->used_chars = NULL;
  
  font->extend     = 1.0;
  font->slant      = 0.0;
  font->bold       = 0.0;
  font->mapc       = -1;
  font->is_unicode = 0;
  font->ucs_group  = 0;
  font->ucs_plane  = 0;
  
  font->tfm_id = (tfm_file ? tfm_open(tfm_file, 1) : -1);
  
  if (mrec) {
    font->extend = mrec->opt.extend;
    font->slant  = mrec->opt.slant;
    font->bold   = mrec->opt.bold;
    if (mrec->opt.mapc >= 0)
      font->mapc = (mrec->opt.mapc >> 8) & 0xff;
    else {
      font->mapc = -1;
    }
    if (mrec->enc_name &&
        !strcmp(mrec->enc_name, "unicode")) {
      font->is_unicode   = 1;
      if (mrec->opt.mapc >= 0) {
        font->ucs_group  = (mrec->opt.mapc >> 24) & 0xff;
        font->ucs_plane  = (mrec->opt.mapc >> 16) & 0xff;
      } else {
        font->ucs_group  = 0;
        font->ucs_plane  = 0;
      }
    } else {
      font->is_unicode   = 0;
    }
  }
  
  return  num_dev_fonts++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_dev_pop_coord ( void  )

Definition at line 1004 of file pdfdev.c.

void pdf_dev_push_coord ( double  xpos,
double  ypos 
)
int pdf_dev_put_image ( int  xobj_id,
transform_info p,
double  ref_x,
double  ref_y 
)

Definition at line 1940 of file pdfdev.c.

{
  char        *res_name;
  pdf_tmatrix  M, M1;
  pdf_rect     r;
  int          len = 0;

  if (num_dev_coords > 0) {
    ref_x -= dev_coords[num_dev_coords-1].x;
    ref_y -= dev_coords[num_dev_coords-1].y;
  }

  pdf_copymatrix(&M, &(p->matrix));
  M.e += ref_x; M.f += ref_y;
  /* Just rotate by -90, but not tested yet. Any problem if M has scaling? */
  if (dev_param.autorotate &&
      text_state.dir_mode) {
    double tmp;
    tmp = -M.a; M.a = M.b; M.b = tmp;
    tmp = -M.c; M.c = M.d; M.d = tmp;
  }

  graphics_mode();
  pdf_dev_gsave();

  pdf_ximage_scale_image(id, &M1, &r, p);
  pdf_concatmatrix(&M, &M1);
  pdf_dev_concat(&M);

  /* Clip */
  if (p->flags & INFO_DO_CLIP) {
#if  0
    pdf_dev_newpath();
    pdf_dev_moveto(r.llx, r.lly);
    pdf_dev_lineto(r.urx, r.lly);
    pdf_dev_lineto(r.urx, r.ury);
    pdf_dev_lineto(r.llx, r.ury);
    pdf_dev_closepath();
    pdf_dev_clip();
    pdf_dev_newpath();
#else
    pdf_dev_rectclip(r.llx, r.lly, r.urx - r.llx, r.ury - r.lly);
#endif
  }

  res_name = pdf_ximage_get_resname(id);
  len = sprintf(work_buffer, " /%s Do", res_name);
  pdf_doc_add_page_content(work_buffer, len);  /* op: Do */

  pdf_dev_grestore();

  pdf_doc_add_page_resource("XObject",
                            res_name,
                            pdf_ximage_get_reference(id));

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_dev_reset_fonts ( void  )

Definition at line 1358 of file pdfdev.c.

{
  int  i;

  for (i = 0; i < num_dev_fonts; i++) {
    dev_fonts[i].used_on_this_page = 0;
  }

  text_state.font_id       = -1;

  text_state.matrix.slant  = 0.0;
  text_state.matrix.extend = 1.0;
  text_state.matrix.rotate = TEXT_WMODE_HH;

  text_state.bold_param    = 0.0;

  text_state.is_mb         = 0;
}

Here is the caller graph for this function:

double pdf_dev_scale ( void  )

Definition at line 65 of file pdfdev.c.

{
  return 1.0;
}
void pdf_dev_set_dirmode ( int  dir_mode)

Definition at line 1854 of file pdfdev.c.

{
  struct dev_font *font;
  int text_rotate;
  int vert_dir, vert_font;

  font = CURRENTFONT();

  vert_font = (font && font->wmode) ? 1 : 0;
  if (dev_param.autorotate) {
    vert_dir = text_dir ? 1 : 0;
  } else {
    vert_dir = vert_font;
  }
  text_rotate = (vert_font << 1)|vert_dir;

  if (font &&
      ANGLE_CHANGES(text_rotate, text_state.matrix.rotate)) {
    text_state.force_reset = 1;
  }

  text_state.matrix.rotate = text_rotate;
  text_state.dir_mode      = text_dir;
}
void pdf_dev_set_param ( int  param_type,
int  value 
)

Definition at line 1922 of file pdfdev.c.

{
  switch (param_type) {
  case PDF_DEV_PARAM_AUTOROTATE:
    dev_set_param_autorotate(value);
    break;
  case PDF_DEV_PARAM_COLORMODE:
    dev_param.colormode = value; /* 0 for B&W */
    break;
  default:
    ERROR("Unknown device parameter: %d", param_type);
  }

  return;
}

Here is the call graph for this function:

void pdf_dev_set_raw_glyph ( spt_t  xpos,
spt_t  ypos,
unsigned char  glyph,
int  font_id 
)

Definition at line 1177 of file pdfdev.c.

{
  struct dev_font *font;
  int              i, len = 0;
  spt_t            kern, delh, delv;
  spt_t            text_xorigin;
  spt_t            text_yorigin;
  
  if (font_id < 0 || font_id >= num_dev_fonts) {
    ERROR("Invalid font: %d (%d)", font_id, num_dev_fonts);
    return;
  }
  if (font_id != text_state.font_id) {
    dev_set_font(font_id);
  }
  
  font = CURRENTFONT();
  if (!font) {
    ERROR("Currentfont not set.");
    return;
  }
  
  text_xorigin = text_state.ref_x;
  text_yorigin = text_state.ref_y;
  
  if (font->format == PDF_FONTTYPE_COMPOSITE) {
    ERROR("This should not happen...");
    return;
  } else {
    if (font->used_chars != NULL) {
          font->used_chars[glyph] = 1;
    }
  }
  
  if (num_dev_coords > 0) {
    xpos -= bpt2spt(dev_coords[num_dev_coords-1].x);
    ypos -= bpt2spt(dev_coords[num_dev_coords-1].y);
  }
  
  /*
   * Kern is in units of character units, i.e., 1000 = 1 em.
   *
   * Positive kern means kerning (reduce excess white space).
   *
   * The following formula is of the form a*x/b where a, x, and b are signed 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.
   *
   * 1000.0 / (font->extend * font->sptsize) is caluculated each times...
   * Is accuracy really a matter? Character widths are always rounded to integer
   * (in 1000 units per em) but dvipdfmx does not take into account of this...
   */
  
  if (text_state.dir_mode) {
    /* Top-to-bottom */
    delh = ypos - text_yorigin + text_state.offset;
    delv = xpos - text_xorigin;
  } else {
    /* Left-to-right */
    delh = text_xorigin + text_state.offset - xpos;
    delv = ypos - text_yorigin;
  }
  
  /* White-space more than 3em is not considered as a part of single text.
   * So we will break string mode in that case.
   * Dvipdfmx spend most of time processing strings with kern = 0 (but far
   * more times in font handling).
   * You may want to use pre-calculated value for WORD_SPACE_MAX.
   * More text compression may be possible by replacing kern with space char
   * when -kern is equal to space char width.
   */
#define WORD_SPACE_MAX(f) (spt_t) (3.0 * (f)->extend * (f)->sptsize)
  
  text_mode();
  kern = 0;

  /* Inaccucary introduced by rounding of character width appears within
   * single text block. There are point_size/1000 rounding error per character.
   * If you really care about accuracy, you should compensate this here too.
   */
  if (motion_state != STRING_MODE)
    string_mode(xpos, ypos,
                font->slant, font->extend, text_state.matrix.rotate);
  else if (kern != 0) {
    /*
     * Same issues as earlier. Use floating point for simplicity.
     * This routine needs to be fast, so we don't call sprintf() or strcpy().
     */
    text_state.offset -= 
    (spt_t) (kern * font->extend * (font->sptsize / 1000.0));
    format_buffer[len++] = text_state.is_mb ? '>' : ')';
    if (font->wmode)
      len += p_itoa(-kern, format_buffer + len);
    else {
      len += p_itoa( kern, format_buffer + len);
    }
    format_buffer[len++] = text_state.is_mb ? '<' : '(';
    pdf_doc_add_page_content(format_buffer, len);  /* op: */
    len = 0;
  }
  
  if (text_state.is_mb) {
    if (FORMAT_BUF_SIZE - len < 2)
      ERROR("Buffer overflow...");
      int first, second;
      
      first  = (glyph >> 4) & 0x0f;
      second = glyph & 0x0f;
      format_buffer[len++] = ((first >= 10)  ? first  + 'W' : first  + '0');
      format_buffer[len++] = ((second >= 10) ? second + 'W' : second + '0');
  } else {
    len += pdfobj_escape_str(format_buffer + len,
                             FORMAT_BUF_SIZE - len, &glyph, 1);
  }
  /* I think if you really care about speed, you should avoid memcopy here. */
  pdf_doc_add_page_content(format_buffer, len);  /* op: */
  
 // text_state.offset += width;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_dev_set_rect ( pdf_rect rect,
spt_t  x_pos,
spt_t  y_pos,
spt_t  width,
spt_t  height,
spt_t  depth 
)

Definition at line 1788 of file pdfdev.c.

{
  double      dev_x, dev_y;
  pdf_coord   p0, p1, p2, p3;
  double      min_x, min_y, max_x, max_y;

  dev_x = x_user * dev_unit.dvi2pts;
  dev_y = y_user * dev_unit.dvi2pts;
  if (text_state.dir_mode) {
    p0.x = dev_x - dev_unit.dvi2pts * depth;
    p0.y = dev_y - dev_unit.dvi2pts * width;
    p1.x = dev_x + dev_unit.dvi2pts * height;
    p1.y = p0.y;
    p2.x = p1.x;
    p2.y = dev_y;
    p3.x = p0.x;
    p3.y = p2.y;
  } else {
    p0.x = dev_x;
    p0.y = dev_y - dev_unit.dvi2pts * depth;
    p1.x = dev_x + dev_unit.dvi2pts * width;
    p1.y = p0.y;
    p2.x = p1.x;
    p2.y = dev_y + dev_unit.dvi2pts * height;
    p3.x = p0.x;
    p3.y = p2.y;
  }

  pdf_dev_transform(&p0, NULL); /* currentmatrix */
  pdf_dev_transform(&p1, NULL);
  pdf_dev_transform(&p2, NULL);
  pdf_dev_transform(&p3, NULL);

  min_x = MIN(p0.x , p1.x);
  min_x = MIN(min_x, p2.x);
  min_x = MIN(min_x, p3.x);

  max_x = MAX(p0.x , p1.x);
  max_x = MAX(max_x, p2.x);
  max_x = MAX(max_x, p3.x);

  min_y = MIN(p0.y , p1.y);
  min_y = MIN(min_y, p2.y);
  min_y = MIN(min_y, p3.y);

  max_y = MAX(p0.y , p1.y);
  max_y = MAX(max_y, p2.y);
  max_y = MAX(max_y, p3.y);

  rect->llx = min_x;
  rect->lly = min_y;
  rect->urx = max_x;
  rect->ury = max_y;

  return;
}

Here is the call graph for this function:

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

Definition at line 1720 of file pdfdev.c.

{
  int    len = 0;
  double width_in_bp;

  if (num_dev_coords > 0) {
    xpos -= bpt2spt(dev_coords[num_dev_coords-1].x);
    ypos -= bpt2spt(dev_coords[num_dev_coords-1].y);
  }

  graphics_mode();

  format_buffer[len++] = ' ';
  format_buffer[len++] = 'q';
  format_buffer[len++] = ' ';
  /* Don't use too thick line. */
  width_in_bp = ((width < height) ? width : height) * dev_unit.dvi2pts;
  if (width_in_bp < 0.0 || /* Shouldn't happen */
      width_in_bp > PDF_LINE_THICKNESS_MAX) {
    pdf_rect rect;

    rect.llx =  dev_unit.dvi2pts * xpos;
    rect.lly =  dev_unit.dvi2pts * ypos;
    rect.urx =  dev_unit.dvi2pts * width;
    rect.ury =  dev_unit.dvi2pts * height;
    len += pdf_sprint_rect(format_buffer+len, &rect);
    format_buffer[len++] = ' ';
    format_buffer[len++] = 'r';
    format_buffer[len++] = 'e';
    format_buffer[len++] = ' ';
    format_buffer[len++] = 'f';
  } else {
    if (width > height) {
      /* NOTE:
       *  A line width of 0 denotes the thinnest line that can be rendered at
       *  device resolution. See, PDF Reference Manual 4th ed., sec. 4.3.2,
       *  "Details of Graphics State Parameters", p. 185.
       */
      if (height < dev_unit.min_bp_val) {
        WARN("Too thin line: height=%ld (%g bp)", height, width_in_bp);
        WARN("Please consider using \"-d\" option.");
      }
      len += dev_sprint_line(format_buffer+len,
                             height,
                             xpos,
                             ypos + height/2,
                             xpos + width,
                             ypos + height/2);
    } else {
      if (width < dev_unit.min_bp_val) {
        WARN("Too thin line: width=%ld (%g bp)", width, width_in_bp);
        WARN("Please consider using \"-d\" option.");
      }
      len += dev_sprint_line(format_buffer+len,
                             width,
                             xpos + width/2,
                             ypos,
                             xpos + width/2,
                             ypos + height);
    }
  }
  format_buffer[len++] = ' ';
  format_buffer[len++] = 'Q';
  pdf_doc_add_page_content(format_buffer, len);  /* op: q re f Q */
}

Here is the call graph for this function:

void pdf_dev_set_string ( spt_t  xpos,
spt_t  ypos,
const void *  instr_ptr,
int  instr_len,
spt_t  text_width,
int  font_id,
int  ctype 
)

Definition at line 1031 of file pdfdev.c.

{
  struct dev_font *font;
  unsigned char   *str_ptr; /* Pointer to the reencoded string. */
  int              length, i, len = 0;
  spt_t            kern, delh, delv;
  spt_t            text_xorigin;
  spt_t            text_yorigin;

  if (font_id < 0 || font_id >= num_dev_fonts) {
    ERROR("Invalid font: %d (%d)", font_id, num_dev_fonts);
    return;
  }
  if (font_id != text_state.font_id) {
    dev_set_font(font_id);
  }

  font = CURRENTFONT();
  if (!font) {
    ERROR("Currentfont not set.");
    return;
  }

  text_xorigin = text_state.ref_x;
  text_yorigin = text_state.ref_y;

  str_ptr = (unsigned char *) instr_ptr;
  length  = instr_len;

  if (font->format == PDF_FONTTYPE_COMPOSITE) {
    if (handle_multibyte_string(font, &str_ptr, &length, ctype) < 0) {
      ERROR("Error in converting input string...");
      return;
    }
    if (font->used_chars != NULL) {
      for (i = 0; i < length; i += 2)
        add_to_used_chars2(font->used_chars,
                           (unsigned short) (str_ptr[i] << 8)|str_ptr[i+1]);
    }
  } else {
    if (font->used_chars != NULL) {
      for (i = 0; i < length; i++)
        font->used_chars[str_ptr[i]] = 1;
    }
  }

  if (num_dev_coords > 0) {
    xpos -= bpt2spt(dev_coords[num_dev_coords-1].x);
    ypos -= bpt2spt(dev_coords[num_dev_coords-1].y);
  }

  /*
   * Kern is in units of character units, i.e., 1000 = 1 em.
   *
   * Positive kern means kerning (reduce excess white space).
   *
   * The following formula is of the form a*x/b where a, x, and b are signed 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.
   *
   * 1000.0 / (font->extend * font->sptsize) is caluculated each times...
   * Is accuracy really a matter? Character widths are always rounded to integer
   * (in 1000 units per em) but dvipdfmx does not take into account of this...
   */

  if (text_state.dir_mode) {
    /* Top-to-bottom */
    delh = ypos - text_yorigin + text_state.offset;
    delv = xpos - text_xorigin;
  } else {
    /* Left-to-right */
    delh = text_xorigin + text_state.offset - xpos;
    delv = ypos - text_yorigin;
  }

  /* White-space more than 3em is not considered as a part of single text.
   * So we will break string mode in that case.
   * Dvipdfmx spend most of time processing strings with kern = 0 (but far
   * more times in font handling).
   * You may want to use pre-calculated value for WORD_SPACE_MAX.
   * More text compression may be possible by replacing kern with space char
   * when -kern is equal to space char width.
   */
#define WORD_SPACE_MAX(f) (spt_t) (3.0 * (f)->extend * (f)->sptsize)

  if (text_state.force_reset ||
      labs(delv) > dev_unit.min_bp_val ||
      labs(delh) > WORD_SPACE_MAX(font)) {
    text_mode();
    kern = 0;
  } else {
    kern = (spt_t) (1000.0 / font->extend * delh / font->sptsize);
  }

  /* Inaccucary introduced by rounding of character width appears within
   * single text block. There are point_size/1000 rounding error per character.
   * If you really care about accuracy, you should compensate this here too.
   */
  if (motion_state != STRING_MODE)
    string_mode(xpos, ypos,
                font->slant, font->extend, text_state.matrix.rotate);
  else if (kern != 0) {
    /*
     * Same issues as earlier. Use floating point for simplicity.
     * This routine needs to be fast, so we don't call sprintf() or strcpy().
     */
    text_state.offset -= 
      (spt_t) (kern * font->extend * (font->sptsize / 1000.0));
    format_buffer[len++] = text_state.is_mb ? '>' : ')';
    if (font->wmode)
      len += p_itoa(-kern, format_buffer + len);
    else {
      len += p_itoa( kern, format_buffer + len);
    }
    format_buffer[len++] = text_state.is_mb ? '<' : '(';
    pdf_doc_add_page_content(format_buffer, len);  /* op: */
    len = 0;
  }

  if (text_state.is_mb) {
    if (FORMAT_BUF_SIZE - len < 2 * length)
      ERROR("Buffer overflow...");
    for (i = 0; i < length; i++) {
      int first, second;

      first  = (str_ptr[i] >> 4) & 0x0f;
      second = str_ptr[i] & 0x0f;
      format_buffer[len++] = ((first >= 10)  ? first  + 'W' : first  + '0');
      format_buffer[len++] = ((second >= 10) ? second + 'W' : second + '0');
    }
  } else {
    len += pdfobj_escape_str(format_buffer + len,
                             FORMAT_BUF_SIZE - len, str_ptr, length);
  }
  /* I think if you really care about speed, you should avoid memcopy here. */
  pdf_doc_add_page_content(format_buffer, len);  /* op: */

  text_state.offset += width;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_dev_set_verbose ( void  )

Definition at line 58 of file pdfdev.c.

{
  verbose++;
}
int pdf_dev_setfont ( const char *  font_name,
spt_t  ptsize 
)
spt_t pdf_dev_string_width ( int  font_id,
unsigned char *  str,
unsigned  len 
)

Definition at line 1010 of file pdfdev.c.

{
  if (font_id < 0 || font_id >= num_dev_fonts) {
    ERROR("Invalid font: %d (%d)", font_id, num_dev_fonts);
    return;
  }
  
  return tfm_string_width(GET_FONT(font_id)->tfm_id, str, len);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_init_device ( double  unit_conv,
int  precision,
int  is_bw 
)

Definition at line 1301 of file pdfdev.c.

{
  if (precision < 0 ||
      precision > DEV_PRECISION_MAX)
    WARN("Number of decimal digits out of range [0-%d].",
         DEV_PRECISION_MAX);

  if (precision < 0) {
    dev_unit.precision  = 0;
  } else if (precision > DEV_PRECISION_MAX) {
    dev_unit.precision  = DEV_PRECISION_MAX;
  } else {
    dev_unit.precision  = precision;
  }
  dev_unit.dvi2pts      = dvi2pts;
  dev_unit.min_bp_val   = (long) ROUND(1.0/(ten_pow[dev_unit.precision]*dvi2pts), 1);
  if (dev_unit.min_bp_val < 0)
    dev_unit.min_bp_val = -dev_unit.min_bp_val;

  dev_param.colormode = (black_and_white ? 0 : 1);

  graphics_mode();
  pdf_color_clear_stack();
  pdf_dev_init_gstates();

  num_dev_fonts  = max_dev_fonts = 0;
  dev_fonts      = NULL;
  num_dev_coords = max_dev_coords = 0;
  dev_coords     = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pdf_sprint_coord ( char *  buf,
const pdf_coord p 
)

Definition at line 256 of file pdfdev.c.

{
  int  len;

  len  = p_dtoa(p->x, dev_unit.precision, buf);
  buf[len++] = ' ';
  len += p_dtoa(p->y, dev_unit.precision, buf+len);
  buf[len]   = '\0'; /* xxx_sprint_xxx NULL terminates strings. */

  return  len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pdf_sprint_length ( char *  buf,
double  value 
)

Definition at line 269 of file pdfdev.c.

{
  int  len;

  len = p_dtoa(value, dev_unit.precision, buf);
  buf[len] = '\0'; /* xxx_sprint_xxx NULL terminates strings. */

  return  len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pdf_sprint_matrix ( char *  buf,
const pdf_tmatrix p 
)

Definition at line 216 of file pdfdev.c.

{
  int  len;
  int  prec2 = MIN(dev_unit.precision + 2, DEV_PRECISION_MAX);
  int  prec0 = MAX(dev_unit.precision, 2);

  len  = p_dtoa(M->a, prec2, buf);
  buf[len++] = ' ';
  len += p_dtoa(M->b, prec2, buf+len);
  buf[len++] = ' ';
  len += p_dtoa(M->c, prec2, buf+len);
  buf[len++] = ' ';
  len += p_dtoa(M->d, prec2, buf+len);
  buf[len++] = ' ';
  len += p_dtoa(M->e, prec0, buf+len);
  buf[len++] = ' ';
  len += p_dtoa(M->f, prec0, buf+len);
  buf[len]   = '\0'; /* xxx_sprint_xxx NULL terminates strings. */

  return  len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pdf_sprint_number ( char *  buf,
double  value 
)

Definition at line 281 of file pdfdev.c.

{
  int  len;

  len = p_dtoa(value, DEV_PRECISION_MAX, buf);
  buf[len] = '\0'; /* xxx_sprint_xxx NULL terminates strings. */

  return  len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pdf_sprint_rect ( char *  buf,
const pdf_rect p 
)

Definition at line 239 of file pdfdev.c.

{
  int  len;

  len  = p_dtoa(rect->llx, dev_unit.precision, buf);
  buf[len++] = ' ';
  len += p_dtoa(rect->lly, dev_unit.precision, buf+len);
  buf[len++] = ' ';
  len += p_dtoa(rect->urx, dev_unit.precision, buf+len);
  buf[len++] = ' ';
  len += p_dtoa(rect->ury, dev_unit.precision, buf+len);
  buf[len]   = '\0'; /* xxx_sprint_xxx NULL terminates strings. */

  return  len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2003 of file pdfdev.c.

{
  /* Physical dimensions */
  info->width    = 0.0;
  info->height   = 0.0;
  info->depth    = 0.0;

  info->bbox.llx = 0.0;
  info->bbox.lly = 0.0;
  info->bbox.urx = 0.0;
  info->bbox.ury = 0.0;

  /* Transformation matrix */
  pdf_setmatrix(&(info->matrix), 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);

  info->flags    = 0;
}

Here is the caller graph for this function: