This is printgl.c in view mode; [Download] [Up]
#include "incl.h"
extern FILE *fpo, *fpi;
extern char buffer[];
extern int inlinecount, outlinecount;
extern double llx, lly, urx, ury, scx, scy;
printgl ()
{
double res_fac, linewidth;
int i, j, n, x, y, lx, by, rx, uy;
char str1[MAXWORD+1], buf[MAXWORD+1];
char *p[MAXTOKENS], *cp;
/*
** Do some initialization.
*/
lx = 10000;
by = 10000;
rx = 0;
uy = 0;
/*
** Get the x- and y picture limits in points.
*/
for (fgets (buffer, MAXBUF, fpi); (!(feof (fpi)));
fgets (buffer, MAXBUF, fpi)) {
i = 0;
p[i++] = strtok (buffer, SEP_CHARS);
while ((p[i++] = strtok (NULL, SEP_CHARS)) != NULL);
n = i - 1;
for (j = 0; j < n; j++) {
if (strcmp (p[j], MOVE_TO) == 0 || strcmp (p[j], LINE_TO) == 0) {
x = atoi (p[j - 2]);
y = atoi (p[j - 1]);
if (x < lx) lx = x;
else if (x > rx) rx = x;
if (y < by) by = y;
else if (y > uy) uy = y;
}
}
}
rewind (fpi);
/*
** Set BoundingBox values.
** Values must be scaled down from PrintGL to PostScript resolution.
** PostScript resolution: 72 pt/inch.
** PrintGL resolution : 1016 pt/inch.
*/
res_fac = (double) POSTSCRIPT_RES / PRINTGL_RES;
llx = lx * res_fac;
lly = by * res_fac;
urx = rx * res_fac;
ury = uy * res_fac;
scx = 1.0;
scy = 1.0;
/*
** Adjust BoundingBox and scale values depending on width (-w)
** height (-h) and space (-s) options.
*/
if (adj_bbox (urx - llx) == EXIT_FAILURE) return (EXIT_FAILURE);
/*
** Replace first line
*/
fgets (buffer, MAXBUF, fpi);
inlinecount++;
fprintf (fpo, "%s", FIRSTLINE);
outlinecount++;
/*
** Replace BoundingBox statement.
*/
for (fgets (buffer, MAXBUF, fpi); (!(feof (fpi)));
fgets (buffer, MAXBUF, fpi)) {
inlinecount++;
sscanf (buffer, "%s", str1);
if (strcmp (str1, PPBOUNDINGBOXC) == 0) {
fprintf (fpo, "%s %d %d %d %d\n", PPBOUNDINGBOXC,
(int)llx, (int)lly, (int)urx, (int)ury);
fprintf (fpo, "%s: 0 1\n", PPPAGES);
fprintf (fpo, "%s\n", PPENDCOMMENTS);
/*
** Insert next statement for use with program ``dvialw''
*/
fprintf (fpo, "%s", DVIALW_BEGIN);
outlinecount += 4;
break;
}
else {
fprintf (fpo, "%s", buffer);
outlinecount++;
}
}
/*
** Scan rest of input file.
*/
for (fgets (buffer, MAXBUF, fpi); (!(feof (fpi)));
fgets (buffer, MAXBUF, fpi)) {
inlinecount++;
sscanf (buffer, "%s", str1);
/*
** The effective linewidth is the product of the initial linewidth
** and the scaling factor.
** When we want a constant linewidth the initial linewidth has to
** be changed depending on the scaling factor.
*/
if (strcmp (str1, "/SP1") == 0 || strcmp (str1, "/SP2") == 0) {
fprintf (fpo, "%s%s", PPP, buffer);
outlinecount++;
fprintf (fpo, "%s { ", str1);
sscanf (buffer, "%*s%*s%lf", &linewidth);
linewidth /= scx;
fprintf (fpo, "%.2lf ", linewidth);
fprintf (fpo, "%s", (buffer + 9));
outlinecount++;
}
/*
** After 'scale' in the statement beginning with 'gsave' there is
** a translation.
** The translation is user supplied by means of the /lf option
** of the PrintGL program.
** This translation isn't of any sense for inserting the picture
** into a LaTeX file so it's deleted.
*/
else if (strcmp (str1, GSAVE) == 0) {
fprintf (fpo, "%s%s", PPP, buffer);
outlinecount++;
strcpy (buf, strtok (buffer, SEP_CHARS));
strcat (buf, " ");
while (strcmp ((cp = strtok (NULL, SEP_CHARS)), SCALE) != 0) {
strcat (buf, cp);
strcat (buf, " ");
}
strcat (buf, cp);
fprintf (fpo, "%s\n", buf);
/*
** Insert scale statement.
** Scale factors may have been changed by -w and/or -h option.
*/
fprintf (fpo, "%.3lf %.3lf %s\n", scx, scy, SCALE);
outlinecount += 2;
}
else if ((strcmp (str1, SHOWPAGE)) == 0) {
/*
** Insert next statement for use with program ``dvialw''
*/
fprintf (fpo, "%s", DVIALW_END);
fprintf (fpo, "%s", buffer);
outlinecount += 2;
}
else {
fprintf (fpo, "%s", buffer);
outlinecount++;
}
}
return (EXIT_SUCCESS);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.