32 #if defined ( PLD_psttf )
48 #define TRMFLT( a ) ( ( fabs( a ) < 5.0e-4 ) ? 0.0 : ( a ) )
56 "psttf:PostScript File (monochrome):0:psttf:55:psttfm\n"
57 "psttfc:PostScript File (color):0:psttf:56:psttfc\n";
65 static char *ps_getdate(
void );
71 #define OUTBUF_LEN 128
72 static char outbuf[OUTBUF_LEN];
75 static int hrshsym = 0;
79 #define N_Pango_Lookup 5
81 const char * DefaultFamilyLookup[N_Pango_Lookup] = {
89 const char * EnvFamilyLookup[N_Pango_Lookup] = {
90 "PLPLOT_FREETYPE_SANS_FAMILY",
91 "PLPLOT_FREETYPE_SERIF_FAMILY",
92 "PLPLOT_FREETYPE_MONO_FAMILY",
93 "PLPLOT_FREETYPE_SCRIPT_FAMILY",
94 "PLPLOT_FREETYPE_SYMBOL_FAMILY"
97 #define FAMILY_LOOKUP_LEN 1024
100 const FontWeight WeightLookup[2] = {
105 const FontStyle StyleLookup[3] = {
111 static DrvOpt ps_options[] = { {
"text",
DRV_INT, &text,
"Use Postscript text (text=0|1)" },
112 {
"color",
DRV_INT, &color,
"Use color (color=0|1)" },
113 {
"hrshsym",
DRV_INT, &hrshsym,
"Use Hershey symbol set (hrshsym=0|1)" },
114 { NULL,
DRV_INT, NULL, NULL } };
122 const char *menustr,
const char *devnam,
125 #ifndef ENABLE_DYNDRIVERS
146 psttf_dispatch_init_helper( pdt,
147 "PostScript File (monochrome)",
"psttf",
154 psttf_dispatch_init_helper( pdt,
155 "PostScript File (color)",
"psttfc",
190 #define MAX_NUM_TRIES 10
197 PostscriptDocument *doc;
206 if ( pls->
xdpi <= 0 )
208 if ( pls->
ydpi <= 0 )
234 if ( pls->
psdoc != NULL )
235 delete (PostscriptDocument *) pls->
psdoc;
237 pls->
psdoc =
new PostscriptDocument();
238 doc = (PostscriptDocument *) ( pls->
psdoc );
239 doc->osBody() << fixed;
240 doc->osBody().precision( 3 );
244 if ( pls->
dev != NULL )
245 free( (
void *) pls->
dev );
247 pls->
dev = calloc( 1, (
size_t)
sizeof (
PSDev ) );
248 if ( pls->
dev == NULL )
249 plexit(
"ps_init: Out of memory." );
290 for ( i = 0; i < N_Pango_Lookup; i++ )
292 if ( ( a = getenv( EnvFamilyLookup[i] ) ) != NULL )
315 PostscriptDocument *doc = (PostscriptDocument *) ( pls->
psdoc );
317 doc->osHeader() <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
319 doc->osHeader() <<
"%%Title: PLplot Graph\n";
320 doc->osHeader() <<
"%%Creator: PLplot Version " <<
PLPLOT_VERSION <<
"\n";
321 doc->osHeader() <<
"%%CreationDate: " << ps_getdate() <<
"\n";
322 doc->osHeader() <<
"%%Pages: (atend)\n";
323 doc->osHeader() <<
"%%EndComments\n\n";
328 doc->osHeader() <<
"/PSSave save def\n";
332 doc->osHeader() <<
"/PSDict 200 dict def\n";
333 doc->osHeader() <<
"PSDict begin\n";
335 doc->osHeader() <<
"/@restore /restore load def\n";
336 doc->osHeader() <<
"/restore\n";
337 doc->osHeader() <<
" {vmstatus pop\n";
338 doc->osHeader() <<
" dup @VMused lt {pop @VMused} if\n";
339 doc->osHeader() <<
" exch pop exch @restore /@VMused exch def\n";
340 doc->osHeader() <<
" } def\n";
341 doc->osHeader() <<
"/@pri\n";
342 doc->osHeader() <<
" {\n";
343 doc->osHeader() <<
" ( ) print\n";
344 doc->osHeader() <<
" ( ) cvs print\n";
345 doc->osHeader() <<
" } def\n";
349 doc->osHeader() <<
"/@copies\n";
350 doc->osHeader() <<
" {\n";
351 doc->osHeader() <<
" /#copies exch def\n";
352 doc->osHeader() <<
" } def\n";
356 doc->osHeader() <<
"/@start\n";
357 doc->osHeader() <<
" {\n";
358 doc->osHeader() <<
" vmstatus pop /@VMused exch def pop\n";
359 doc->osHeader() <<
" } def\n";
363 doc->osHeader() <<
"/@end\n";
364 doc->osHeader() <<
" {flush\n";
365 doc->osHeader() <<
" end\n";
366 doc->osHeader() <<
" PSSave restore\n";
367 doc->osHeader() <<
" } def\n";
372 doc->osHeader() <<
"/bop\n";
373 doc->osHeader() <<
" {\n";
374 doc->osHeader() <<
" /SaveImage save def\n";
375 doc->osHeader() <<
" } def\n";
379 doc->osHeader() <<
"/eop\n";
380 doc->osHeader() <<
" {\n";
381 doc->osHeader() <<
" showpage\n";
382 doc->osHeader() <<
" SaveImage restore\n";
383 doc->osHeader() <<
" } def\n";
387 doc->osHeader() <<
"/@line\n";
388 doc->osHeader() <<
" {0 setlinecap\n";
389 doc->osHeader() <<
" 0 setlinejoin\n";
390 doc->osHeader() <<
" 1 setmiterlimit\n";
391 doc->osHeader() <<
" } def\n";
395 doc->osHeader() <<
"/@hsize {/hs exch def} def\n";
396 doc->osHeader() <<
"/@vsize {/vs exch def} def\n";
400 doc->osHeader() <<
"/@hoffset {/ho exch def} def\n";
401 doc->osHeader() <<
"/@voffset {/vo exch def} def\n";
405 doc->osHeader() <<
"/lw " << (int) (
411 doc->osHeader() <<
"/@SetPlot\n";
412 doc->osHeader() <<
" {\n";
413 doc->osHeader() <<
" ho vo translate\n";
414 doc->osHeader() <<
" XScale YScale scale\n";
415 doc->osHeader() <<
" lw setlinewidth\n";
416 doc->osHeader() <<
" } def\n";
420 doc->osHeader() <<
"/XScale\n";
421 doc->osHeader() <<
" {hs " <<
YPSSIZE <<
" div} def\n";
422 doc->osHeader() <<
"/YScale\n";
423 doc->osHeader() <<
" {vs " <<
XPSSIZE <<
" div} def\n";
427 doc->osHeader() <<
"/M {moveto} def\n";
428 doc->osHeader() <<
"/D {lineto} def\n";
429 doc->osHeader() <<
"/A {0.5 0 360 arc} def\n";
430 doc->osHeader() <<
"/S {stroke} def\n";
431 doc->osHeader() <<
"/Z {stroke newpath} def\n";
433 doc->osHeader() <<
"/F {closepath gsave eofill grestore stroke} def\n";
435 doc->osHeader() <<
"/F {closepath gsave fill grestore stroke} def\n";
436 doc->osHeader() <<
"/N {newpath} def\n";
437 doc->osHeader() <<
"/C {setrgbcolor} def\n";
438 doc->osHeader() <<
"/G {setgray} def\n";
439 doc->osHeader() <<
"/W {setlinewidth} def\n";
440 doc->osHeader() <<
"/R {rotate} def\n";
441 doc->osHeader() <<
"/B {Z " << 0 <<
" " << 0 <<
" M " << 0 <<
" " <<
PSY <<
" D " <<
PSX <<
" " <<
PSY <<
" D " <<
PSX <<
" " << 0 <<
" D " << 0 <<
" " << 0 <<
" closepath} def\n";
442 doc->osHeader() <<
"/CL {newpath M D D D closepath clip} def\n";
446 doc->osHeader() <<
"end\n\n";
450 doc->osHeader() <<
"PSDict begin\n";
451 doc->osHeader() <<
"@start\n";
452 doc->osHeader() <<
COPIES <<
" @copies\n";
453 doc->osHeader() <<
"@line\n";
454 doc->osHeader() <<
YSIZE <<
" @hsize\n";
455 doc->osHeader() <<
XSIZE <<
" @vsize\n";
456 doc->osHeader() <<
YOFFSET <<
" @hoffset\n";
457 doc->osHeader() <<
XOFFSET <<
" @voffset\n";
459 doc->osHeader() <<
"@SetPlot\n" << endl;
472 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
473 PLINT x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
484 doc->osBody() <<
'\n';
488 doc->osBody() <<
' ';
490 snprintf( outbuf, OUTBUF_LEN,
"%d %d D", x2, y2 );
496 doc->osBody() <<
" Z\n";
499 if ( x1 == x2 && y1 == y2 )
500 snprintf( outbuf, OUTBUF_LEN,
"%d %d A", x1, y1 );
502 snprintf( outbuf, OUTBUF_LEN,
"%d %d M %d %d D", x1, y1, x2, y2 );
515 doc->osBody() << outbuf;
516 pls->
bytecnt += 1 + strlen( outbuf );
532 for ( i = 0; i < npts - 1; i++ )
545 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
546 doc->osBody() <<
" S\neop\n";
560 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
571 doc->osBody() <<
"%%Page: " << (int) pls->
page <<
" 1\n";
573 doc->osBody() <<
"%%Page: " << (int) pls->
page <<
" " << (
int) pls->
page <<
"\n";
575 doc->osBody() <<
"bop\n";
579 if ( pls->
cmap0[0].
r != 0xFF ||
580 pls->
cmap0[0].
g != 0xFF ||
587 doc->osBody() <<
"B " << r <<
" " << g <<
" " << b <<
" C F\n";
609 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
627 doc->osFooter() <<
"%%Pages: 1\n";
629 doc->osFooter() <<
"%%Pages: " << (int) pls->
page <<
"\n";
631 doc->osFooter() <<
"@end" << endl;
639 if ( !strcmp( pls->
FileName,
"-" ) )
641 doc->write( cout, dev->
llx, dev->
lly, dev->
urx, dev->
ury );
648 doc->write( out, dev->
llx, dev->
lly, dev->
urx, dev->
ury );
666 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
675 doc->osBody() <<
" S\n" << width <<
" W";
684 doc->osBody() <<
" S\n" << ( pls->
icol0 ? 0.0 : 1.0 ) <<
" G";
687 doc->osBody() <<
" " << (int) dev->
xold <<
" " << (
int) dev->
yold <<
" M \n";
698 doc->osBody() <<
" S\n" << r <<
" " << g <<
" " << b <<
" C";
703 doc->osBody() <<
" S\n" << 1.0 - r <<
" G";
707 doc->osBody() <<
" " << (int) dev->
xold <<
" " << (
int) dev->
yold <<
" M \n";
743 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
744 PLINT n, ix = 0, iy = 0;
747 doc->osBody() <<
" Z\n";
749 for ( n = 0; n < pls->
dev_npts; n++ )
751 x = pls->
dev_x[ix++];
752 y = pls->
dev_y[iy++];
762 snprintf( outbuf, OUTBUF_LEN,
"N %d %d M", x, y );
767 doc->osBody() << outbuf;
768 pls->
bytecnt += strlen( outbuf );
774 doc->osBody() <<
'\n';
778 doc->osBody() <<
' ';
782 snprintf( outbuf, OUTBUF_LEN,
"%d %d D", x, y );
788 doc->osBody() << outbuf;
789 pls->
bytecnt += strlen( outbuf );
794 doc->osBody() <<
" F ";
810 t = time( (time_t *) 0 );
813 *( p + len - 1 ) =
'\0';
823 # define RISE_FACTOR 0.6
837 PLFLT theta, shear, stride;
841 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
847 #define PROC_STR_STRING_LENGTH 1000
848 char *strp, str[PROC_STR_STRING_LENGTH], *cur_strp,
849 cur_str[PROC_STR_STRING_LENGTH];
850 float font_factor = 1.4;
851 PLINT clxmin, clxmax, clymin, clymax;
852 PLINT clipx[4], clipy[4];
854 PLFLT scale = 1., up = 0.;
856 double lineSpacing, xAdvance, ymintmp, ymaxtmp, ymin, ymax, xmin, xmax;
863 char *fonts[PROC_STR_STRING_LENGTH];
864 FontStyle styles[PROC_STR_STRING_LENGTH];
865 FontWeight weights[PROC_STR_STRING_LENGTH];
868 unsigned char fontfamily, fontstyle, fontweight;
869 PLFLT old_sscale, sscale, old_soffset, soffset, dup;
883 font = (
char *) FamilyLookup[fontfamily];
884 weight = WeightLookup[fontweight];
885 style = StyleLookup[fontstyle];
889 fprintf( stderr,
"fci = 0x%x, font name pointer = NULL \n", fci );
890 plabort(
"proc_str: FCI inconsistent with TrueTypeLookup; "
891 "internal PLplot error" );
904 if ( ( f < PROC_STR_STRING_LENGTH ) && ( s + 3 < PROC_STR_STRING_LENGTH ) )
909 fonts[f] = (
char *) FamilyLookup[fontfamily];
910 weights[f] = WeightLookup[fontweight];
911 styles[f] = StyleLookup[fontstyle];
912 if ( fonts[f] == NULL )
914 fprintf( stderr,
"string-supplied FCI = 0x%x, font name pointer = NULL \n", cur_text[j] );
915 plabort(
"proc_str: string-supplied FCI inconsistent with font lookup;" );
925 else if ( s + 1 < PROC_STR_STRING_LENGTH )
940 ft_ht = pls->
chrht * 72.0 / 25.4;
947 tt[0] = t[0] * cs + t[2] * sn;
948 tt[1] = t[1] * cs + t[3] * sn;
949 tt[2] = -t[0] * sn + t[2] * cs;
950 tt[3] = -t[1] * sn + t[3] * cs;
964 if ( args->
base == 2 )
966 else if ( args->
base == 1 )
969 offset = -
ENLARGE * ft_ht / 2.;
973 args->
y += (int) ( offset * cos( theta ) );
974 args->
x -= (int) ( offset * sin( theta ) );
978 &( args->
x ), &( args->
y ) );
993 difilt( clipx, clipy, 4, &clxmin, &clxmax, &clymin, &clymax );
995 &clipx[0], &clipy[0] );
997 &clipx[1], &clipy[1] );
999 &clipx[2], &clipy[2] );
1001 &clipx[3], &clipy[3] );
1002 doc->osBody() <<
" gsave " << clipx[0] <<
" " << clipy[0] <<
" " <<
1003 clipx[1] <<
" " << clipy[1] <<
" " << clipx[2] <<
" " <<
1004 clipy[2] <<
" " << clipx[3] <<
" " << clipy[3] <<
" CL\n";
1007 doc->osBody() <<
" " << args->
x <<
" " << args->
y <<
" M\n";
1010 doc->osBody() <<
"gsave " << TRMFLT( theta * 180. /
PI ) <<
" R\n";
1012 doc->osBody() <<
"[" << TRMFLT( tt[0] ) <<
" " << TRMFLT( tt[2] ) <<
" " << TRMFLT( tt[1] )
1013 <<
" " << TRMFLT( tt[3] ) <<
" 0 0] concat\n";
1024 if ( *cur_strp == esc )
1028 if ( *cur_strp == esc )
1030 *strp++ = *cur_strp++;
1032 else if ( *cur_strp ==
'f' )
1035 if ( *cur_strp++ !=
'f' )
1039 plabort(
"proc_str, internal PLplot logic error;"
1040 "wrong escf escape sequence" );
1045 weight = weights[f];
1050 switch ( *cur_strp++ )
1055 &old_sscale, &sscale, &old_soffset, &soffset );
1061 dup = -0.5 * ( 1.0 - sscale );
1068 &old_sscale, &sscale, &old_soffset, &soffset );
1074 dup = 0.5 * ( 1.0 - sscale );
1084 plwarn(
"'+', '-', and 'b/B' text escape sequences not processed." );
1092 while ( *cur_strp && *cur_strp != esc )
1094 *strp++ = *cur_strp++;
1101 doc->setFont( font, style, weight );
1102 doc->setFontSize( font_factor *
ENLARGE * ft_ht * scale );
1103 doc->get_dimensions( (
const char *) str, &lineSpacing, &xAdvance, &ymintmp, &ymaxtmp );
1105 }
while ( *cur_strp );
1109 xmin = -xmax * args->
just;
1120 doc->osBody() <<
" gsave " << TRMFLT( xmin * tt[0] ) <<
" " <<
1121 TRMFLT( xmin * tt[2] ) <<
" rmoveto\n";
1131 if ( *cur_strp == esc )
1135 if ( *cur_strp == esc )
1137 *strp++ = *cur_strp++;
1139 else if ( *cur_strp ==
'f' )
1142 if ( *cur_strp++ !=
'f' )
1146 plabort(
"proc_str, internal PLplot logic error;"
1147 "wrong escf escape sequence" );
1152 weight = weights[f];
1158 switch ( *cur_strp++ )
1163 &old_sscale, &sscale, &old_soffset, &soffset );
1169 dup = -0.5 * ( 1.0 - sscale );
1176 &old_sscale, &sscale, &old_soffset, &soffset );
1182 dup = 0.5 * ( 1.0 - sscale );
1192 plwarn(
"'+', '-', and 'b/B' text escape sequences not processed." );
1200 while ( *cur_strp && *cur_strp != esc )
1202 *strp++ = *cur_strp++;
1209 doc->setFont( font, style, weight );
1210 doc->setFontSize( font_factor *
ENLARGE * ft_ht * scale );
1211 doc->get_dimensions( (
const char *) str, &lineSpacing, &xAdvance, &ymintmp, &ymaxtmp );
1212 ymin =
MIN( ymintmp + up, ymin );
1213 ymax =
MAX( ymaxtmp + up, ymax );
1219 doc->osBody() <<
"gsave " << TRMFLT( up * tt[1] ) <<
" " << TRMFLT( up * tt[3] ) <<
" rmoveto\n";
1222 doc->osBody() << show( (
const char *) str );
1226 doc->osBody() <<
"grestore " << TRMFLT( xAdvance * tt[0] ) <<
" " << TRMFLT( xAdvance * tt[2] ) <<
" rmoveto\n";
1227 }
while ( *cur_strp );
1229 doc->osBody() <<
"grestore\n";
1230 doc->osBody() <<
"grestore\n";
1231 doc->osBody() <<
"grestore\n";
1239 xx[0] = (
PLINT) ( t[0] * xmin + t[1] * ymin );
1240 yy[0] = (
PLINT) ( t[2] * xmin + t[3] * ymin );
1241 xx[1] = (
PLINT) ( t[0] * xmin + t[1] * ymax );
1242 yy[1] = (
PLINT) ( t[2] * xmin + t[3] * ymax );
1243 xx[2] = (
PLINT) ( t[0] * xmax + t[1] * ymin );
1244 yy[2] = (
PLINT) ( t[2] * xmax + t[3] * ymin );
1245 xx[3] = (
PLINT) ( t[0] * xmax + t[1] * ymax );
1246 yy[3] = (
PLINT) ( t[2] * xmax + t[3] * ymax );
1254 xmin =
MIN(
MIN(
MIN( xx[0], xx[1] ), xx[2] ), xx[3] ) + args->
x;
1255 xmax =
MAX(
MAX(
MAX( xx[0], xx[1] ), xx[2] ), xx[3] ) + args->
x;
1256 ymin =
MIN(
MIN(
MIN( yy[0], yy[1] ), yy[2] ), yy[3] ) + args->
y;
1257 ymax =
MAX(
MAX(
MAX( yy[0], yy[1] ), yy[2] ), yy[3] ) + args->
y;
1259 dev->
llx = (int) (
MIN( dev->
llx, xmin ) );
1260 dev->
lly = (int) (
MIN( dev->
lly, ymin ) );
1261 dev->
urx = (int) (
MAX( dev->
urx, xmax ) );
1262 dev->
ury = (int) (
MAX( dev->
ury, ymax ) );
1317 #endif // defined(PLD_psttf) || ....
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 plP_fci2hex(PLUNICODE fci, unsigned char *phexdigit, unsigned char hexpower)
void(* plD_state_fp)(struct PLStream_struct *, PLINT)
void(* plD_tidy_fp)(struct PLStream_struct *)
void plOpenFile(PLStream *pls)
void plCloseFile(PLStream *pls)
void plD_esc_psttf(PLStream *, PLINT, void *)
void plGetFam(PLStream *pls)
void plD_init_psttfm(PLStream *)
int ucs4_to_utf8(PLUNICODE unichar, char *ptr)
#define FAMILY_LOOKUP_LEN
void plabort(PLCHAR_VECTOR errormsg)
void plD_polyline_psttf(PLStream *, short *, short *, PLINT)
void plD_tidy_psttf(PLStream *)
void plFamInit(PLStream *pls)
void(* plD_polyline_fp)(struct PLStream_struct *, short *, short *, PLINT)
void plD_init_psttfc(PLStream *)
void plD_state_psttf(PLStream *, PLINT)
void(* plD_esc_fp)(struct PLStream_struct *, PLINT, void *)
void(* plD_bop_fp)(struct PLStream_struct *)
void plD_line_psttf(PLStream *, short, short, short, short)
void difilt(PLINT *xsc, PLINT *ysc, PLINT npts, PLINT *clpxmi, PLINT *clpxma, PLINT *clpymi, PLINT *clpyma)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_psttfm(PLDispatchTable *pdt)
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_psttf(PLStream *)
void plRotationShear(PLFLT *xFormMatrix, PLFLT *rotation, PLFLT *shear, PLFLT *stride)
static void proc_str(PLStream *, EscText *)
unsigned short unicode_array_len
void plRotPhy(PLINT orient, PLINT xmin, PLINT ymin, PLINT xmax, PLINT ymax, PLINT *px, PLINT *py)
void plD_eop_psttf(PLStream *)
void plwarn(PLCHAR_VECTOR errormsg)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_psttfc(PLDispatchTable *pdt)
plD_polyline_fp pl_polyline
PLUNICODE * unicode_array
void(* plD_init_fp)(struct PLStream_struct *)