46 #define TRMFLT( a ) ( ( fabs( a ) < 5.0e-4 ) ? 0.0 : ( a ) ) 55 "psttf:PostScript File (monochrome):0:psttf:55:psttf\n" 58 "psttfc:PostScript File (color):0:psttf:56:psttfc\n" 78 const char *menustr,
const char *devnam,
81 #define OUTBUF_LEN 128 89 #define N_Pango_Lookup 5 100 "PLPLOT_FREETYPE_SANS_FAMILY",
101 "PLPLOT_FREETYPE_SERIF_FAMILY",
102 "PLPLOT_FREETYPE_MONO_FAMILY",
103 "PLPLOT_FREETYPE_SCRIPT_FAMILY",
104 "PLPLOT_FREETYPE_SYMBOL_FAMILY" 107 #define FAMILY_LOOKUP_LEN 1024 123 {
"hrshsym",
DRV_INT, &
hrshsym,
"Use Hershey symbol set (hrshsym=0|1)" },
124 { NULL,
DRV_INT, NULL, NULL } };
132 const char *menustr,
const char *devnam,
135 #ifndef ENABLE_DYNDRIVERS 158 "PostScript File (monochrome)",
"psttf",
180 #endif //#ifdef PLD_psttf 186 "PostScript File (color)",
"psttfc",
202 #endif //#ifdef PLD_psttfc 204 #define MAX_NUM_TRIES 10 211 PostscriptDocument *doc;
220 if ( pls->
xdpi <= 0 )
222 if ( pls->
ydpi <= 0 )
248 if ( pls->
psdoc != NULL )
249 delete (PostscriptDocument *) pls->
psdoc;
251 pls->
psdoc =
new PostscriptDocument();
252 doc = (PostscriptDocument *) ( pls->
psdoc );
253 doc->osBody() << fixed;
254 doc->osBody().precision( 3 );
258 if ( pls->
dev != NULL )
259 free( (
void *) pls->
dev );
261 pls->
dev = calloc( 1, (
size_t)
sizeof (
PSDev ) );
262 if ( pls->
dev == NULL )
263 plexit(
"ps_init: Out of memory." );
329 PostscriptDocument *doc = (PostscriptDocument *) ( pls->
psdoc );
331 doc->osHeader() <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
333 doc->osHeader() <<
"%%Title: PLplot Graph\n";
334 doc->osHeader() <<
"%%Creator: PLplot Version " <<
PLPLOT_VERSION <<
"\n";
335 doc->osHeader() <<
"%%CreationDate: " <<
ps_getdate() <<
"\n";
336 doc->osHeader() <<
"%%Pages: (atend)\n";
337 doc->osHeader() <<
"%%EndComments\n\n";
342 doc->osHeader() <<
"/PSSave save def\n";
346 doc->osHeader() <<
"/PSDict 200 dict def\n";
347 doc->osHeader() <<
"PSDict begin\n";
349 doc->osHeader() <<
"/@restore /restore load def\n";
350 doc->osHeader() <<
"/restore\n";
351 doc->osHeader() <<
" {vmstatus pop\n";
352 doc->osHeader() <<
" dup @VMused lt {pop @VMused} if\n";
353 doc->osHeader() <<
" exch pop exch @restore /@VMused exch def\n";
354 doc->osHeader() <<
" } def\n";
355 doc->osHeader() <<
"/@pri\n";
356 doc->osHeader() <<
" {\n";
357 doc->osHeader() <<
" ( ) print\n";
358 doc->osHeader() <<
" ( ) cvs print\n";
359 doc->osHeader() <<
" } def\n";
363 doc->osHeader() <<
"/@copies\n";
364 doc->osHeader() <<
" {\n";
365 doc->osHeader() <<
" /#copies exch def\n";
366 doc->osHeader() <<
" } def\n";
370 doc->osHeader() <<
"/@start\n";
371 doc->osHeader() <<
" {\n";
372 doc->osHeader() <<
" vmstatus pop /@VMused exch def pop\n";
373 doc->osHeader() <<
" } def\n";
377 doc->osHeader() <<
"/@end\n";
378 doc->osHeader() <<
" {flush\n";
379 doc->osHeader() <<
" end\n";
380 doc->osHeader() <<
" PSSave restore\n";
381 doc->osHeader() <<
" } def\n";
386 doc->osHeader() <<
"/bop\n";
387 doc->osHeader() <<
" {\n";
388 doc->osHeader() <<
" /SaveImage save def\n";
389 doc->osHeader() <<
" } def\n";
393 doc->osHeader() <<
"/eop\n";
394 doc->osHeader() <<
" {\n";
395 doc->osHeader() <<
" showpage\n";
396 doc->osHeader() <<
" SaveImage restore\n";
397 doc->osHeader() <<
" } def\n";
401 doc->osHeader() <<
"/@line\n";
402 doc->osHeader() <<
" {0 setlinecap\n";
403 doc->osHeader() <<
" 0 setlinejoin\n";
404 doc->osHeader() <<
" 1 setmiterlimit\n";
405 doc->osHeader() <<
" } def\n";
409 doc->osHeader() <<
"/@hsize {/hs exch def} def\n";
410 doc->osHeader() <<
"/@vsize {/vs exch def} def\n";
414 doc->osHeader() <<
"/@hoffset {/ho exch def} def\n";
415 doc->osHeader() <<
"/@voffset {/vo exch def} def\n";
419 doc->osHeader() <<
"/lw " << (int) (
425 doc->osHeader() <<
"/@SetPlot\n";
426 doc->osHeader() <<
" {\n";
427 doc->osHeader() <<
" ho vo translate\n";
428 doc->osHeader() <<
" XScale YScale scale\n";
429 doc->osHeader() <<
" lw setlinewidth\n";
430 doc->osHeader() <<
" } def\n";
434 doc->osHeader() <<
"/XScale\n";
435 doc->osHeader() <<
" {hs " <<
YPSSIZE <<
" div} def\n";
436 doc->osHeader() <<
"/YScale\n";
437 doc->osHeader() <<
" {vs " <<
XPSSIZE <<
" div} def\n";
441 doc->osHeader() <<
"/M {moveto} def\n";
442 doc->osHeader() <<
"/D {lineto} def\n";
443 doc->osHeader() <<
"/A {0.5 0 360 arc} def\n";
444 doc->osHeader() <<
"/S {stroke} def\n";
445 doc->osHeader() <<
"/Z {stroke newpath} def\n";
447 doc->osHeader() <<
"/F {closepath gsave eofill grestore stroke} def\n";
449 doc->osHeader() <<
"/F {closepath gsave fill grestore stroke} def\n";
450 doc->osHeader() <<
"/N {newpath} def\n";
451 doc->osHeader() <<
"/C {setrgbcolor} def\n";
452 doc->osHeader() <<
"/G {setgray} def\n";
453 doc->osHeader() <<
"/W {setlinewidth} def\n";
454 doc->osHeader() <<
"/R {rotate} def\n";
455 doc->osHeader() <<
"/B {Z " << 0 <<
" " << 0 <<
" M " << 0 <<
" " <<
PSY <<
" D " <<
PSX <<
" " <<
PSY <<
" D " <<
PSX <<
" " << 0 <<
" D " << 0 <<
" " << 0 <<
" closepath} def\n";
456 doc->osHeader() <<
"/CL {newpath M D D D closepath clip} def\n";
460 doc->osHeader() <<
"end\n\n";
464 doc->osHeader() <<
"PSDict begin\n";
465 doc->osHeader() <<
"@start\n";
466 doc->osHeader() <<
COPIES <<
" @copies\n";
467 doc->osHeader() <<
"@line\n";
468 doc->osHeader() <<
YSIZE <<
" @hsize\n";
469 doc->osHeader() <<
XSIZE <<
" @vsize\n";
470 doc->osHeader() <<
YOFFSET <<
" @hoffset\n";
471 doc->osHeader() <<
XOFFSET <<
" @voffset\n";
473 doc->osHeader() <<
"@SetPlot\n" << endl;
486 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
487 PLINT x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
498 doc->osBody() <<
'\n';
502 doc->osBody() <<
' ';
510 doc->osBody() <<
" Z\n";
513 if ( x1 == x2 && y1 == y2 )
546 for ( i = 0; i < npts - 1; i++ )
559 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
560 doc->osBody() <<
" S\neop\n";
574 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
585 doc->osBody() <<
"%%Page: " << (int) pls->
page <<
" 1\n";
587 doc->osBody() <<
"%%Page: " << (int) pls->
page <<
" " << (
int) pls->
page <<
"\n";
589 doc->osBody() <<
"bop\n";
593 if ( pls->
cmap0[0].
r != 0xFF ||
594 pls->
cmap0[0].
g != 0xFF ||
601 doc->osBody() <<
"B " << r <<
" " << g <<
" " << b <<
" C F\n";
623 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
641 doc->osFooter() <<
"%%Pages: 1\n";
643 doc->osFooter() <<
"%%Pages: " << (int) pls->
page <<
"\n";
645 doc->osFooter() <<
"@end" << endl;
653 if ( !strcmp( pls->
FileName,
"-" ) )
655 doc->write( cout, dev->
llx, dev->
lly, dev->
urx, dev->
ury );
662 doc->write( out, dev->
llx, dev->
lly, dev->
urx, dev->
ury );
680 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
689 doc->osBody() <<
" S\n" << width <<
" W";
698 doc->osBody() <<
" S\n" << ( pls->
icol0 ? 0.0 : 1.0 ) <<
" G";
701 doc->osBody() <<
" " << (int) dev->
xold <<
" " << (
int) dev->
yold <<
" M \n";
712 doc->osBody() <<
" S\n" << r <<
" " << g <<
" " << b <<
" C";
717 doc->osBody() <<
" S\n" << 1.0 - r <<
" G";
721 doc->osBody() <<
" " << (int) dev->
xold <<
" " << (
int) dev->
yold <<
" M \n";
757 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
758 PLINT n, ix = 0, iy = 0;
761 doc->osBody() <<
" Z\n";
763 for ( n = 0; n < pls->
dev_npts; n++ )
765 x = pls->
dev_x[ix++];
766 y = pls->
dev_y[iy++];
788 doc->osBody() <<
'\n';
792 doc->osBody() <<
' ';
808 doc->osBody() <<
" F ";
824 t = time( (time_t *) 0 );
827 *( p + len - 1 ) =
'\0';
837 # define RISE_FACTOR 0.6 851 PLFLT theta, shear, stride;
855 PostscriptDocument *doc = (PostscriptDocument *) pls->
psdoc;
861 #define PROC_STR_STRING_LENGTH 1000 864 float font_factor = 1.4;
865 PLINT clxmin, clxmax, clymin, clymax;
866 PLINT clipx[4], clipy[4];
868 PLFLT scale = 1., up = 0.;
870 double lineSpacing, xAdvance, ymintmp, ymaxtmp, ymin, ymax, xmin, xmax;
882 unsigned char fontfamily, fontstyle, fontweight;
883 PLFLT old_sscale, sscale, old_soffset, soffset, dup;
903 fprintf( stderr,
"fci = 0x%x, font name pointer = NULL \n", fci );
904 plabort(
"proc_str: FCI inconsistent with TrueTypeLookup; " 905 "internal PLplot error" );
926 if ( fonts[f] == NULL )
928 fprintf( stderr,
"string-supplied FCI = 0x%x, font name pointer = NULL \n", cur_text[j] );
929 plabort(
"proc_str: string-supplied FCI inconsistent with font lookup;" );
954 ft_ht = pls->
chrht * 72.0 / 25.4;
961 tt[0] = t[0] * cs + t[2] * sn;
962 tt[1] = t[1] * cs + t[3] * sn;
963 tt[2] = -t[0] * sn + t[2] * cs;
964 tt[3] = -t[1] * sn + t[3] * cs;
978 if ( args->
base == 2 )
980 else if ( args->
base == 1 )
983 offset = -
ENLARGE * ft_ht / 2.;
987 args->
y += (int) ( offset * cos( theta ) );
988 args->
x -= (int) ( offset * sin( theta ) );
992 &( args->
x ), &( args->
y ) );
1003 clipx[1] = clipx[2];
1004 clipy[1] = clipy[0];
1005 clipx[3] = clipx[0];
1006 clipy[3] = clipy[2];
1007 difilt( clipx, clipy, 4, &clxmin, &clxmax, &clymin, &clymax );
1009 &clipx[0], &clipy[0] );
1011 &clipx[1], &clipy[1] );
1013 &clipx[2], &clipy[2] );
1015 &clipx[3], &clipy[3] );
1016 doc->osBody() <<
" gsave " << clipx[0] <<
" " << clipy[0] <<
" " <<
1017 clipx[1] <<
" " << clipy[1] <<
" " << clipx[2] <<
" " <<
1018 clipy[2] <<
" " << clipx[3] <<
" " << clipy[3] <<
" CL\n";
1021 doc->osBody() <<
" " << args->
x <<
" " << args->
y <<
" M\n";
1024 doc->osBody() <<
"gsave " <<
TRMFLT( theta * 180. /
PI ) <<
" R\n";
1026 doc->osBody() <<
"[" <<
TRMFLT( tt[0] ) <<
" " <<
TRMFLT( tt[2] ) <<
" " <<
TRMFLT( tt[1] )
1027 <<
" " <<
TRMFLT( tt[3] ) <<
" 0 0] concat\n";
1038 if ( *cur_strp == esc )
1042 if ( *cur_strp == esc )
1044 *strp++ = *cur_strp++;
1046 else if ( *cur_strp ==
'f' )
1049 if ( *cur_strp++ !=
'f' )
1053 plabort(
"proc_str, internal PLplot logic error;" 1054 "wrong escf escape sequence" );
1059 weight = weights[f];
1064 switch ( *cur_strp++ )
1069 &old_sscale, &sscale, &old_soffset, &soffset );
1075 dup = -0.5 * ( 1.0 - sscale );
1082 &old_sscale, &sscale, &old_soffset, &soffset );
1088 dup = 0.5 * ( 1.0 - sscale );
1098 plwarn(
"'+', '-', and 'b/B' text escape sequences not processed." );
1106 while ( *cur_strp && *cur_strp != esc )
1108 *strp++ = *cur_strp++;
1115 doc->setFont( font, style, weight );
1116 doc->setFontSize( font_factor *
ENLARGE * ft_ht * scale );
1117 doc->get_dimensions( (
const char *) str, &lineSpacing, &xAdvance, &ymintmp, &ymaxtmp );
1119 }
while ( *cur_strp );
1123 xmin = -xmax * args->
just;
1134 doc->osBody() <<
" gsave " <<
TRMFLT( xmin * tt[0] ) <<
" " <<
1135 TRMFLT( xmin * tt[2] ) <<
" rmoveto\n";
1145 if ( *cur_strp == esc )
1149 if ( *cur_strp == esc )
1151 *strp++ = *cur_strp++;
1153 else if ( *cur_strp ==
'f' )
1156 if ( *cur_strp++ !=
'f' )
1160 plabort(
"proc_str, internal PLplot logic error;" 1161 "wrong escf escape sequence" );
1166 weight = weights[f];
1172 switch ( *cur_strp++ )
1177 &old_sscale, &sscale, &old_soffset, &soffset );
1183 dup = -0.5 * ( 1.0 - sscale );
1190 &old_sscale, &sscale, &old_soffset, &soffset );
1196 dup = 0.5 * ( 1.0 - sscale );
1206 plwarn(
"'+', '-', and 'b/B' text escape sequences not processed." );
1214 while ( *cur_strp && *cur_strp != esc )
1216 *strp++ = *cur_strp++;
1223 doc->setFont( font, style, weight );
1224 doc->setFontSize( font_factor *
ENLARGE * ft_ht * scale );
1225 doc->get_dimensions( (
const char *) str, &lineSpacing, &xAdvance, &ymintmp, &ymaxtmp );
1226 ymin =
MIN( ymintmp + up, ymin );
1227 ymax =
MAX( ymaxtmp + up, ymax );
1233 doc->osBody() <<
"gsave " <<
TRMFLT( up * tt[1] ) <<
" " <<
TRMFLT( up * tt[3] ) <<
" rmoveto\n";
1236 doc->osBody() << show( (
const char *) str );
1240 doc->osBody() <<
"grestore " <<
TRMFLT( xAdvance * tt[0] ) <<
" " <<
TRMFLT( xAdvance * tt[2] ) <<
" rmoveto\n";
1241 }
while ( *cur_strp );
1243 doc->osBody() <<
"grestore\n";
1244 doc->osBody() <<
"grestore\n";
1245 doc->osBody() <<
"grestore\n";
1253 xx[0] = (
PLINT) ( t[0] * xmin + t[1] * ymin );
1254 yy[0] = (
PLINT) ( t[2] * xmin + t[3] * ymin );
1255 xx[1] = (
PLINT) ( t[0] * xmin + t[1] * ymax );
1256 yy[1] = (
PLINT) ( t[2] * xmin + t[3] * ymax );
1257 xx[2] = (
PLINT) ( t[0] * xmax + t[1] * ymin );
1258 yy[2] = (
PLINT) ( t[2] * xmax + t[3] * ymin );
1259 xx[3] = (
PLINT) ( t[0] * xmax + t[1] * ymax );
1260 yy[3] = (
PLINT) ( t[2] * xmax + t[3] * ymax );
1268 xmin =
MIN(
MIN(
MIN( xx[0], xx[1] ), xx[2] ), xx[3] ) + args->
x;
1269 xmax =
MAX(
MAX(
MAX( xx[0], xx[1] ), xx[2] ), xx[3] ) + args->
x;
1270 ymin =
MIN(
MIN(
MIN( yy[0], yy[1] ), yy[2] ), yy[3] ) + args->
y;
1271 ymax =
MAX(
MAX(
MAX( yy[0], yy[1] ), yy[2] ), yy[3] ) + args->
y;
1273 dev->
llx = (int) (
MIN( dev->
llx, xmin ) );
1274 dev->
lly = (int) (
MIN( dev->
lly, ymin ) );
1275 dev->
urx = (int) (
MAX( dev->
urx, xmax ) );
1276 dev->
ury = (int) (
MAX( dev->
ury, ymax ) );
PLDLLIMPEXP_DRIVER const char * plD_DEVICE_INFO_psttf
int plParseDrvOpts(DrvOpt *acc_opt)
static void psttf_dispatch_init_helper(PLDispatchTable *pdt, const char *menustr, const char *devnam, int type, int seq, plD_init_fp init)
void plP_script_scale(PLBOOL ifupper, PLINT *level, PLFLT *old_scale, PLFLT *scale, PLFLT *old_offset, PLFLT *offset)
const char * EnvFamilyLookup[N_Pango_Lookup]
void plexit(PLCHAR_VECTOR errormsg)
void writeHeader(PLStream *pls)
void plD_tidy_psttf(PLStream *pls)
void plP_fci2hex(PLUNICODE fci, unsigned char *phexdigit, unsigned char hexpower)
const FontWeight WeightLookup[2]
void plOpenFile(PLStream *pls)
void plCloseFile(PLStream *pls)
void plGetFam(PLStream *pls)
void(* plD_tidy_fp)(struct PLStream_struct *)
void plD_bop_psttf(PLStream *pls)
int ucs4_to_utf8(PLUNICODE unichar, char *ptr)
static DrvOpt ps_options[]
void plD_init_psttf(PLStream *)
void plD_state_psttf(PLStream *pls, PLINT op)
void(* plD_init_fp)(struct PLStream_struct *)
void(* plD_eop_fp)(struct PLStream_struct *)
void plabort(PLCHAR_VECTOR errormsg)
const FontStyle StyleLookup[3]
char FamilyLookup[N_Pango_Lookup][FAMILY_LOOKUP_LEN]
static char outbuf[OUTBUF_LEN]
#define PROC_STR_STRING_LENGTH
void plFamInit(PLStream *pls)
void plD_init_psttfc(PLStream *)
const char * DefaultFamilyLookup[N_Pango_Lookup]
void(* plD_line_fp)(struct PLStream_struct *, short, short, short, short)
void(* plD_esc_fp)(struct PLStream_struct *, PLINT, void *)
void(* plD_polyline_fp)(struct PLStream_struct *, short *, short *, PLINT)
static void proc_str(PLStream *, EscText *)
void difilt(PLINT *xsc, PLINT *ysc, PLINT npts, PLINT *clpxmi, PLINT *clpxma, PLINT *clpymi, PLINT *clpyma)
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_psttf(PLDispatchTable *pdt)
#define FAMILY_LOOKUP_LEN
#define PLDLLIMPEXP_DRIVER
static PLStream * pls[PL_NSTREAMS]
void plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
void plRotationShear(PLFLT *xFormMatrix, PLFLT *rotation, PLFLT *shear, PLFLT *stride)
unsigned short unicode_array_len
static char * ps_getdate(void)
void plD_eop_psttf(PLStream *pls)
void(* plD_bop_fp)(struct PLStream_struct *)
void plRotPhy(PLINT orient, PLINT xmin, PLINT ymin, PLINT xmax, PLINT ymax, PLINT *px, PLINT *py)
void plwarn(PLCHAR_VECTOR errormsg)
void plD_polyline_psttf(PLStream *pls, short *xa, short *ya, PLINT npts)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_psttfc(PLDispatchTable *pdt)
void plD_esc_psttf(PLStream *pls, PLINT op, void *ptr)
static void fill_polygon(PLStream *pls)
plD_polyline_fp pl_polyline
static void ps_init(PLStream *)
void(* plD_state_fp)(struct PLStream_struct *, PLINT)
PLUNICODE * unicode_array
void plD_line_psttf(PLStream *pls, short x1a, short y1a, short x2a, short y2a)