48 #define TRMFLT( a ) ( ( fabs( a ) < 5.0e-4 ) ? 0.0 : ( a ) )
53 "ps:PostScript File (monochrome):0:ps:29:psm\n"
54 "psc:PostScript File (color):0:ps:30:psc\n";
62 static char *ps_getdate(
void );
66 static void esc_purge(
unsigned char *,
unsigned char * );
68 #define OUTBUF_LEN 128
69 static char outbuf[OUTBUF_LEN];
74 static DrvOpt ps_options[] = { {
"text",
DRV_INT, &
text,
"Use Postscript text (text=0|1)" },
75 {
"color",
DRV_INT, &color,
"Use color (color=0|1)" },
76 {
"hrshsym",
DRV_INT, &
hrshsym,
"Use Hershey symbol set (hrshsym=0|1)" },
77 { NULL,
DRV_INT, NULL, NULL } };
82 const int number_of_entries );
93 const char *menustr,
const char *devnam,
96 #ifndef ENABLE_DYNDRIVERS
117 ps_dispatch_init_helper( pdt,
118 "PostScript File (monochrome)",
"ps",
125 ps_dispatch_init_helper( pdt,
126 "PostScript File (color)",
"psc",
176 if ( pls->
xdpi <= 0 )
178 if ( pls->
ydpi <= 0 )
204 if ( pls->
dev != NULL )
205 free( (
void *) pls->
dev );
207 pls->
dev = calloc( 1, (
size_t)
sizeof (
PSDev ) );
208 if ( pls->
dev == NULL )
209 plexit(
"ps_init: Out of memory." );
250 fprintf(
OF,
"%%!PS-Adobe-2.0 EPSF-2.0\n" );
251 fprintf(
OF,
"%%%%BoundingBox: \n" );
252 fprintf(
OF,
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" );
254 fprintf(
OF,
"%%%%Title: PLplot Graph\n" );
255 fprintf(
OF,
"%%%%Creator: PLplot Version %s\n",
VERSION );
256 fprintf(
OF,
"%%%%CreationDate: %s\n", ps_getdate() );
257 fprintf(
OF,
"%%%%Pages: (atend)\n" );
258 fprintf(
OF,
"%%%%EndComments\n\n" );
263 fprintf(
OF,
"/PSSave save def\n" );
267 fprintf(
OF,
"/PSDict 200 dict def\n" );
268 fprintf(
OF,
"PSDict begin\n" );
270 fprintf(
OF,
"/@restore /restore load def\n" );
271 fprintf(
OF,
"/restore\n" );
272 fprintf(
OF,
" {vmstatus pop\n" );
273 fprintf(
OF,
" dup @VMused lt {pop @VMused} if\n" );
274 fprintf(
OF,
" exch pop exch @restore /@VMused exch def\n" );
275 fprintf(
OF,
" } def\n" );
276 fprintf(
OF,
"/@pri\n" );
277 fprintf(
OF,
" {\n" );
278 fprintf(
OF,
" ( ) print\n" );
279 fprintf(
OF,
" ( ) cvs print\n" );
280 fprintf(
OF,
" } def\n" );
284 fprintf(
OF,
"/@copies\n" );
285 fprintf(
OF,
" {\n" );
286 fprintf(
OF,
" /#copies exch def\n" );
287 fprintf(
OF,
" } def\n" );
291 fprintf(
OF,
"/@start\n" );
292 fprintf(
OF,
" {\n" );
293 fprintf(
OF,
" vmstatus pop /@VMused exch def pop\n" );
294 fprintf(
OF,
" } def\n" );
298 fprintf(
OF,
"/@end\n" );
299 fprintf(
OF,
" {flush\n" );
300 fprintf(
OF,
" end\n" );
301 fprintf(
OF,
" PSSave restore\n" );
302 fprintf(
OF,
" } def\n" );
307 fprintf(
OF,
"/bop\n" );
308 fprintf(
OF,
" {\n" );
309 fprintf(
OF,
" /SaveImage save def\n" );
310 fprintf(
OF,
" } def\n" );
314 fprintf(
OF,
"/eop\n" );
315 fprintf(
OF,
" {\n" );
316 fprintf(
OF,
" showpage\n" );
317 fprintf(
OF,
" SaveImage restore\n" );
318 fprintf(
OF,
" } def\n" );
322 fprintf(
OF,
"/@line\n" );
323 fprintf(
OF,
" {0 setlinecap\n" );
324 fprintf(
OF,
" 0 setlinejoin\n" );
325 fprintf(
OF,
" 1 setmiterlimit\n" );
326 fprintf(
OF,
" } def\n" );
330 fprintf(
OF,
"/@hsize {/hs exch def} def\n" );
331 fprintf(
OF,
"/@vsize {/vs exch def} def\n" );
335 fprintf(
OF,
"/@hoffset {/ho exch def} def\n" );
336 fprintf(
OF,
"/@voffset {/vo exch def} def\n" );
340 fprintf(
OF,
"/lw %d def\n", (
int) (
346 fprintf(
OF,
"/@SetPlot\n" );
347 fprintf(
OF,
" {\n" );
348 fprintf(
OF,
" ho vo translate\n" );
349 fprintf(
OF,
" XScale YScale scale\n" );
350 fprintf(
OF,
" lw setlinewidth\n" );
351 fprintf(
OF,
" } def\n" );
355 fprintf(
OF,
"/XScale\n" );
356 fprintf(
OF,
" {hs %d div} def\n",
YPSSIZE );
357 fprintf(
OF,
"/YScale\n" );
358 fprintf(
OF,
" {vs %d div} def\n",
XPSSIZE );
362 fprintf(
OF,
"/M {moveto} def\n" );
363 fprintf(
OF,
"/D {lineto} def\n" );
364 fprintf(
OF,
"/A {0.5 0 360 arc} def\n" );
365 fprintf(
OF,
"/S {stroke} def\n" );
366 fprintf(
OF,
"/Z {stroke newpath} def\n" );
371 fprintf(
OF,
"/F {closepath gsave eofill grestore stroke} def " );
373 fprintf(
OF,
"/F {closepath gsave fill grestore stroke} def " );
374 fprintf(
OF,
"/N {newpath} def" );
375 fprintf(
OF,
"/C {setrgbcolor} def\n" );
376 fprintf(
OF,
"/G {setgray} def\n" );
377 fprintf(
OF,
"/W {setlinewidth} def\n" );
378 fprintf(
OF,
"/SF {selectfont} def\n" );
379 fprintf(
OF,
"/R {rotate} def\n" );
380 fprintf(
OF,
"/SW {stringwidth 2 index mul exch 2 index mul exch rmoveto pop} bind def\n" );
381 fprintf(
OF,
"/B {Z %d %d M %d %d D %d %d D %d %d D %d %d closepath} def\n",
383 fprintf(
OF,
"/CL {newpath M D D D closepath clip} def\n" );
387 fprintf(
OF,
"end\n\n" );
391 fprintf(
OF,
"PSDict begin\n" );
392 fprintf(
OF,
"@start\n" );
393 fprintf(
OF,
"%d @copies\n",
COPIES );
394 fprintf(
OF,
"@line\n" );
395 fprintf(
OF,
"%d @hsize\n",
YSIZE );
396 fprintf(
OF,
"%d @vsize\n",
XSIZE );
400 fprintf(
OF,
"@SetPlot\n\n" );
413 PLINT x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
430 snprintf( outbuf, OUTBUF_LEN,
"%d %d D", x2, y2 );
436 fprintf(
OF,
" Z\n" );
439 if ( x1 == x2 && y1 == y2 )
440 snprintf( outbuf, OUTBUF_LEN,
"%d %d A", x1, y1 );
442 snprintf( outbuf, OUTBUF_LEN,
"%d %d M %d %d D", x1, y1, x2, y2 );
455 fprintf(
OF,
"%s", outbuf );
472 for ( i = 0; i < npts - 1; i++ )
473 plD_line_ps( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] );
485 fprintf(
OF,
" S\neop\n" );
509 fprintf(
OF,
"%%%%Page: %d %d\n", (
int) pls->
page, 1 );
511 fprintf(
OF,
"%%%%Page: %d %d\n", (
int) pls->
page, (
int) pls->
page );
513 fprintf(
OF,
"bop\n" );
517 if ( pls->
cmap0[0].
r != 0xFF ||
518 pls->
cmap0[0].
g != 0xFF ||
525 fprintf(
OF,
"B %.4f %.4f %.4f C F\n", r, g, b );
548 fprintf(
OF,
"\n%%%%Trailer\n" );
566 fprintf(
OF,
"%%%%Pages: %d\n", (
int) 1 );
568 fprintf(
OF,
"%%%%Pages: %d\n", (
int) pls->
page );
570 fprintf(
OF,
"@end\n" );
571 fprintf(
OF,
"%%%%EOF\n" );
577 fprintf(
OF,
"%%!PS-Adobe-2.0 EPSF-2.0\n" );
578 fprintf(
OF,
"%%%%BoundingBox: %d %d %d %d\n",
601 fprintf(
OF,
" S\n%d W", width );
610 fprintf(
OF,
" S\n%.4f G", ( pls->
icol0 ? 0.0 : 1.0 ) );
621 fprintf(
OF,
" S\n%.4f %.4f %.4f C", r, g, b );
626 fprintf(
OF,
" S\n%.4f G", 1.0 - r );
635 fprintf(
OF,
" %d %d M \n", (
int) dev->
xold, (
int) dev->
yold );
670 PLINT n, ix = 0, iy = 0;
673 fprintf(
OF,
" Z\n" );
675 for ( n = 0; n < pls->
dev_npts; n++ )
677 x = pls->
dev_x[ix++];
688 snprintf( outbuf, OUTBUF_LEN,
"N %d %d M", x,
y );
693 fprintf(
OF,
"%s", outbuf );
708 snprintf( outbuf, OUTBUF_LEN,
"%d %d D", x,
y );
714 fprintf(
OF,
"%s", outbuf );
720 fprintf(
OF,
" F " );
736 t = time( (time_t *) 0 );
738 len = (int) strlen( p );
739 *( p + len - 1 ) =
'\0';
750 # define RISE_FACTOR 0.6
764 PLFLT theta, shear, stride;
766 PLFLT cs, sn, l1, l2;
772 #define PROC_STR_STRING_LENGTH 1000
773 unsigned char *strp, str[PROC_STR_STRING_LENGTH], *cur_strp,
774 cur_str[PROC_STR_STRING_LENGTH];
775 float font_factor = 1.4f;
776 PLINT clxmin, clxmax, clymin, clymax;
777 PLINT clipx[4], clipy[4];
779 PLFLT scale = 1., up = 0.;
787 const char *fonts[PROC_STR_STRING_LENGTH];
790 PLFLT old_sscale, sscale, old_soffset, soffset, ddup;
801 font = get_font( dev, fci );
811 if ( ( f < PROC_STR_STRING_LENGTH ) && ( s + 3 < PROC_STR_STRING_LENGTH ) )
813 fci_save = cur_text[j];
814 fonts[f++] = get_font( dev, fci_save );
815 cur_str[s++] = (
unsigned char) esc;
820 else if ( s + 4 < PROC_STR_STRING_LENGTH )
827 PLINT ifamily, istyle, iweight;
828 plgfont( &ifamily, &istyle, &iweight );
829 if ( 0 <= cur_text[j] && cur_text[j] < 256 )
830 cur_str[s++] = cur_text[j];
835 font = get_font( dev, 0 );
837 font = get_font( dev, fci );
839 cur_str[s] = plunicode2type1( cur_text[j], dev->
lookup, dev->
nlookup );
840 if ( cur_text[j] !=
' ' && cur_str[s] ==
' ' )
848 fonts[f++] = get_font( dev, 0 );
849 cur_str[s++] = (
unsigned char) esc;
852 cur_str[s++] = plunicode2type1( cur_text[j], dev->
lookup, dev->
nlookup );
859 fonts[f++] = get_font( dev, fci_save );
860 cur_str[s++] = (
unsigned char) esc;
863 cur_str[s++] = plunicode2type1( cur_text[j], dev->
lookup, dev->
nlookup );
872 pldebug(
"proc_str",
"unicode = 0x%x, type 1 code = %d\n",
873 cur_text[j], cur_str[s - 1] );
884 ft_ht = pls->
chrht * 72.0 / 25.4;
891 tt[0] = t[0] * cs + t[2] * sn;
892 tt[1] = t[1] * cs + t[3] * sn;
893 tt[2] = -t[0] * sn + t[2] * cs;
894 tt[3] = -t[1] * sn + t[3] * cs;
908 if ( args->
base == 2 )
910 else if ( args->
base == 1 )
913 offset = -
ENLARGE * ft_ht / 2.;
917 args->
y += (
PLINT) ( offset * cos( theta ) );
918 args->
x -= (
PLINT) ( offset * sin( theta ) );
922 &( args->
x ), &( args->
y ) );
937 difilt( clipx, clipy, 4, &clxmin, &clxmax, &clymin, &clymax );
939 &clipx[0], &clipy[0] );
941 &clipx[1], &clipy[1] );
943 &clipx[2], &clipy[2] );
945 &clipx[3], &clipy[3] );
946 fprintf(
OF,
" gsave %d %d %d %d %d %d %d %d CL\n", clipx[0], clipy[0], clipx[1], clipy[1], clipx[2], clipy[2], clipx[3], clipy[3] );
949 fprintf(
OF,
" %d %d M\n", args->
x, args->
y );
952 fprintf(
OF,
"gsave %.3f R\n", TRMFLT( theta * 180. /
PI ) );
959 esc_purge( str, cur_str );
961 fprintf(
OF,
"/%s %.3f SF\n", font, TRMFLT( font_factor *
ENLARGE * ft_ht ) );
966 fprintf(
OF,
"%.3f (", TRMFLT( -args->
just ) );
967 while ( str[i] !=
'\0' )
969 if ( str[i] ==
'(' || str[i] ==
')' || str[i] ==
'\\' )
970 fprintf(
OF,
"\\%c", str[i] );
972 fprintf(
OF,
"%c", str[i] );
975 fprintf(
OF,
") SW\n" );
986 if ( *cur_strp == esc )
990 if ( *cur_strp == esc )
992 *strp++ = *cur_strp++;
994 else if ( *cur_strp ==
'f' )
997 if ( *cur_strp++ !=
'f' )
1001 plabort(
"proc_str, internal PLplot logic error;"
1002 "wrong escf escape sequence" );
1006 pldebug(
"proc_str",
"string-specified fci = 0x%x, font name = %s\n", fci, font );
1010 switch ( *cur_strp++ )
1015 &old_sscale, &sscale, &old_soffset, &soffset );
1021 ddup = -0.5 * ( 1.0 - sscale );
1028 &old_sscale, &sscale, &old_soffset, &soffset );
1034 ddup = 0.5 * ( 1.0 - sscale );
1044 plwarn(
"'+', '-', and 'b/B' text escape sequences not processed." );
1052 while ( *cur_strp && *cur_strp != esc )
1054 if ( *cur_strp ==
'(' || *cur_strp ==
')' || *cur_strp ==
'\\' )
1056 *strp++ = *cur_strp++;
1060 if ( fabs( up ) < 0.001 )
1064 fprintf(
OF,
"/%s [%.3f %.3f %.3f %.3f 0 0] SF\n",
1066 TRMFLT( tt[0] * font_factor *
ENLARGE * ft_ht * scale ),
1067 TRMFLT( tt[2] * font_factor *
ENLARGE * ft_ht * scale ),
1068 TRMFLT( tt[1] * font_factor *
ENLARGE * ft_ht * scale ),
1069 TRMFLT( tt[3] * font_factor *
ENLARGE * ft_ht * scale ) );
1074 fprintf(
OF,
"gsave %.3f %.3f rmoveto\n", TRMFLT( up * tt[1] ), TRMFLT( up * tt[3] ) );
1077 fprintf(
OF,
"(%s) show\n", str );
1081 fprintf(
OF,
"grestore (%s) stringwidth rmoveto\n", str );
1082 }
while ( *cur_strp );
1084 fprintf(
OF,
"grestore\n" );
1085 fprintf(
OF,
"grestore\n" );
1098 l1 = -i * args->
just;
1099 l2 = i * ( 1. - args->
just );
1105 dev->
llx = (int) (
MIN( dev->
llx, args->
x + (
MIN( l1 * cs, l2 * cs ) - 1.5 ) * font_factor * ft_ht *
ENLARGE ) );
1106 dev->
lly = (int) (
MIN( dev->
lly, args->
y + (
MIN( l1 * sn, l2 * sn ) - 1.5 ) * font_factor * ft_ht *
ENLARGE ) );
1107 dev->
urx = (int) (
MAX( dev->
urx, args->
x + (
MAX( l1 * cs, l2 * cs ) + 1.5 ) * font_factor * ft_ht * ENLARGE ) );
1108 dev->
ury = (int) (
MAX( dev->
ury, args->
y + (
MAX( l1 * sn, l2 * sn ) + 1.5 ) * font_factor * ft_ht * ENLARGE ) );
1113 esc_purge(
unsigned char *dstr,
unsigned char *sstr )
1161 static unsigned char
1166 int jlo = -1, jmid, jhi = nlookup;
1167 while ( jhi - jlo > 1 )
1173 jmid = ( jlo + jhi ) / 2;
1174 if ( index > lookup[jmid].Unicode )
1176 else if ( index < lookup[jmid].Unicode )
1182 return ( lookup[jmid].Type1 );
1219 pldebug(
"set_font",
"fci = 0x%x, font name = %s\n", fci, font );
int plParseDrvOpts(DrvOpt *acc_opt)
void plP_script_scale(PLBOOL ifupper, PLINT *level, PLFLT *old_scale, PLFLT *scale, PLFLT *old_offset, PLFLT *offset)
void(* plD_line_fp)(struct PLStream_struct *, short, short, short, short)
void(* plD_eop_fp)(struct PLStream_struct *)
void(* plD_state_fp)(struct PLStream_struct *, PLINT)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_psc(PLDispatchTable *pdt)
void plD_polyline_ps(PLStream *, short *, short *, PLINT)
void plD_init_psc(PLStream *)
void(* plD_tidy_fp)(struct PLStream_struct *)
static const Unicode_to_Type1_table unicode_to_symbol_lookup_table[194]
const Unicode_to_Type1_table * lookup
void plOpenFile(PLStream *pls)
void plCloseFile(PLStream *pls)
void plD_init_psm(PLStream *)
static const int number_of_entries_in_unicode_to_standard_table
void plGetFam(PLStream *pls)
static void fill_polygon(PLStream *pls)
void plD_esc_ps(PLStream *, PLINT, void *)
void PLFLT PLINT PLINT PLFLT x
void plFamInit(PLStream *pls)
void plD_tidy_ps(PLStream *)
void(* plD_polyline_fp)(struct PLStream_struct *, short *, short *, PLINT)
void plD_line_ps(PLStream *, short, short, short, short)
static const int number_of_entries_in_unicode_to_symbol_table
void plD_state_ps(PLStream *, PLINT)
void(* plD_esc_fp)(struct PLStream_struct *, PLINT, void *)
const char * plP_FCI2FontName(PLUNICODE fci, const FCI_to_FontName_Table lookup[], const int nlookup)
void(* plD_bop_fp)(struct PLStream_struct *)
void PLFLT PLINT PLINT PLFLT PLFLT y
void difilt(PLINT *xsc, PLINT *ysc, PLINT npts, PLINT *clpxmi, PLINT *clpxma, PLINT *clpymi, PLINT *clpyma)
static const FCI_to_FontName_Table Type1Lookup[N_Type1Lookup]
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
#define PLDLLIMPEXP_DRIVER
void plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
void plD_bop_ps(PLStream *)
void plRotationShear(PLFLT *xFormMatrix, PLFLT *rotation, PLFLT *shear, PLFLT *stride)
static void proc_str(PLStream *, EscText *)
unsigned short unicode_array_len
void plabort(const char *errormsg)
void plD_eop_ps(PLStream *)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_psm(PLDispatchTable *pdt)
void plwarn(const char *errormsg)
void plRotPhy(PLINT orient, PLINT xmin, PLINT ymin, PLINT xmax, PLINT ymax, PLINT *px, PLINT *py)
static const Unicode_to_Type1_table unicode_to_standard_lookup_table[154]
plD_polyline_fp pl_polyline
PLUNICODE * unicode_array
void(* plD_init_fp)(struct PLStream_struct *)
void plexit(const char *errormsg)