void drawtext ( char *buf /* whatever followed "x X DrawText */ ) { char *p; /* for eliminating white space etc. */ /* * * Called from devcntrl() whenever an "x X DrawText command is recognized. *buf * should contain three arguments in the following order. First comes the text we * want to print along the current baseline. Right now the string should be given * as a PostScript string using characters '(' and ')' as the delimiters. Next in * *buf comes a justification mode that can be the words left, right, or center. * Last comes a number that represents the starting value of the parameter t that's * given as the argument to the parametric equations that describe the current * baseline. For example if *buf is given by, * * (hello world) left .5 * * hello world will be printed along the path described by the current baseline * and left justified at whatever (x(.5), y(.5)) happens to be. Usually will be * preceeded by an "x X NewBaseline" call that defines the current baseline. The * origin of the coordinate system used by the parametric equations will be the * current point. * */ for ( p = buf; *p; p++ ) /* eliminate trailing '\n' */ if ( *p == '\n' ) { *p = '\0'; break; } /* End if */ for ( p = buf; *p && (*p == ' ' || *p == ':'); p++ ) ; if ( *p != '\0' ) { /* something's there */ endtext(); getbaseline(); xymove(hpos, vpos); fprintf(tf, "mark %s drawfunnytext\n", p); resetpos(); } /* End if */ } /* End of drawtext */
void picture ( char *buf /* stuff following 'x X PI' command */ ) { int poffset; /* page offset */ int indent; /* indent */ int length; /* line length */ int totrap; /* distance to next trap */ char name[4096]; /* picture file and page string */ char hwo[4096], *p; /* height, width and offset strings */ char flags[4096]; /* miscellaneous stuff */ int page = 1; /* page number pulled from name[] */ double frame[4]; /* height, width, y, and x offsets from hwo[] */ char units; /* scale indicator for frame dimensions */ int whiteout = 0; /* white out the box? */ int outline = 0; /* draw a box around the picture? */ int scaleboth = 0; /* scale both dimensions? */ double adjx = 0.5; /* left-right adjustment */ double adjy = 0.5; /* top-bottom adjustment */ double rot = 0; /* rotation in clockwise degrees */ FILE *fp_in; /* for *name */ int i; /* loop index */ /* * * Called from devcntrl() after an 'x X PI' command is found. The syntax of that * command is: * * x X PI:args * * with args separated by colons and given by: * * poffset * indent * length * totrap * file[(page)] * height[,width[,yoffset[,xoffset]]] * [flags] * * poffset, indent, length, and totrap are given in machine units. height, width, * and offset refer to the picture frame in inches, unless they're followed by * the u scale indicator. flags is a string that provides a little bit of control * over the placement of the picture in the frame. Rotation of the picture, in * clockwise degrees, is set by the a flag. If it's not followed by an angle * the current rotation angle is incremented by 90 degrees, otherwise the angle * is set by the number that immediately follows the a. * */ if ( picflag == OFF ) /* skip it */ return; endtext(); flags[0] = '\0'; /* just to be safe */ if ( sscanf(buf, "%d:%d:%d:%d:%[^:]:%[^:]:%[^:]", &poffset, &indent, &length, &totrap, name, hwo, flags) < 6 ) { error(NON_FATAL, "too few arguments to specify picture"); return; } /* End if */ if ( sscanf(name, "%*[^(](%d", &page) == 1 ) /* grab the page number */ strtok(name, "("); /* and separate it from the name */ if ( (fp_in = picopen(name)) == NULL ) { error(NON_FATAL, "can't open picture file %s", name); return; } /* End if */ frame[0] = frame[1] = -1; /* default frame height, width */ frame[2] = frame[3] = 0; /* and y and x offsets */ for ( i = 0, p = hwo-1; i < 4 && p != NULL; i++, p = strchr(p, ',') ) if ( sscanf(++p, "%lf%c", &frame[i], &units) == 2 ) if ( units == 'i' || units == ',' || units == '\0' ) frame[i] *= res; if ( frame[0] <= 0 ) /* check what we got for height */ frame[0] = totrap; if ( frame[1] <= 0 ) /* and width - check too big?? */ frame[1] = length - indent; frame[3] += poffset + indent; /* real x offset */ for ( i = 0; flags[i]; i++ ) switch ( flags[i] ) { case 'c': adjx = adjy = 0.5; break; /* move to the center */ case 'l': adjx = 0; break; /* left */ case 'r': adjx = 1; break; /* right */ case 't': adjy = 1; break; /* top */ case 'b': adjy = 0; break; /* or bottom justify */ case 'o': outline = 1; break; /* outline the picture */ case 'w': whiteout = 1; break; /* white out the box */ case 's': scaleboth = 1; break; /* scale both dimensions */ case 'a': if ( sscanf(&flags[i+1], "%lf", &rot) != 1 ) rot += 90; } /* End switch */ fprintf(tf, "save mark\n"); fprintf(tf, "[ /NamespacePush pdfmark\n"); ps_include(name, fp_in, tf, page, whiteout, outline, scaleboth, frame[3]+frame[1]/2, -vpos-frame[2]-frame[0]/2, frame[1], frame[0], adjx, adjy, -rot); fprintf(tf, "[ /NamespacePop pdfmark\n"); fprintf(tf, "cleartomark restore\n"); xymove(hpos, vpos); t_sf(1); fclose(fp_in); } /* End of picture */