46 #define TRMFLT( a ) ( ( fabs( a ) < 5.0e-4 ) ? 0.0 : ( a ) )
51 "ps:PostScript File (monochrome):0:ps:29:psm\n"
52 "psc:PostScript File (color):0:ps:30:psc\n";
60 static char *ps_getdate(
void );
64 static void esc_purge(
unsigned char *,
unsigned char * );
66 #define OUTBUF_LEN 128
67 static char outbuf[OUTBUF_LEN];
70 static int hrshsym = 1;
72 static DrvOpt ps_options[] = { {
"text",
DRV_INT, &text,
"Use Postscript text (text=0|1)" },
73 {
"color",
DRV_INT, &color,
"Use color (color=0|1)" },
74 {
"hrshsym",
DRV_INT, &hrshsym,
"Use Hershey symbol set (hrshsym=0|1)" },
75 { NULL,
DRV_INT, NULL, NULL } };
80 const int number_of_entries );
91 const char *menustr,
const char *devnam,
94 #ifndef ENABLE_DYNDRIVERS
115 ps_dispatch_init_helper( pdt,
116 "PostScript File (monochrome)",
"ps",
123 ps_dispatch_init_helper( pdt,
124 "PostScript File (color)",
"psc",
174 if ( pls->
xdpi <= 0 )
176 if ( pls->
ydpi <= 0 )
202 if ( pls->
dev != NULL )
203 free( (
void *) pls->
dev );
205 pls->
dev = calloc( 1, (
size_t)
sizeof (
PSDev ) );
206 if ( pls->
dev == NULL )
207 plexit(
"ps_init: Out of memory." );
248 fprintf(
OF,
"%%!PS-Adobe-2.0 EPSF-2.0\n" );
249 fprintf(
OF,
"%%%%BoundingBox: \n" );
250 fprintf(
OF,
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" );
252 fprintf(
OF,
"%%%%Title: PLplot Graph\n" );
254 fprintf(
OF,
"%%%%CreationDate: %s\n", ps_getdate() );
255 fprintf(
OF,
"%%%%Pages: (atend)\n" );
256 fprintf(
OF,
"%%%%EndComments\n\n" );
261 fprintf(
OF,
"/PSSave save def\n" );
265 fprintf(
OF,
"/PSDict 200 dict def\n" );
266 fprintf(
OF,
"PSDict begin\n" );
268 fprintf(
OF,
"/@restore /restore load def\n" );
269 fprintf(
OF,
"/restore\n" );
270 fprintf(
OF,
" {vmstatus pop\n" );
271 fprintf(
OF,
" dup @VMused lt {pop @VMused} if\n" );
272 fprintf(
OF,
" exch pop exch @restore /@VMused exch def\n" );
273 fprintf(
OF,
" } def\n" );
274 fprintf(
OF,
"/@pri\n" );
275 fprintf(
OF,
" {\n" );
276 fprintf(
OF,
" ( ) print\n" );
277 fprintf(
OF,
" ( ) cvs print\n" );
278 fprintf(
OF,
" } def\n" );
282 fprintf(
OF,
"/@copies\n" );
283 fprintf(
OF,
" {\n" );
284 fprintf(
OF,
" /#copies exch def\n" );
285 fprintf(
OF,
" } def\n" );
289 fprintf(
OF,
"/@start\n" );
290 fprintf(
OF,
" {\n" );
291 fprintf(
OF,
" vmstatus pop /@VMused exch def pop\n" );
292 fprintf(
OF,
" } def\n" );
296 fprintf(
OF,
"/@end\n" );
297 fprintf(
OF,
" {flush\n" );
298 fprintf(
OF,
" end\n" );
299 fprintf(
OF,
" PSSave restore\n" );
300 fprintf(
OF,
" } def\n" );
305 fprintf(
OF,
"/bop\n" );
306 fprintf(
OF,
" {\n" );
307 fprintf(
OF,
" /SaveImage save def\n" );
308 fprintf(
OF,
" } def\n" );
312 fprintf(
OF,
"/eop\n" );
313 fprintf(
OF,
" {\n" );
314 fprintf(
OF,
" showpage\n" );
315 fprintf(
OF,
" SaveImage restore\n" );
316 fprintf(
OF,
" } def\n" );
320 fprintf(
OF,
"/@line\n" );
321 fprintf(
OF,
" {0 setlinecap\n" );
322 fprintf(
OF,
" 0 setlinejoin\n" );
323 fprintf(
OF,
" 1 setmiterlimit\n" );
324 fprintf(
OF,
" } def\n" );
328 fprintf(
OF,
"/@hsize {/hs exch def} def\n" );
329 fprintf(
OF,
"/@vsize {/vs exch def} def\n" );
333 fprintf(
OF,
"/@hoffset {/ho exch def} def\n" );
334 fprintf(
OF,
"/@voffset {/vo exch def} def\n" );
338 fprintf(
OF,
"/lw %d def\n", (
int) (
344 fprintf(
OF,
"/@SetPlot\n" );
345 fprintf(
OF,
" {\n" );
346 fprintf(
OF,
" ho vo translate\n" );
347 fprintf(
OF,
" XScale YScale scale\n" );
348 fprintf(
OF,
" lw setlinewidth\n" );
349 fprintf(
OF,
" } def\n" );
353 fprintf(
OF,
"/XScale\n" );
354 fprintf(
OF,
" {hs %d div} def\n",
YPSSIZE );
355 fprintf(
OF,
"/YScale\n" );
356 fprintf(
OF,
" {vs %d div} def\n",
XPSSIZE );
360 fprintf(
OF,
"/M {moveto} def\n" );
361 fprintf(
OF,
"/D {lineto} def\n" );
362 fprintf(
OF,
"/A {0.5 0 360 arc} def\n" );
363 fprintf(
OF,
"/S {stroke} def\n" );
364 fprintf(
OF,
"/Z {stroke newpath} def\n" );
369 fprintf(
OF,
"/F {closepath gsave eofill grestore stroke} def " );
371 fprintf(
OF,
"/F {closepath gsave fill grestore stroke} def " );
372 fprintf(
OF,
"/N {newpath} def" );
373 fprintf(
OF,
"/C {setrgbcolor} def\n" );
374 fprintf(
OF,
"/G {setgray} def\n" );
375 fprintf(
OF,
"/W {setlinewidth} def\n" );
376 fprintf(
OF,
"/SF {selectfont} def\n" );
377 fprintf(
OF,
"/R {rotate} def\n" );
378 fprintf(
OF,
"/SW {stringwidth 2 index mul exch 2 index mul exch rmoveto pop} bind def\n" );
379 fprintf(
OF,
"/B {Z %d %d M %d %d D %d %d D %d %d D %d %d closepath} def\n",
381 fprintf(
OF,
"/CL {newpath M D D D closepath clip} def\n" );
385 fprintf(
OF,
"end\n\n" );
389 fprintf(
OF,
"PSDict begin\n" );
390 fprintf(
OF,
"@start\n" );
391 fprintf(
OF,
"%d @copies\n",
COPIES );
392 fprintf(
OF,
"@line\n" );
393 fprintf(
OF,
"%d @hsize\n",
YSIZE );
394 fprintf(
OF,
"%d @vsize\n",
XSIZE );
398 fprintf(
OF,
"@SetPlot\n\n" );
411 PLINT x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
428 snprintf( outbuf, OUTBUF_LEN,
"%d %d D", x2, y2 );
434 fprintf(
OF,
" Z\n" );
437 if ( x1 == x2 && y1 == y2 )
438 snprintf( outbuf, OUTBUF_LEN,
"%d %d A", x1, y1 );
440 snprintf( outbuf, OUTBUF_LEN,
"%d %d M %d %d D", x1, y1, x2, y2 );
453 fprintf(
OF,
"%s", outbuf );
470 for ( i = 0; i < npts - 1; i++ )
471 plD_line_ps( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] );
483 fprintf(
OF,
" S\neop\n" );
507 fprintf(
OF,
"%%%%Page: %d %d\n", (
int) pls->
page, 1 );
509 fprintf(
OF,
"%%%%Page: %d %d\n", (
int) pls->
page, (
int) pls->
page );
511 fprintf(
OF,
"bop\n" );
515 if ( pls->
cmap0[0].
r != 0xFF ||
516 pls->
cmap0[0].
g != 0xFF ||
523 fprintf(
OF,
"B %.4f %.4f %.4f C F\n", r, g, b );
546 fprintf(
OF,
"\n%%%%Trailer\n" );
564 fprintf(
OF,
"%%%%Pages: %d\n", (
int) 1 );
566 fprintf(
OF,
"%%%%Pages: %d\n", (
int) pls->
page );
568 fprintf(
OF,
"@end\n" );
569 fprintf(
OF,
"%%%%EOF\n" );
575 fprintf(
OF,
"%%!PS-Adobe-2.0 EPSF-2.0\n" );
576 fprintf(
OF,
"%%%%BoundingBox: %d %d %d %d\n",
599 fprintf(
OF,
" S\n%d W", width );
608 fprintf(
OF,
" S\n%.4f G", ( pls->
icol0 ? 0.0 : 1.0 ) );
611 fprintf(
OF,
" %d %d M \n", (
int) dev->
xold, (
int) dev->
yold );
622 fprintf(
OF,
" S\n%.4f %.4f %.4f C", r, g, b );
627 fprintf(
OF,
" S\n%.4f G", 1.0 - r );
631 fprintf(
OF,
" %d %d M \n", (
int) dev->
xold, (
int) dev->
yold );
667 PLINT n, ix = 0, iy = 0;
670 fprintf(
OF,
" Z\n" );
672 for ( n = 0; n < pls->
dev_npts; n++ )
674 x = pls->
dev_x[ix++];
675 y = pls->
dev_y[iy++];
685 snprintf( outbuf, OUTBUF_LEN,
"N %d %d M", x, y );
690 fprintf(
OF,
"%s", outbuf );
705 snprintf( outbuf, OUTBUF_LEN,
"%d %d D", x, y );
711 fprintf(
OF,
"%s", outbuf );
717 fprintf(
OF,
" F " );
733 t = time( (time_t *) 0 );
735 len = (int) strlen( p );
736 *( p + len - 1 ) =
'\0';
747 # define RISE_FACTOR 0.6
761 PLFLT theta, shear, stride;
763 PLFLT cs, sn, l1, l2;
769 #define PROC_STR_STRING_LENGTH 1000
770 unsigned char *strp, str[PROC_STR_STRING_LENGTH], *cur_strp,
771 cur_str[PROC_STR_STRING_LENGTH];
772 float font_factor = 1.4f;
773 PLINT clxmin, clxmax, clymin, clymax;
774 PLINT clipx[4], clipy[4];
776 PLFLT scale = 1., up = 0.;
784 const char *fonts[PROC_STR_STRING_LENGTH];
787 PLFLT old_sscale, sscale, old_soffset, soffset, ddup;
798 font = get_font( dev, fci );
808 if ( ( f < PROC_STR_STRING_LENGTH ) && ( s + 3 < PROC_STR_STRING_LENGTH ) )
810 fci_save = cur_text[j];
811 fonts[f++] = get_font( dev, fci_save );
812 cur_str[s++] = (
unsigned char) esc;
817 else if ( s + 4 < PROC_STR_STRING_LENGTH )
824 PLINT ifamily, istyle, iweight;
825 plgfont( &ifamily, &istyle, &iweight );
826 if ( 0 <= cur_text[j] && cur_text[j] < 256 )
827 cur_str[s++] = cur_text[j];
832 font = get_font( dev, 0 );
834 font = get_font( dev, fci );
836 cur_str[s] = plunicode2type1( cur_text[j], dev->
lookup, dev->
nlookup );
837 if ( cur_text[j] !=
' ' && cur_str[s] ==
' ' )
845 fonts[f++] = get_font( dev, 0 );
846 cur_str[s++] = (
unsigned char) esc;
849 cur_str[s++] = plunicode2type1( cur_text[j], dev->
lookup, dev->
nlookup );
856 fonts[f++] = get_font( dev, fci_save );
857 cur_str[s++] = (
unsigned char) esc;
860 cur_str[s++] = plunicode2type1( cur_text[j], dev->
lookup, dev->
nlookup );
869 pldebug(
"proc_str",
"unicode = 0x%x, type 1 code = %d\n",
870 cur_text[j], cur_str[s - 1] );
881 ft_ht = pls->
chrht * 72.0 / 25.4;
888 tt[0] = t[0] * cs + t[2] * sn;
889 tt[1] = t[1] * cs + t[3] * sn;
890 tt[2] = -t[0] * sn + t[2] * cs;
891 tt[3] = -t[1] * sn + t[3] * cs;
905 if ( args->
base == 2 )
907 else if ( args->
base == 1 )
910 offset = -
ENLARGE * ft_ht / 2.;
914 args->
y += (
PLINT) ( offset * cos( theta ) );
915 args->
x -= (
PLINT) ( offset * sin( theta ) );
919 &( args->
x ), &( args->
y ) );
934 difilt( clipx, clipy, 4, &clxmin, &clxmax, &clymin, &clymax );
936 &clipx[0], &clipy[0] );
938 &clipx[1], &clipy[1] );
940 &clipx[2], &clipy[2] );
942 &clipx[3], &clipy[3] );
943 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] );
946 fprintf(
OF,
" %d %d M\n", args->
x, args->
y );
949 fprintf(
OF,
"gsave %.3f R\n", TRMFLT( theta * 180. /
PI ) );
956 esc_purge( str, cur_str );
958 fprintf(
OF,
"/%s %.3f SF\n", font, TRMFLT( font_factor *
ENLARGE * ft_ht ) );
963 fprintf(
OF,
"%.3f (", TRMFLT( -args->
just ) );
964 while ( str[i] !=
'\0' )
966 if ( str[i] ==
'(' || str[i] ==
')' || str[i] ==
'\\' )
967 fprintf(
OF,
"\\%c", str[i] );
969 fprintf(
OF,
"%c", str[i] );
972 fprintf(
OF,
") SW\n" );
983 if ( *cur_strp == esc )
987 if ( *cur_strp == esc )
989 *strp++ = *cur_strp++;
991 else if ( *cur_strp ==
'f' )
994 if ( *cur_strp++ !=
'f' )
998 plabort(
"proc_str, internal PLplot logic error;"
999 "wrong escf escape sequence" );
1003 pldebug(
"proc_str",
"string-specified fci = 0x%x, font name = %s\n", fci, font );
1007 switch ( *cur_strp++ )
1012 &old_sscale, &sscale, &old_soffset, &soffset );
1018 ddup = -0.5 * ( 1.0 - sscale );
1025 &old_sscale, &sscale, &old_soffset, &soffset );
1031 ddup = 0.5 * ( 1.0 - sscale );
1041 plwarn(
"'+', '-', and 'b/B' text escape sequences not processed." );
1049 while ( *cur_strp && *cur_strp != esc )
1051 if ( *cur_strp ==
'(' || *cur_strp ==
')' || *cur_strp ==
'\\' )
1053 *strp++ = *cur_strp++;
1057 if ( fabs( up ) < 0.001 )
1061 fprintf(
OF,
"/%s [%.3f %.3f %.3f %.3f 0 0] SF\n",
1063 TRMFLT( tt[0] * font_factor *
ENLARGE * ft_ht * scale ),
1064 TRMFLT( tt[2] * font_factor *
ENLARGE * ft_ht * scale ),
1065 TRMFLT( tt[1] * font_factor *
ENLARGE * ft_ht * scale ),
1066 TRMFLT( tt[3] * font_factor *
ENLARGE * ft_ht * scale ) );
1071 fprintf(
OF,
"gsave %.3f %.3f rmoveto\n", TRMFLT( up * tt[1] ), TRMFLT( up * tt[3] ) );
1074 fprintf(
OF,
"(%s) show\n", str );
1078 fprintf(
OF,
"grestore (%s) stringwidth rmoveto\n", str );
1079 }
while ( *cur_strp );
1081 fprintf(
OF,
"grestore\n" );
1082 fprintf(
OF,
"grestore\n" );
1095 l1 = -i * args->
just;
1096 l2 = i * ( 1. - args->
just );
1102 dev->
llx = (int) (
MIN( dev->
llx, args->
x + (
MIN( l1 * cs, l2 * cs ) - 1.5 ) * font_factor * ft_ht *
ENLARGE ) );
1103 dev->
lly = (int) (
MIN( dev->
lly, args->
y + (
MIN( l1 * sn, l2 * sn ) - 1.5 ) * font_factor * ft_ht *
ENLARGE ) );
1104 dev->
urx = (int) (
MAX( dev->
urx, args->
x + (
MAX( l1 * cs, l2 * cs ) + 1.5 ) * font_factor * ft_ht * ENLARGE ) );
1105 dev->
ury = (int) (
MAX( dev->
ury, args->
y + (
MAX( l1 * sn, l2 * sn ) + 1.5 ) * font_factor * ft_ht * ENLARGE ) );
1110 esc_purge(
unsigned char *dstr,
unsigned char *sstr )
1158 static unsigned char
1163 int jlo = -1, jmid, jhi = nlookup;
1164 while ( jhi - jlo > 1 )
1170 jmid = ( jlo + jhi ) / 2;
1171 if ( index > lookup[jmid].Unicode )
1173 else if ( index < lookup[jmid].Unicode )
1179 return ( lookup[jmid].Type1 );
1216 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 plexit(PLCHAR_VECTOR errormsg)
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)
void plD_esc_ps(PLStream *, PLINT, void *)
void plabort(PLCHAR_VECTOR errormsg)
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 *)
void(* plD_bop_fp)(struct PLStream_struct *)
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
static PLStream * pls[PL_NSTREAMS]
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 plD_eop_ps(PLStream *)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_psm(PLDispatchTable *pdt)
void plRotPhy(PLINT orient, PLINT xmin, PLINT ymin, PLINT xmax, PLINT ymax, PLINT *px, PLINT *py)
PLCHAR_VECTOR plP_FCI2FontName(PLUNICODE fci, const FCI_to_FontName_Table lookup[], const int nlookup)
void plwarn(PLCHAR_VECTOR errormsg)
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 *)