Back to index

wims  3.65+svn20090927
Defines | Functions | Variables
dvi.c File Reference
#include "dvicmd.c"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define DVI_post_post   DVI_post

Functions

void DVI_post (void)
void DVI_eop (void)
void DVI_bop (void)
void DVI_nop (void)
int DVI_put (int p)
void DVI_set (int p)
int DVI_put_rule (void)
void DVI_set_rule (void)
void DVI_fnt_num (int p)
void DVI_fnt_def (int p)
void DVI_push (void)
void DVI_pop (void)
void DVI_move (int *hv, int p)
void DVI_move2 (int *hv, int *xyz, int p)
void DVI_xxx (int p)
void dvi (void)

Variables

unsigned char * dvibuf
unsigned char * dviptr
int dvilen
int pass
int passstop
int num
int den
int mag
int minx
int maxx
int miny
int maxy
double dviratio
int dvix
int dviy
int d_h
int d_v
int d_w
int d_x
int d_y
int d_z
int d_f
int pageptr
struct {
int minx
int maxx
int miny
int maxy
pagedata [MAX_PAGES]
struct {
int h
int v
int w
int x
int y
int z
dvistack [DVI_STACK_LIMIT]
int dvistackptr

Define Documentation

Definition at line 39 of file dvi.c.


Function Documentation

void dvi ( void  )

Definition at line 245 of file dvi.c.

{
    unsigned char cc, *startpoint;
    char namebuf[1024];
    
    snprintf(namebuf,sizeof(namebuf),"%s/texgif.dvi",tmpdir);
    dvilen=getfile(namebuf,&dvibuf);
    if(dvilen<=0) error("dvi file not found.");
    dviptr=dvibuf; fontcnt=0;
    if(*dviptr++!=dvi_pre || *dviptr++!=2) {
       /* baddvi: */ error("Bad dvi file header.");
    }
    num=texint(dviptr,4); dviptr+=4;
    den=texint(dviptr,4); dviptr+=4;
    mag=texint(dviptr,4); dviptr+=4;
    cc=*dviptr++; dviptr+=cc; startpoint=dviptr;
    density=rint((double) compressratio*mag*basedensity/1000);
    dviratio=(double) num/den*density/254000;
printf("dvi file: num=%d, den=%d, ratio=%f, mag=%d, density=%d\n",
       num,den,dviratio, mag, density);
    for(pass=1; pass<=2; pass++) {
       passstop=0; d_f=-1; pageptr=0;
       for(dviptr=startpoint; dviptr<dvibuf+dvilen && passstop>=0; dviptr++) {
           if(*dviptr<128) {
              DVI_set(0); continue;
           }
           if(*dviptr>=171 && *dviptr<=234) {
              DVI_fnt_num(0); continue;
           }
           switch(*dviptr) {
              case dvi_set1: case dvi_set2: case dvi_set3:
              case dvi_set4: DVI_set(*dviptr-dvi_set1+1); break;
              case dvi_set_rule: DVI_set_rule(); break;
              
              case dvi_put1: case dvi_put2: case dvi_put3:
              case dvi_put4: DVI_put(*dviptr-dvi_put1+1); break;
              case dvi_put_rule: DVI_put_rule(); break;
              
              case dvi_nop: DVI_nop(); break;
              case dvi_bop: DVI_bop(); break;
              case dvi_eop: DVI_eop(); break;
              case dvi_push: DVI_push(); break;
              case dvi_pop: DVI_pop(); break;
              
              case dvi_right1: case dvi_right2: case dvi_right3:
              case dvi_right4: DVI_move(&d_h, *dviptr-dvi_right1+1); break;
              
              case dvi_w0: case dvi_w1: case dvi_w2: case dvi_w3:
              case dvi_w4: DVI_move2(&d_h, &d_w, *dviptr-dvi_w0); break;
              case dvi_x0: case dvi_x1: case dvi_x2: case dvi_x3:
              case dvi_x4: DVI_move2(&d_h, &d_x, *dviptr-dvi_x0); break;
       
              case dvi_down1: case dvi_down2: case dvi_down3:
              case dvi_down4: DVI_move(&d_v, *dviptr-dvi_down1+1); break;
              
              case dvi_y0: case dvi_y1: case dvi_y2: case dvi_y3:
              case dvi_y4: DVI_move2(&d_v, &d_y, *dviptr-dvi_y0); break;
              case dvi_z0: case dvi_z1: case dvi_z2: case dvi_z3:
              case dvi_z4: DVI_move2(&d_v, &d_z, *dviptr-dvi_z0); break;
              
              case dvi_fnt1: case dvi_fnt2: case dvi_fnt3:
              case dvi_fnt4: DVI_fnt_num(*dviptr-dvi_fnt1+1); break;
              
              case dvi_xxx1: case dvi_xxx2: case dvi_xxx3:
              case dvi_xxx4: DVI_xxx(*dviptr-dvi_xxx1+1); break;
              
              case dvi_fnt_def1: case dvi_fnt_def2: case dvi_fnt_def3:
              case dvi_fnt_def4: DVI_fnt_def(*dviptr-dvi_fnt_def1+1); break;
              
              case dvi_pre: error("Bad dvi file: pre within file.");
              case dvi_post: DVI_post(); break;
              case dvi_post_post: DVI_post_post(); break;
              
              default: error("Bad dvi file: unknown command.");
           }
       }
    }
    free(dvibuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DVI_bop ( void  )

Definition at line 61 of file dvi.c.

{
    passstop=1; dvistackptr=0;
    d_h=d_v=d_w=d_x=d_y=d_z=0; d_f=-1;
    dviptr+=44;
    if(pass==1) {
       minx=miny=65536;
       maxx=maxy=-1;
    }
    else {
       char *p;
       maxx=pagedata[pageptr].maxx;
       minx=pagedata[pageptr].minx;
       maxy=pagedata[pageptr].maxy;
       miny=pagedata[pageptr].miny;
       if(maxx<=minx || maxy<=miny) error("Empty page.");
       createimage(maxx-minx,maxy-miny);
       currentcolor=color_black;
       p=getenv("w_instex_color");
       if(p!=NULL && *p!=0) makecolor(p);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DVI_eop ( void  )

Definition at line 45 of file dvi.c.

{
    if(pass==1) {
       pagedata[pageptr].minx=minx;
       pagedata[pageptr].maxx=maxx;
       pagedata[pageptr].miny=miny;
       pagedata[pageptr].maxy=maxy;
    }
    else saveimage();
    pageptr++;
    if(*outfile==0 || pageptr>=MAX_PAGES) {
       passstop=-1; dviptr=dvibuf+dvilen;
    }
    else passstop=0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DVI_fnt_def ( int  p)

Definition at line 157 of file dvi.c.

{
    int i, fnum, fdensity;
    char fname[1024];
    unsigned long int c,s,d,a,l;
    double fratio;
    union { unsigned long c; char C[4]; } U;

    if(fontcnt>=FONT_NUMBER_LIMIT) error("Font number exceeded design capacity.");
    fnum=texint(++dviptr,p); dviptr+=p;
    for (i = 0; i <= 3; i++) U.C[i] = dviptr[i];
    c=U.c; dviptr+=4;
    s=texint(dviptr,4); dviptr+=4;
    d=texint(dviptr,4); dviptr+=4;
    a=*dviptr++; l=*dviptr++;
    if(a+l>1000 || a+l<1) error("Bad dvi: bad font name.");
    memmove(fname,dviptr,a+l); fname[a+l]=0; dviptr+=a+l-1;
    if(pass==1) {
       fdensity=(double) density*((double) s/d);
       if(loadfont(fname, c, fdensity, wfont+fontcnt)==NULL) {
           if(loadfont("cmr10",0,fdensity,wfont+fontcnt)==NULL) 
             error("Font panick: even cmr10 cannot be found.");
           else fprintf(stderr,"Font %s not found; replace by cmr10.\n",fname);
       }
       wfont[fontcnt].num=fnum;
       fratio=(double) s/wfont[fontcnt].designsize*d/65536;
       for(i=0;i<wfont[fontcnt].cnt; i++)
         wfont[fontcnt].fh[i].w=fratio*wfont[fontcnt].fh[i].w;
       fontcnt++;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DVI_fnt_num ( int  p)

Definition at line 148 of file dvi.c.

{
    int fnum;
    if(p==0) fnum=*dviptr-171; else fnum=texint(dviptr+1,p);
    dviptr+=p;
    for(d_f=0; d_f<fontcnt && wfont[d_f].num!=fnum; d_f++);
    if(d_f>=fontcnt) error("Bad dvi: using font before defining it.");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DVI_move ( int *  hv,
int  p 
)

Definition at line 213 of file dvi.c.

{
    int t;
    t=texintsigned(dviptr+1,p); dviptr+=p;
    *hv+=t;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DVI_move2 ( int *  hv,
int *  xyz,
int  p 
)

Definition at line 220 of file dvi.c.

{
    if(p>0) *xyz=texintsigned(dviptr+1,p);
    *hv+=*xyz;
    dviptr+=p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DVI_nop ( void  )

Definition at line 84 of file dvi.c.

{}

Here is the caller graph for this function:

void DVI_pop ( void  )

Definition at line 201 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void DVI_post ( void  )

Definition at line 40 of file dvi.c.

Here is the caller graph for this function:

void DVI_push ( void  )

Definition at line 189 of file dvi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int DVI_put ( int  p)

Definition at line 86 of file dvi.c.

{
    int cc, ct, x1, x2, y1, y2;
    if(d_f<0) error("Bad dvi: trying to put non-existing font.");
    if(p==0) cc=*dviptr; else cc=texint(dviptr+1,p);
    dviptr+=p;
    if(cc<wfont[d_f].bc || cc>wfont[d_f].ec) return -1;
    dvix=rint(dviratio*d_h); dviy=rint(dviratio*d_v);
    if(pass==1) {
       ct=cc-wfont[d_f].bc;
       x1=dvix+wfont[d_f].fh[ct].xstart; y1=dviy+wfont[d_f].fh[ct].ystart;
       x2=x1+wfont[d_f].fh[ct].xmax; y2=y1+wfont[d_f].fh[ct].ymax;
       if(minx>x1) minx=x1; if(miny>y1) miny=y1;
       if(maxx<x2) maxx=x2; if(maxy<y2) maxy=y2;
    }
    else {
       paintfont(wfont+d_f,cc,dvix-minx,dviy-miny,currentcolor);
    }
    return cc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int DVI_put_rule ( void  )

Definition at line 115 of file dvi.c.

{
    int xxx, xx, yy, x1, y1, x2, y2, xx1, xx2, yy1, yy2;
    yy=texint(dviptr+1,4); xx=texint(dviptr+5,4); dviptr+=8;
    if(xx<=0 || yy<=0) return xx;
    xxx=xx;
    if(xx>=0) {xx=rint(dviratio*xx+blacker); if(xx>0) xx--;}
    else {xx=rint(dviratio*xx-blacker); if(xx<0) xx--;}
    if(yy>=0) {yy=rint(dviratio*yy+blacker); if(yy>0) yy--;}
    else {yy=rint(dviratio*yy-blacker); if(yy<0) yy--;}
    if(pass==1) {
       x1=rint(dviratio*d_h); y2=rint(dviratio*d_v);
       x2=x1+xx; y1=y2-yy;
       if(x1<x2) {xx1=x1; xx2=x2;} else {xx1=x2; xx2=x1;}
       if(y1<y2) {yy1=y1; yy2=y2;} else {yy1=y2; yy2=y1;}
       if(minx>x1) minx=x1; if(miny>y1) miny=y1;
       if(maxx<x2) maxx=x2; if(maxy<y2) maxy=y2;
    }
    else {
       x1=rint(dviratio*d_h)-minx; y1=rint(dviratio*d_v)-miny;
       x2=x1+xx; y2=y1-yy;
       if(x1<x2) {xx1=x1; xx2=x2;} else {xx1=x2; xx2=x1;}
       if(y1<y2) {yy1=y1; yy2=y2;} else {yy1=y2; yy2=y1;}
       gdImageFilledRectangle(image,xx1,yy1,xx2,yy2,currentcolor);
    }
    return xxx;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DVI_set ( int  p)

Definition at line 107 of file dvi.c.

{
    int cc;
    cc=DVI_put(p);
    if(cc<0) return;
    d_h+=wfont[d_f].fh[cc-wfont[d_f].bc].w;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DVI_set_rule ( void  )

Definition at line 143 of file dvi.c.

{
    d_h+=DVI_put_rule();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DVI_xxx ( int  p)

Definition at line 227 of file dvi.c.

{
    int i, t;
    char *pp, buf[1024];
    
    t=texint(dviptr+1,p);
    if(pass<2 || t>1000) {dviptr+=t+p; return;}
    memmove(buf,dviptr+1+1,t); buf[t]=0;
    dviptr+=t+p;
    for(i=0;i<t;i++) buf[i]=tolower(buf[i]);
    if(strncmp(buf,"color",5)!=0) return;
    pp=find_word_start(buf+5); if(*pp!='=') return;
    makecolor(pp+1);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int d_f

Definition at line 28 of file dvi.c.

int d_h

Definition at line 27 of file dvi.c.

int d_v

Definition at line 27 of file dvi.c.

int d_w

Definition at line 27 of file dvi.c.

int d_x

Definition at line 27 of file dvi.c.

int d_y

Definition at line 27 of file dvi.c.

int d_z

Definition at line 27 of file dvi.c.

int den

Definition at line 23 of file dvi.c.

unsigned char* dvibuf

Definition at line 20 of file dvi.c.

int dvilen

Definition at line 21 of file dvi.c.

unsigned char * dviptr

Definition at line 20 of file dvi.c.

double dviratio

Definition at line 25 of file dvi.c.

struct { ... } dvistack[DVI_STACK_LIMIT]

Definition at line 37 of file dvi.c.

int dvix

Definition at line 26 of file dvi.c.

int dviy

Definition at line 26 of file dvi.c.

int mag

Definition at line 23 of file dvi.c.

int maxx

Definition at line 24 of file dvi.c.

int maxy

Definition at line 24 of file dvi.c.

int minx

Definition at line 24 of file dvi.c.

int miny

Definition at line 24 of file dvi.c.

int num

Definition at line 23 of file dvi.c.

struct { ... } pagedata[MAX_PAGES]
int pageptr

Definition at line 29 of file dvi.c.

int pass

Definition at line 22 of file dvi.c.

int passstop

Definition at line 22 of file dvi.c.