/*
kate: mode C++; syntax C++; indent-mode none;
*/
#usage "Encapsulated PostScript output\n"
"
This program creates a Encapsulated Postscript file from "
"a board or a sheet. Program is based on psdraw4.ulp "
"and adds drawing polygons and other shapes of pads. Many "
"postscript operators were redefined to make file smaller.
\n"
"Mirror and/or upside-down operation of image can be done by "
"uncommenting lines marked by %MIRROR and/or %UPSIDE DOWN "
"resp. at the end.
\n"
"Run RATSNEST to calculate polygons before exporting!
\n"
"Tested on EAGLE v4.03.
\n"
"Author: Filip Kinovic, kinovicf@centrum.cz, 9.5.2004, v1.0"
int i, LayerActive[];
int ifirst, iplunge;
real rcurx, rcury, rlastx, rlasty;
string fileName, ttext;
string excFileName;
void PSopen(string title, int L, int B, int R, int T, real scale)
{
int xoffset = 30, yoffset = 30, bboffset = 3;
printf("%%!PS-Adobe-3.0 EPSF-3.0\n"
"%%%%Creator: EAGLE v%d.%02d\n"
"%%%%Title: %s\n"
"%%%%CreationDate: %s\n"
"%%%%Pages: 0\n"
"%%%%LanguageLevel: 2\n"
"%%%%BoundingBox: %d %d %d %d\n"
"%%%%EndComments\n"
"\n",
EAGLE_VERSION, EAGLE_RELEASE,
title,
t2string(time()),
xoffset - bboffset,
yoffset - bboffset,
int((R - L) * u2inch(72) * scale) + xoffset + bboffset,
int((T - B) * u2inch(72) * scale) + yoffset + bboffset);
printf("%%%%BeginProlog\n"
"%%redefination of operators\n"
"/d /def load def\n"
"/, /load load d\n"
"/bd {bind d} bind d\n"
"/ld {, d} bd\n"
"/~ /exch ld\n"
"/! /pop ld\n"
"/@ /dup ld\n"
"/V /div ld\n"
"/: /gsave ld\n"
"/; /grestore ld\n"
"/` /begin ld\n"
"/E /end ld\n"
"/+ /translate ld\n"
"/+S /scale ld\n"
"/R /rotate ld\n"
"/N /newpath ld\n"
"/C /closepath ld\n"
"/K /stroke ld\n"
"/L /fill ld\n"
"/O /eofill ld\n"
"/S /show ld\n"
"/LH /showpage ld\n"
"/M /moveto ld\n"
"/I /lineto ld\n"
"/-M /rlineto ld\n"
"/-c /curveto ld\n"
"/Ac /arc ld\n"
"/Lw /setlinewidth ld\n"
"/Lc /setlinecap ld\n"
"/Lj /setlinejoin ld\n"
"/sd /setdash ld\n"
"/sg /setgray ld\n"
"/sr /setrgbcolor ld\n"
"/Ji /setfont ld\n"
"/FS {findfont ~ scalefont} bd\n"
"%%%%EndProlog\n"
"\n"
"%%%%Page: 1 1\n");
printf(":\n"
"%d %d +\n"
"1 Lc 1 Lj\n"
"%%%d %d + %%MIRROR\n"
"%%%d %d + %%UPSIDE DOWN\n"
"%10.8f %10.8f +S %%normal\n"
"%%%3.1f %3.1f +S %%MIRROR\n"
"%%%3.1f %3.1f +S %%UPSIDE DOWN\n"
"%d %d +\n\n",
xoffset, yoffset,
int((R - L) * u2inch(72) * scale), 0,
0, int((T - B) * u2inch(72) * scale),
scale * u2inch(72), scale * u2inch(72),
-1.0, 1.0,
1.0, -1.0,
-L, -B);
}
void PSclose(void)
{
printf("LH\n");
printf(";\n");
printf("\n%%%%EOF");
}
void DrawArc(UL_ARC A)
{
if (LayerActive[A.layer])
{
printf("N %d %d %d %f %f Ac %d Lw K\n",
A.xc, A.yc, A.radius, A.angle1, A.angle2, A.width);
output(excFileName, "at")
{
int isegments;
real radius, anginc, ang, xc, yc, xn, yn;
isegments = (A.angle2 - A.angle1)/20.0;
if( isegments < 2 ) { isegments = 2; }
anginc = (A.angle2 - A.angle1)/isegments;
radius = u2mm(A.radius);
xc = u2mm(A.xc);
yc = u2mm(A.yc);
printf(";ARC x1,y1:%.3f %.3f\n",u2mm(A.x1),u2mm(A.y1));
printf(";ARC x2,y2:%.3f %.3f\n",u2mm(A.x2),u2mm(A.y2));
printf(";ARC xc,yc:%.3f %.3f\n",u2mm(A.xc),u2mm(A.yc));
printf(";ARC a1,a2:%.3f %.3f\n",A.angle1,A.angle2);
printf(";ARC radius:%.3f\n",u2mm(A.radius));
printf("G00X%.3fY%.3f\n",u2mm(A.x1),u2mm(A.y1));
printf("M15\n");
for(i=0,ang=A.angle1; i