home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fonts 1
/
freshfonts1.bin
/
bbs
/
programs
/
amiga
/
pastex13.lha
/
DVIPS
/
dvips5519.lha
/
dvips
/
emspecial.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-12
|
35KB
|
1,479 lines
/*
* emspecial.c
* This routine handles the emTeX special commands.
*/
#include "dvips.h" /* The copyright notice in that file is included too!*/
#include <ctype.h>
extern int atoi();
extern FILE *search();
extern char *getenv();
/*
* These are the external routines called:
*/
/**/
extern void hvpos() ;
extern void cmdout() ;
extern void mhexout() ;
extern void nlcmdout() ;
extern void newline() ;
extern void floatout() ;
extern void numout() ;
extern void error() ;
extern void specerror() ;
extern char errbuf[] ;
extern shalfword linepos;
extern FILE *bitfile;
extern int actualdpi ;
extern int vactualdpi ;
extern integer hh, vv;
extern char *figpath ;
extern int prettycolumn ;
extern int quiet;
extern Boolean disablecomments ;
#ifdef DEBUG
extern integer debug_flag;
#endif
#ifdef EMTEX
/* emtex specials, added by rjl */
#define EMMAX 1613 /* maximum number of emtex special points */
#define TRUE 1
#define FALSE 0
/*
* We define these seek constants if they don't have their
* values already defined.
*/
#ifndef SEEK_SET
#define SEEK_SET (0)
#endif
#ifndef SEEK_END
#define SEEK_END (2)
#endif
struct empt {
shalfword point;
integer x, y;
};
struct empt *empoints = NULL;
boolean emused = FALSE; /* true if em points used on this page */
integer emx, emy;
struct emunit {
char *unit;
float factor;
};
struct emunit emtable[] = {
{"pt",72.27},
{"pc",72.27/12},
{"in",1.0},
{"bp",72.0},
{"cm",2.54},
{"mm",25.4},
{"dd",72.27/(1238/1157)},
{"cc",72.27/12/(1238/1157)},
{"sp",72.27*65536},
{"",0.0}
};
/* clear the empoints array if necessary */
void
emclear()
{
int i;
if (emused && empoints)
for (i=0; i<EMMAX; i++)
empoints[i].point = 0;
emused = FALSE ;
}
/* put an empoint into the empoints array */
struct empt *emptput(point, x, y)
shalfword point;
integer x, y;
{
int i, start;
emused = TRUE;
start = point % EMMAX;
i = start;
while ( empoints[i].point != 0 ) {
if ( empoints[i].point == point )
break;
i++;
if (i >= EMMAX)
i = 0;
if (i == start) {
sprintf(errbuf,"!Too many em: special points");
specerror(errbuf);
}
}
empoints[i].point = point;
empoints[i].x = x;
empoints[i].y = y;
return(&empoints[i]);
}
/* get an empoint from the empoints array */
struct empt *emptget(point)
shalfword point;
{
int i, start;
start = point % EMMAX;
i = start;
if (emused == TRUE)
while ( empoints[i].point != 0 ) {
if (empoints[i].point == point)
return(&empoints[i]);
i++;
if (i >= EMMAX)
i = 0;
if (i == start)
break;
}
sprintf(errbuf,"!em: point %d not defined",point);
specerror(errbuf);
return(NULL); /* never returns due to error */
}
/* convert width into dpi units */
float emunits(width,unit)
float width;
char *unit;
{
struct emunit *p;
for (p=emtable; *(p->unit)!='\0'; p++) {
if (strcmp(p->unit,unit)==0)
return( width * actualdpi / p->factor );
}
return (-1.0); /* invalid unit */
}
/* The main routine for \special{em:graph ...} called from dospecial.c */
/* the line cut parameter is not supported (and is ignored) */
void emspecial(p)
char *p ;
{
float emwidth, emheight;
shalfword empoint1, empoint2;
struct empt *empoint;
char emunit[3];
char emstr[80];
char *emp;
void emgraph();
hvpos() ;
for (emp = p+3; *emp && isspace(*emp); emp++); /* skip blanks */
if (strncmp(emp, "linewidth", 9) == 0) {
/* code for linewidth */
for (emp = emp+9; *emp && isspace(*emp); emp++); /* skip blanks */
sscanf(emp, "%f%2s", &emwidth, emunit);
emwidth = emunits(emwidth,emunit);
if (emwidth!=-1.0) {
sprintf(emstr,"%.1f setlinewidth", emwidth);
cmdout(emstr);
#ifdef DEBUG
if (dd(D_SPECIAL))
(void)fprintf(stderr, "em special: Linewidth set to %.1f dots\n",
emwidth) ;
#endif
} else {
sprintf(errbuf,"Unknown em: special width");
specerror(errbuf);
}
}
else if (strncmp(emp, "moveto", 6) == 0) {
#ifdef DEBUG
if (dd(D_SPECIAL))
#ifdef SHORTINT
(void)fprintf(stderr, "em special: moveto %ld,%ld\n", hh, vv);
#else
(void)fprintf(stderr, "em special: moveto %d,%d\n", hh, vv);
#endif
#endif
emx = hh;
emy = vv;
}
else if (strncmp(emp, "lineto", 6) == 0) {
#ifdef DEBUG
if (dd(D_SPECIAL))
#ifdef SHORTINT
(void)fprintf(stderr, "em special: lineto %ld,%ld\n", hh, vv);
#else
(void)fprintf(stderr, "em special: lineto %d,%d\n", hh, vv);
#endif
#endif
cmdout("np");
numout(emx);
numout(emy);
cmdout("a");
numout(hh);
numout(vv);
cmdout("li");
cmdout("st");
emx = hh;
emy = vv;
}
else if (strncmp(emp, "point", 5) == 0) {
if (empoints == NULL) {
empoints =
(struct empt *)mymalloc((integer)EMMAX * sizeof(struct empt)) ;
emused = TRUE;
emclear();
}
for (emp = emp+5; *emp && isspace(*emp); emp++); /* skip blanks */
empoint1 = (shalfword)atoi(emp);
empoint = emptput(empoint1,hh,vv);
#ifdef DEBUG
if (dd(D_SPECIAL))
#ifdef SHORTINT
(void)fprintf(stderr, "em special: Point %d is %ld,%ld\n",
#else
(void)fprintf(stderr, "em special: Point %d is %d,%d\n",
#endif
empoint->point, empoint->x, empoint->y) ;
#endif
}
else if (strncmp(emp, "line", 4) == 0) {
for (emp = emp+4; *emp && isspace(*emp); emp++); /* skip blanks */
empoint1 = (shalfword)atoi(emp);
for (; *emp && isdigit(*emp); emp++); /* skip point 1 */
if ( *emp && strchr("hvp",*emp)!=0 )
emp++; /* skip line cut */
for (; *emp && isspace(*emp); emp++); /* skip blanks */
if ( *emp && (*emp==',') )
emp++; /* skip comma separator */
for (; *emp && isspace(*emp); emp++); /* skip blanks */
empoint2 = (shalfword)atoi(emp);
for (; *emp && isdigit(*emp); emp++); /* skip point 2 */
if ( *emp && strchr("hvp",*emp)!=0 )
emp++; /* skip line cut */
for (; *emp && isspace(*emp); emp++); /* skip blanks */
if ( *emp && (*emp==',') )
emp++; /* skip comma separator */
emwidth = -1.0;
emunit[0]='\0';
sscanf(emp, "%f%2s", &emwidth, emunit);
emwidth = emunits(emwidth,emunit);
#ifdef DEBUG
if (dd(D_SPECIAL))
(void)fprintf(stderr, "em special: Line from point %d to point %d\n",
empoint1, empoint2) ;
#endif
cmdout("np");
if (emwidth!=-1.0) {
#ifdef DEBUG
if (dd(D_SPECIAL))
(void)fprintf(stderr,"em special: Linewidth temporarily set to %.1f dots\n",
emwidth) ;
#endif
strcpy(emstr,"currentlinewidth");
cmdout(emstr);
sprintf(emstr,"%.1f setlinewidth", emwidth);
cmdout(emstr);
}
empoint = emptget(empoint1);
numout(empoint->x);
numout(empoint->y);
cmdout("a");
empoint = emptget(empoint2);
numout(empoint->x);
numout(empoint->y);
cmdout("li");
cmdout("st");
if (emwidth!=-1.0) {
strcpy(emstr,"setlinewidth");
cmdout(emstr);
}
}
else if (strncmp(emp, "message", 7) == 0) {
(void)fprintf(stderr, "em message: %s\n", emp+7) ;
}
else if (strncmp(emp, "graph", 5) == 0) {
int i;
for (emp = emp+5; *emp && isspace(*emp); emp++); /* skip blanks */
for (i=0; *emp && !isspace(*emp) && !(*emp==',') ; emp++)
emstr[i++] = *emp; /* copy filename */
emstr[i] = '\0';
/* now get optional width and height */
emwidth = emheight = -1.0; /* no dimension is <= 0 */
for (; *emp && ( isspace(*emp) || (*emp==',') ); emp++)
; /* skip blanks and comma */
if (*emp) {
sscanf(emp, "%f%2s", &emwidth, emunit); /* read width */
emwidth = emunits(emwidth,emunit); /* convert to pixels */
for (; *emp && ( isdigit(*emp) || isalpha(*emp) ); emp++)
; /* skip width dimension */
for (; *emp && ( isspace(*emp) || (*emp==',') ); emp++)
; /* skip blanks and comma */
if (*emp) {
sscanf(emp, "%f%2s", &emheight, emunit); /* read height */
emheight = emunits(emheight,emun