1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/* XNECVIEW - a program for visualizing NEC2 structure and gain files
*
* Copyright (C) 1998-1999, P.T. de Boer -- pa3fwm@amsat.org
*
* Distributed on the conditions of the GPL: see the files README and
* COPYING, which accompany this source file.
*
* This module contains all low level postscript drawing routines.
*/
#include <stdio.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <time.h>
#include <string.h>
#include "xnecview.h"
FILE *psfile=NULL;
int needstroke;
int needmoveto;
void ps_DrawLine(double x1,double y1,double x2,double y2)
{
static double lastx=-1,lasty=-1;
if (x1!=lastx || y1!=lasty || needmoveto) {
if (needstroke) fprintf(psfile,"stroke\n");
fprintf(psfile,"%g %g m\n",x1,y1);
needmoveto=0;
}
fprintf(psfile,"%g %g l\n",x2,y2);
lastx=x2; lasty=y2;
needstroke=1;
}
void ps_SetLineAttributes(unsigned line_width,int line_style,int cap_style,int join_style)
{
if (needstroke) { fprintf(psfile,"stroke\n"); needstroke=0; }
if (line_width==0) line_width++; /* Zero width lines for X11 speed of drawing but in
postscript don't really want the thinnest lines
which are possible on the device! */
fprintf(psfile,"%u setlinewidth ",line_width);
switch (line_style) {
case LineSolid:
fprintf(psfile,"[] 0 setdash\n");
break;
case LineOnOffDash:
fprintf(psfile,"[5 5] 0 setdash\n");
break;
}
if (cap_style!=CapRound || join_style!=JoinRound || line_style==LineDoubleDash) {
puts("Error in ps_SetLineAttributes!");
}
needmoveto=1;
}
void ps_SetForeground(XColor *xc)
{
if (needstroke) { fprintf(psfile,"stroke\n"); needstroke=0; }
fprintf(psfile,"%g %g %g setrgbcolor\n",xc->red/65536.,xc->green/65536.,xc->blue/65536.);
needmoveto=1;
}
void ps_ClearWindow(void)
{
}
void ps_DrawStringLL(double a,double b,char *s)
{
fprintf(psfile,"gsave %g %g descent sub m (%s) 1 -1 scale show grestore\n",a,b,s);
}
void ps_DrawStringUL(double a,double b,char *s)
{
fprintf(psfile,"gsave %g %g ascent add m (%s) 1 -1 scale show grestore\n",a,b,s);
}
Outdev out_ps = {
ps_SetLineAttributes,
ps_DrawLine,
ps_SetForeground,
ps_ClearWindow,
ps_DrawStringLL,
ps_DrawStringUL,
} ;
#define PSsize 400
#define PSllx 50
#define PSlly 150
int write_postscript(char *filename)
{
Outdev *oldout;
time_t ti;
psfile=fopen(filename,"w");
if (!psfile) return 1;
oldout=out;
out=&out_ps;
time(&ti);
fprintf(psfile,"%%!PS-Adobe-2.0 EPSF-2.0\n"
"%%%%DocumentFonts: %s\n"
"%%%%Title: Xnecview output\n"
"%%%%Creator: Xnecview %s\n"
"%%%%CreationDate: %s"
"%%%%Pages: 1\n"
"%%%%BoundingBox: %g %g %g %g\n"
"%%%%EndComments\n",
PSFONT,
VERSION,
ctime(&ti),
(double)PSllx,(double)PSlly,(double)PSllx+PSsize,(double)PSlly+PSsize);
fprintf(psfile,"/xnecview 10 dict def\n xnecview begin \n"); /* use a private dictionary as recommended in EPSF-3.0 standard */
fprintf(psfile,"/l /lineto load def\n"); /* define abbreviations l and m for lineto and moveto */
fprintf(psfile,"/m /moveto load def\n");
fprintf(psfile,"end\n"); /* end use (definition) of local dictionary */
fprintf(psfile,"%%%%EndProlog\n");
fprintf(psfile,"%%%%Page: 1 1\n");
fprintf(psfile,"xnecview begin\n"); /* use local dictionary again */
fprintf(psfile,"%g %g translate %g %g scale\n", /* set scaling and translation such that our Xwindow coordinates can be used */
(double)PSllx,
(double)PSlly+PSsize,
(double)PSsize/winsize,
-(double)PSsize/winsize );
fprintf(psfile,"newpath 0 0 moveto 0 %g lineto %g %g lineto %g 0 lineto closepath clip newpath\n",
(double)winsize, (double)winsize, (double)winsize, (double)winsize );
fprintf(psfile,"1 setlinejoin 1 setlinecap\n");
fprintf(psfile,"/%s findfont %i scalefont setfont\n",PSFONT,fontheight); /* prepare the font */
fprintf(psfile,"gsave 0 0 moveto (10ALIZgjy) true charpath pathbbox grestore /ascent exch def pop /descent exch def pop\n"); /* estimate ascent and descent of font */
needstroke=0;
needmoveto=0;
draw_all(0);
fprintf(psfile,"save 0 setgray 10 %i moveto 1 -1 scale (Antenna: %s) show restore\n",
fontheight,inputfilename);
if (gainplot!=GPnone) {
fprintf(psfile,"save 0 setgray 10 %i moveto 1 -1 scale (Scale: %s%s%s) show restore\n",
2*fontheight,
GSnames[gainscale],
scaleplot ? ", " : "",
scaleplot ? GSnumbers[gainscale] : "");
}
if (needstroke) fprintf(psfile,"stroke\n");
fprintf(psfile,"end\n"); /* end use of local dictionary */
fprintf(psfile,"showpage\n");
out=oldout;
return ferror(psfile) | fclose(psfile);
}
|