Back to index

tetex-bin  3.0
Classes | Defines | Functions | Variables
tpic.c File Reference
#include <string.h>
#include <stdlib.h>
#include "system.h"
#include "mem.h"
#include "mfileio.h"
#include "tpic.h"
#include "pdfparse.h"
#include "pdfdoc.h"
#include "pdfdev.h"
#include "dvi.h"

Go to the source code of this file.

Classes

struct  path

Defines

#define MI2DEV   (0.072/pdf_dev_scale())
#define ROTATE(x, y, c, s)   {new_x=(c)*(x)-(s)*(y);new_y=(s)*(x)+(c)*(y);x=new_x,y=new_y;}
#define MAX_ANG_STEP   1.0
#define TPIC_PN   1
#define TPIC_PA   2
#define TPIC_FP   3
#define TPIC_IP   4
#define TPIC_DA   5
#define TPIC_DT   6
#define TPIC_SP   7
#define TPIC_AR   8
#define TPIC_IA   9
#define TPIC_SH   10
#define TPIC_WH   11
#define TPIC_BK   12
#define TPIC_TX   13

Functions

static void tpic_clear_state (void)
static void set_pen_size (char **buffer, char *end)
static void set_fill_color (char **buffer, char *end)
static void add_point (char **buffer, char *end)
static void show_path (int hidden)
static void flush_path (double x_user, double y_user, int hidden, double dash_dot)
static void spline_path (double x_user, double y_user, double dash_dot)
static void arc (char **buffer, char *end, double x_user, double y_user, int hidden)
int tpic_parse_special (char *buffer, UNSIGNED_QUAD size, double x_user, double y_user)

Variables

double pen_size = 1.0
int fill_shape = 0
double fill_color = 0.0
double default_fill_color = 0.5
static struct pathpath
unsigned long path_length = 0
unsigned long max_path_length = 0
struct {
char * s
int tpic_command
tpic_specials []

Class Documentation

struct path

Definition at line 44 of file tpic.c.

Class Members
double x
double y

Define Documentation

#define MAX_ANG_STEP   1.0
#define MI2DEV   (0.072/pdf_dev_scale())

Definition at line 39 of file tpic.c.

#define ROTATE (   x,
  y,
  c,
  s 
)    {new_x=(c)*(x)-(s)*(y);new_y=(s)*(x)+(c)*(y);x=new_x,y=new_y;}
#define TPIC_AR   8

Definition at line 337 of file tpic.c.

#define TPIC_BK   12

Definition at line 341 of file tpic.c.

#define TPIC_DA   5

Definition at line 334 of file tpic.c.

#define TPIC_DT   6

Definition at line 335 of file tpic.c.

#define TPIC_FP   3

Definition at line 332 of file tpic.c.

#define TPIC_IA   9

Definition at line 338 of file tpic.c.

#define TPIC_IP   4

Definition at line 333 of file tpic.c.

#define TPIC_PA   2

Definition at line 331 of file tpic.c.

#define TPIC_PN   1

Definition at line 330 of file tpic.c.

#define TPIC_SH   10

Definition at line 339 of file tpic.c.

#define TPIC_SP   7

Definition at line 336 of file tpic.c.

#define TPIC_TX   13

Definition at line 342 of file tpic.c.

#define TPIC_WH   11

Definition at line 340 of file tpic.c.


Function Documentation

static void add_point ( char **  buffer,
char *  end 
) [static]

Definition at line 93 of file tpic.c.

{
  char *x= NULL, *y= NULL;
MEM_START
  skip_white (buffer, end);
  if (*buffer < end)
    x = parse_number (buffer, end);
  skip_white (buffer, end);
  if (*buffer < end)
    y = parse_number (buffer, end);
  if ((x) && (y)) {
    if (path_length >= max_path_length) {
      max_path_length += 256;
      path = RENEW (path, max_path_length, struct path);
    }
    path[path_length].x = atof(x)*MI2DEV;
    path[path_length].y = atof(y)*MI2DEV;
    path_length += 1;
  } else {
    dump (*buffer, end);
    fprintf (stderr, "tpic special: pa: Missing coordinate\n");
  }
  if (x) RELEASE(x);
  if (y) RELEASE(y);
MEM_END
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void arc ( char **  buffer,
char *  end,
double  x_user,
double  y_user,
int  hidden 
) [static]

Definition at line 251 of file tpic.c.

{
  char *xcs= NULL, *ycs= NULL,
    *xrs=NULL, *yrs=NULL, *sas=NULL, *eas=NULL;
  char *save;
  double xc, yc, xr, yr, sa, ea;
MEM_START
  save = *buffer;
/* pen_size == 0 is equivalent to hidden */ 
  if (pen_size == 0)
    hidden = 1;
  if ((xcs=parse_number(buffer, end)) &&
      (ycs=parse_number(buffer, end)) &&
      (xrs=parse_number(buffer, end)) &&
      (yrs=parse_number(buffer, end)) &&
      (sas=parse_number(buffer, end)) &&
      (eas=parse_number(buffer, end))) {
    double c, s, cur_x, cur_y, inc_ang;
    double cp1_x, cp1_y, cp2_x, cp2_y;
    double new_x, new_y;
    int len, i, nsteps;
    xc=atof (xcs)*MI2DEV; yc=atof (ycs)*MI2DEV;
    xr=atof (xrs)*MI2DEV; yr=atof (yrs)*MI2DEV;
    sa=atof (sas); ea=atof (eas);
#define ROTATE(x,y,c,s) {new_x=(c)*(x)-(s)*(y);new_y=(s)*(x)+(c)*(y);x=new_x,y=new_y;}
    #define MAX_ANG_STEP 1.0
    nsteps = (int) ((ea-sa)/MAX_ANG_STEP) + 1;
    inc_ang = (ea-sa)/nsteps;
    c = cos(inc_ang); s = sin(inc_ang);
    cur_x=cos(sa); cur_y=sin(sa);
    cp1_x = cur_x - inc_ang/3.0*cur_y;
    cp1_y = cur_y + inc_ang/3.0*cur_x;
    cp2_x = cur_x + inc_ang/3.0*cur_y;
    cp2_y = cur_y - inc_ang/3.0*cur_x;
    sprintf (work_buffer, " q");
    len = strlen (work_buffer);
    pdf_doc_add_to_page (work_buffer, len);
    if (pen_size != 0.0) {
      sprintf (work_buffer, " %.2f w", pen_size);
      len = strlen (work_buffer);
     }
    pdf_doc_add_to_page (work_buffer, len);
    sprintf (work_buffer, " 1 J");
    len = strlen (work_buffer);
    pdf_doc_add_to_page (work_buffer, len);
    sprintf (work_buffer, " %.2f %.2f m", x_user+xr*cur_x+xc, y_user-yr*cur_y-yc);
    len = strlen (work_buffer);
    pdf_doc_add_to_page (work_buffer, len);
    ROTATE (cp2_x, cp2_y, c, s);
    ROTATE (cur_x, cur_y, c, s);
    for (i=0; i<nsteps; i++) {
      sprintf (work_buffer, " %.2f %.2f %.2f %.2f %.2f %.2f c",
              x_user+xr*cp1_x+xc, y_user-yr*cp1_y-yc,
              x_user+xr*cp2_x+xc, y_user-yr*cp2_y-yc,
              x_user+xr*cur_x+xc, y_user-yr*cur_y-yc);
      len = strlen (work_buffer);
      pdf_doc_add_to_page (work_buffer, len);
      ROTATE (cur_x, cur_y, c, s);
      ROTATE (cp1_x, cp1_y, c, s);
      ROTATE (cp2_x, cp2_y, c, s);
    }
    show_path (hidden);
    pdf_doc_add_to_page (" Q", 2);
  } else {
    dump (save, end);
    fprintf (stderr, "tpic special: ar/ir: Error in parameters\n");
  }
  if (xcs) RELEASE(xcs);
  if (ycs) RELEASE(ycs);
  if (xrs) RELEASE(xrs);
  if (yrs) RELEASE(yrs);
  if (sas) RELEASE(sas);
  if (eas) RELEASE(eas);
MEM_END
  tpic_clear_state();
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void flush_path ( double  x_user,
double  y_user,
int  hidden,
double  dash_dot 
) [static]

Definition at line 146 of file tpic.c.

{
  int len;
MEM_START
  /* Make pen_size == 0 equivalent to hidden */
  if (pen_size == 0)
    hidden = 1;
  if (path_length > 1) {
    int i;
    sprintf (work_buffer, " q");
    len = strlen (work_buffer);
    pdf_doc_add_to_page (work_buffer, len);
    if (pen_size != 0.0) {
      sprintf (work_buffer, " %.2f w", pen_size);
      len = strlen (work_buffer);
    }
    pdf_doc_add_to_page (work_buffer, len);
    sprintf (work_buffer, " 1 J 1 j");
    len = strlen (work_buffer);
    pdf_doc_add_to_page (work_buffer, len);
    if (dash_dot != 0.0) {
      if (dash_dot > 0.0) {
       sprintf (work_buffer, " [%.1f %.1f] 0 d",
               dash_dot*72.0, dash_dot*36.0);
        len = strlen (work_buffer);
      } else {
       sprintf (work_buffer, " [%.1f %.1f] 0 d", pen_size,
               -dash_dot*72.0);
        len = strlen (work_buffer);
      }
      pdf_doc_add_to_page (work_buffer, len);
    }
    sprintf (work_buffer, " %.2f %.2f m",
            x_user+path[0].x, y_user-path[0].y);
    len = strlen (work_buffer);
    pdf_doc_add_to_page (work_buffer, len);
    for (i=0; i<path_length; i++) {
      sprintf (work_buffer, " %.2f %.2f l", x_user+path[i].x, y_user-path[i].y);
      len = strlen (work_buffer);
      pdf_doc_add_to_page (work_buffer, len);
    } 
    show_path (hidden);
    pdf_doc_add_to_page (" Q", 2);
  } else {
    fprintf (stderr, "tpic special: fp: Not enough points!\n");
  }
  tpic_clear_state();
MEM_END
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_fill_color ( char **  buffer,
char *  end 
) [static]

Definition at line 75 of file tpic.c.

{
  char *number;
MEM_START
  fill_shape = 1;
  fill_color = default_fill_color; 
  skip_white (buffer, end);
  if ((number = parse_number(buffer, end))) {
    fill_color = 1.0 - atof (number);
    if (fill_color > 1.0)
      fill_color = 1.0;
    if (fill_color < 0.0)
      fill_color = 0.0;
    RELEASE (number);
  }
MEM_END
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_pen_size ( char **  buffer,
char *  end 
) [static]

Definition at line 62 of file tpic.c.

{
  char *number;
  skip_white (buffer, end);
  if ((number = parse_number(buffer, end))) {
    pen_size = atof (number) * MI2DEV;
    RELEASE (number);
  } else {
    dump (*buffer, end);
    fprintf (stderr, "tpic special: pn: Invalid pen size\n");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void show_path ( int  hidden) [static]

Definition at line 121 of file tpic.c.

{
  int len;
  /* The semantics of a fill_color of 0.0 or 0.5 will be to use current
     painting color known to dvipdfm */
  if (fill_shape && fill_color != 0.0) {
    sprintf (work_buffer, " %.2f g", fill_color);
    len = strlen (work_buffer);
    pdf_doc_add_to_page (work_buffer, len);
  }
  if (!hidden && fill_shape) {
    pdf_doc_add_to_page (" b", 2);
  }
  if (hidden && fill_shape) {
    pdf_doc_add_to_page (" f", 2);
  }
  if (!hidden && !fill_shape)
    pdf_doc_add_to_page (" S", 2);
  if (fill_shape)
    fill_shape = 0;
  fill_color = 0.0;
  fill_shape = 0.0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void spline_path ( double  x_user,
double  y_user,
double  dash_dot 
) [static]

Definition at line 197 of file tpic.c.

{
  int len;
MEM_START
  /* Spline is meaningless for path length of less than 3 */
  if (path_length > 2) {
    int i;
    sprintf (work_buffer, " q 1.4 M %.2f w", pen_size);
    len = strlen (work_buffer);
    pdf_doc_add_to_page (work_buffer, len);
    if (dash_dot != 0.0) {
      if (dash_dot > 0.0) {
       sprintf (work_buffer, " [%.1f %.1f] 0 d",
               dash_dot*72.0, dash_dot*36.0);
        len = strlen (work_buffer);
      } else if (dash_dot < 0.0) {
       sprintf (work_buffer, " [%.1f %.1f] 0 d 1 J", pen_size,
               -dash_dot*72.0);
        len = strlen (work_buffer);
      }
      pdf_doc_add_to_page (work_buffer, len);
    }
    sprintf (work_buffer, " %.2f %.2f m",
            x_user+path[0].x, y_user-path[0].y);
    len = strlen (work_buffer);
    pdf_doc_add_to_page (work_buffer, len);
    sprintf (work_buffer, " %.2f %.2f l",
            x_user+0.5*(path[0].x+path[1].x), 
            y_user-0.5*(path[0].y+path[1].y));
    len = strlen (work_buffer);
    pdf_doc_add_to_page (work_buffer, len);
    for (i=1; i<path_length-1; i++) {
      sprintf (work_buffer, " %.2f %.2f %.2f %.2f y",
              x_user+path[i].x, y_user-path[i].y,
              x_user+0.5*(path[i].x+path[i+1].x),
              y_user-0.5*(path[i].y+path[i+1].y));
      len = strlen (work_buffer);
      pdf_doc_add_to_page (work_buffer, len);
    } 
    sprintf (work_buffer, " %.2f %.2f l",
            x_user+path[path_length-1].x,
            y_user-path[path_length-1].y);
    len = strlen (work_buffer);
    pdf_doc_add_to_page (work_buffer, len);
    show_path (0);
    pdf_doc_add_to_page (" Q", 2);
  } else {
    fprintf (stderr, "tpic special: sp: Not enough points!\n");
  }
  tpic_clear_state();
MEM_END
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void tpic_clear_state ( void  ) [static]

Definition at line 50 of file tpic.c.

{
  if ((path))
    RELEASE(path);
  path = NULL;
  path_length = 0;
  max_path_length = 0;
  fill_shape = 0;
  fill_color = 0.0;
  return;
}

Here is the caller graph for this function:

int tpic_parse_special ( char *  buffer,
UNSIGNED_QUAD  size,
double  x_user,
double  y_user 
)

Definition at line 363 of file tpic.c.

{
  int i, tpic_command, result = 0;
  char *end = buffer + size;
  char *token;
  skip_white (&buffer, end);
  if ((token = parse_ident (&buffer, end))) {
    for (i=0; i<(sizeof(tpic_specials)/sizeof(tpic_specials[0])); i++) {
      if (!strcmp (tpic_specials[i].s, token))
       break;
    }
    RELEASE (token);
  } else
    return 0;
  if (i < sizeof(tpic_specials)/sizeof(tpic_specials[0])) {
    tpic_command = tpic_specials[i].tpic_command;
    skip_white (&buffer, end);
    result = 1;
    switch (tpic_command) {
    case TPIC_PN:
      set_pen_size (&buffer, end);
      break;
    case TPIC_PA:
      add_point (&buffer, end);
      break;
    case TPIC_FP:
      flush_path(x_user, y_user, 0, 0.0);
      break;
    case TPIC_IP: 
      flush_path(x_user, y_user, 1, 0.0);
      break;
    case TPIC_DA:
      {
       char *s;
       if ((s=parse_number(&buffer, end))) {
         flush_path(x_user, y_user, 0, atof (s));
         RELEASE (s);
       }
      }
      break;
    case TPIC_DT:
      {
       char *s;
       if ((s=parse_number(&buffer, end))) {
         flush_path(x_user, y_user, 0, -atof (s));
         RELEASE (s);
       }
      }
      break;
    case TPIC_SP:
      {
       char *s;
       if ((s=parse_number(&buffer, end)))
         spline_path (x_user, y_user, atof (s));
       else
         spline_path(x_user, y_user, 0.0);
       break;
      }
    case TPIC_AR:
      arc (&buffer, end, x_user, y_user, 0);
      break;
    case TPIC_IA:
      arc (&buffer, end, x_user, y_user, 1);
      break;
    case TPIC_SH:
      set_fill_color (&buffer, end);
      break;
    case TPIC_WH: 
      fill_shape = 1;
      fill_color = 1.0;
      break;
    case TPIC_BK:
      fill_shape = 1;
      fill_color = 0.0;
      break;
    case TPIC_TX: 
      fill_shape = 1;
      {
       long num = 0, den = 0;
       while (buffer++ < end) {
         switch (*(buffer++)) {
         case '0':
           num += 0;
         case '1':
         case '2':
         case '4':
         case '8':
           num += 1;
           break;
         case '3':
         case '5':
         case '6':
         case '9':
         case 'a':
         case 'A':
         case 'c':
         case 'C':
           num += 2;
           break;
         case '7':
         case 'b':
         case 'B':
         case 'd':
         case 'D':
           num += 3;
           break;
         case 'f':
         case 'F':
           num += 4;
           break;
         default:
           break;
         }
         den += 16;
       }
       if (den != 0) {
         default_fill_color = 1.0 - (float) (num)/(den);
       }
       else {
         default_fill_color = 0.5;
       }
      }
      break;
    default:
      fprintf (stderr, "Fix me, I'm broke.  This should never happen");
      exit(1);
    }
  } else {
    result = 0;
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

double default_fill_color = 0.5

Definition at line 43 of file tpic.c.

double fill_color = 0.0

Definition at line 43 of file tpic.c.

Definition at line 42 of file tpic.c.

unsigned long max_path_length = 0

Definition at line 48 of file tpic.c.

struct path * path [static]
unsigned long path_length = 0

Definition at line 48 of file tpic.c.

double pen_size = 1.0

Definition at line 41 of file tpic.c.

struct { ... } tpic_specials[]