2
* Grace - GRaphing, Advanced Computation and Exploration of data
4
* Home page: http://plasma-gate.weizmann.ac.il/Grace/
6
* Copyright (c) 1991-1995 Paul J Turner, Portland, OR
7
* Copyright (c) 1996-2002 Grace Development Team
9
* Maintained by Evgeny Stambulchik <fnevgeny@plasma-gate.weizmann.ac.il>
14
* This program is free software; you can redistribute it and/or modify
15
* it under the terms of the GNU General Public License as published by
16
* the Free Software Foundation; either version 2 of the License, or
17
* (at your option) any later version.
19
* This program is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU General Public License for more details.
24
* You should have received a copy of the GNU General Public License
25
* along with this program; if not, write to the Free Software
26
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30
* GRACE PostScript driver
52
# include "motifinc.h"
55
extern FILE *prstream;
57
static void put_string(FILE *fp, char *s, int len);
59
static int curformat = DEFAULT_PS_FORMAT;
61
static unsigned long page_scale;
62
static double pixel_size;
63
static float page_scalef;
64
static int page_orientation;
66
static int *psfont_status = NULL;
69
static int ps_pattern;
70
static double ps_linew;
72
static int ps_linecap;
73
static int ps_linejoin;
75
static int ps_grayscale = FALSE;
76
static int ps_level2 = TRUE;
77
static int docdata = DOCDATA_8BIT;
79
static int ps_setup_offset_x = 0;
80
static int ps_setup_offset_y = 0;
82
static int ps_setup_grayscale = FALSE;
83
static int ps_setup_level2 = TRUE;
84
static int ps_setup_docdata = DOCDATA_8BIT;
86
static int ps_setup_feed = MEDIA_FEED_AUTO;
87
static int ps_setup_hwres = FALSE;
89
static int eps_setup_grayscale = FALSE;
90
static int eps_setup_level2 = TRUE;
91
static int eps_setup_tight_bb = TRUE;
92
static int eps_setup_docdata = DOCDATA_8BIT;
96
static Device_entry dev_ps = {DEVICE_PRINT,
108
static Device_entry dev_eps = {DEVICE_FILE,
120
int register_ps_drv(void)
122
return register_device(dev_ps);
125
int register_eps_drv(void)
127
return register_device(dev_eps);
130
static int ps_initgraphics(int format)
135
int width_pp, height_pp, page_offset_x, page_offset_y;
142
/* device-dependent routines */
143
devupdatecmap = NULL;
145
devdrawpixel = ps_drawpixel;
146
devdrawpolyline = ps_drawpolyline;
147
devfillpolygon = ps_fillpolygon;
148
devdrawarc = ps_drawarc;
149
devfillarc = ps_fillarc;
150
devputpixmap = ps_putpixmap;
151
devputtext = ps_puttext;
153
devleavegraphics = ps_leavegraphics;
155
pg = get_page_geometry();
157
page_scale = MIN2(pg.height, pg.width);
158
pixel_size = 1.0/page_scale;
159
page_scalef = (float) page_scale*72.0/pg.dpi;
161
if (curformat == PS_FORMAT && pg.height < pg.width) {
162
page_orientation = PAGE_ORIENT_LANDSCAPE;
164
page_orientation = PAGE_ORIENT_PORTRAIT;
167
/* undefine all graphics state parameters */
175
/* Font status table */
176
if (psfont_status != NULL) {
177
xfree(psfont_status);
179
psfont_status = xmalloc(number_of_fonts()*SIZEOF_INT);
180
for (i = 0; i < number_of_fonts(); i++) {
181
psfont_status[i] = FALSE;
186
fprintf(prstream, "%%!PS-Adobe-3.0\n");
188
page_offset_x = ps_setup_offset_x;
189
page_offset_y = ps_setup_offset_y;
192
fprintf(prstream, "%%!PS-Adobe-3.0 EPSF-3.0\n");
193
tight_bb = eps_setup_tight_bb;
198
errmsg("Invalid PS format");
199
return RETURN_FAILURE;
202
if (page_orientation == PAGE_ORIENT_LANDSCAPE) {
203
width_pp = (int) rint(72.0*pg.height/pg.dpi);
204
height_pp = (int) rint(72.0*pg.width/pg.dpi);
206
width_pp = (int) rint(72.0*pg.width/pg.dpi);
207
height_pp = (int) rint(72.0*pg.height/pg.dpi);
210
if (tight_bb == TRUE) {
211
fprintf(prstream, "%%%%BoundingBox: (atend)\n");
213
fprintf(prstream, "%%%%BoundingBox: %d %d %d %d\n",
214
page_offset_x, page_offset_y,
215
width_pp + page_offset_x, height_pp + page_offset_y);
218
if (ps_level2 == TRUE) {
219
fprintf(prstream, "%%%%LanguageLevel: 2\n");
221
fprintf(prstream, "%%%%LanguageLevel: 1\n");
224
fprintf(prstream, "%%%%Creator: %s\n", bi_version_string());
227
fprintf(prstream, "%%%%CreationDate: %s", ctime(&time_value));
230
fprintf(prstream, "%%%%DocumentData: Clean7Bit\n");
233
fprintf(prstream, "%%%%DocumentData: Clean8Bit\n");
236
fprintf(prstream, "%%%%DocumentData: Binary\n");
239
if (page_orientation == PAGE_ORIENT_LANDSCAPE) {
240
fprintf(prstream, "%%%%Orientation: Landscape\n");
242
fprintf(prstream, "%%%%Orientation: Portrait\n");
245
if (curformat == PS_FORMAT) {
246
fprintf(prstream, "%%%%Pages: 1\n");
247
fprintf(prstream, "%%%%PageOrder: Ascend\n");
249
fprintf(prstream, "%%%%Title: %s\n", get_docname());
250
fprintf(prstream, "%%%%For: %s\n", get_username());
251
fprintf(prstream, "%%%%DocumentNeededResources: (atend)\n");
252
fprintf(prstream, "%%%%EndComments\n");
255
fprintf(prstream, "%%%%BeginProlog\n");
256
if (curformat == PS_FORMAT) {
257
fprintf(prstream, "/PAGE_OFFSET_X %d def\n", page_offset_x);
258
fprintf(prstream, "/PAGE_OFFSET_Y %d def\n", page_offset_y);
260
fprintf(prstream, "/m {moveto} def\n");
261
fprintf(prstream, "/l {lineto} def\n");
262
fprintf(prstream, "/s {stroke} def\n");
263
fprintf(prstream, "/n {newpath} def\n");
264
fprintf(prstream, "/c {closepath} def\n");
265
fprintf(prstream, "/RL {rlineto} def\n");
266
fprintf(prstream, "/SLW {setlinewidth} def\n");
267
fprintf(prstream, "/GS {gsave} def\n");
268
fprintf(prstream, "/GR {grestore} def\n");
269
fprintf(prstream, "/SC {setcolor} def\n");
270
fprintf(prstream, "/SGRY {setgray} def\n");
271
fprintf(prstream, "/SRGB {setrgbcolor} def\n");
272
fprintf(prstream, "/SD {setdash} def\n");
273
fprintf(prstream, "/SLC {setlinecap} def\n");
274
fprintf(prstream, "/SLJ {setlinejoin} def\n");
275
fprintf(prstream, "/SCS {setcolorspace} def\n");
276
fprintf(prstream, "/FFSF {findfont setfont} def\n");
277
fprintf(prstream, "/CC {concat} def\n");
278
fprintf(prstream, "/PXL {n m 0 0 RL s} def\n");
280
for (i = 0; i < number_of_colors(); i++) {
281
fprintf(prstream,"/Color%d {", i);
282
if (ps_grayscale == TRUE) {
283
fprintf(prstream,"%.4f", get_colorintensity(i));
287
fprintf(prstream, "%.4f %.4f %.4f",
288
frgb->red,frgb->green, frgb->blue);
291
fprintf(prstream,"} def\n");
294
if (ps_level2 == TRUE) {
295
fprintf(prstream, "/PTRN {\n");
296
fprintf(prstream, " /pat_bits exch def \n");
297
fprintf(prstream, " <<\n");
298
fprintf(prstream, " /PaintType 2\n");
299
fprintf(prstream, " /PatternType 1 /TilingType 1\n");
300
fprintf(prstream, " /BBox[0 0 16 16]\n");
301
fprintf(prstream, " /XStep 16 /YStep 16\n");
302
fprintf(prstream, " /PaintProc {\n");
303
fprintf(prstream, " pop\n");
304
fprintf(prstream, " 16 16 true [-1 0 0 -1 16 16] pat_bits imagemask\n");
305
fprintf(prstream, " }\n");
306
fprintf(prstream, " >>\n");
307
fprintf(prstream, " [%.4f 0 0 %.4f 0 0]\n", 1.0/page_scalef, 1.0/page_scalef);
308
fprintf(prstream, " makepattern\n");
309
fprintf(prstream, "} def\n");
310
for (i = 0; i < number_of_patterns(); i++) {
311
fprintf(prstream, "/Pattern%d {<", i);
312
for (j = 0; j < 32; j++) {
313
fprintf(prstream, "%02x", pat_bits[i][j]);
315
fprintf(prstream, "> PTRN} bind def\n");
320
fprintf(prstream, "/ellipsedict 8 dict def\n");
321
fprintf(prstream, "ellipsedict /mtrx matrix put\n");
322
fprintf(prstream, "/EARC {\n");
323
fprintf(prstream, " ellipsedict begin\n");
324
fprintf(prstream, " /endangle exch def\n");
325
fprintf(prstream, " /startangle exch def\n");
326
fprintf(prstream, " /yrad exch def\n");
327
fprintf(prstream, " /xrad exch def\n");
328
fprintf(prstream, " /y exch def\n");
329
fprintf(prstream, " /x exch def\n");
330
fprintf(prstream, " /savematrix mtrx currentmatrix def\n");
331
fprintf(prstream, " x y translate\n");
332
fprintf(prstream, " xrad yrad scale\n");
333
fprintf(prstream, " 0 0 1 startangle endangle arc\n");
334
fprintf(prstream, " savematrix setmatrix\n");
335
fprintf(prstream, " end\n");
336
fprintf(prstream, "} def\n");
338
/* Text under/overlining etc */
339
fprintf(prstream, "/TL {\n");
340
fprintf(prstream, " /kcomp exch def\n");
341
fprintf(prstream, " /linewidth exch def\n");
342
fprintf(prstream, " /offset exch def\n");
343
fprintf(prstream, " GS\n");
344
fprintf(prstream, " 0 offset rmoveto\n");
345
fprintf(prstream, " linewidth SLW\n");
346
fprintf(prstream, " dup stringwidth exch kcomp add exch RL s\n");
347
fprintf(prstream, " GR\n");
348
fprintf(prstream, "} def\n");
351
fprintf(prstream, "/KINIT\n");
352
fprintf(prstream, "{\n");
353
fprintf(prstream, " /kvector exch def\n");
354
fprintf(prstream, " /kid 0 def\n");
355
fprintf(prstream, "} def\n");
356
fprintf(prstream, "/KPROC\n");
357
fprintf(prstream, "{\n");
358
fprintf(prstream, " pop pop\n");
359
fprintf(prstream, " kvector kid get\n");
360
fprintf(prstream, " 0 rmoveto\n");
361
fprintf(prstream, " /kid 1 kid add def\n");
362
fprintf(prstream, "} def\n");
364
/* Default encoding */
365
enc = get_default_encoding();
366
fprintf(prstream, "/DefEncoding [\n");
367
for (i = 0; i < 256; i++) {
368
fprintf(prstream, " /%s\n", enc[i]);
370
fprintf(prstream, "] def\n");
372
fprintf(prstream, "%%%%EndProlog\n");
374
fprintf(prstream, "%%%%BeginSetup\n");
375
if (ps_level2 == TRUE && curformat == PS_FORMAT) {
377
switch (ps_setup_feed) {
378
case MEDIA_FEED_AUTO:
380
case MEDIA_FEED_MATCH:
381
fprintf(prstream, "%%%%BeginFeature: *PageSize\n");
383
"<</PageSize [%d %d] /ImagingBBox null>> setpagedevice\n",
384
width_pp, height_pp);
385
fprintf(prstream, "%%%%EndFeature\n");
387
case MEDIA_FEED_MANUAL:
388
fprintf(prstream, "%%%%BeginFeature: *ManualFeed\n");
389
fprintf(prstream, "<</ManualFeed true>> setpagedevice\n");
390
fprintf(prstream, "%%%%EndFeature\n");
394
/* force HW resolution */
395
if (ps_setup_hwres == TRUE) {
396
fprintf(prstream, "%%%%BeginFeature: *HWResolution\n");
397
fprintf(prstream, "<</HWResolution [%d %d]>> setpagedevice\n",
398
(int) pg.dpi, (int) pg.dpi);
399
fprintf(prstream, "%%%%EndFeature\n");
403
/* compensate for printer page offsets */
404
if (curformat == PS_FORMAT) {
405
fprintf(prstream, "PAGE_OFFSET_X PAGE_OFFSET_Y translate\n");
407
fprintf(prstream, "%.2f %.2f scale\n", page_scalef, page_scalef);
408
/* rotate to get landscape on hardcopy */
409
if (page_orientation == PAGE_ORIENT_LANDSCAPE) {
410
fprintf(prstream, "90 rotate\n");
411
fprintf(prstream, "0.0 -1.0 translate\n");
413
fprintf(prstream, "%%%%EndSetup\n");
415
if (curformat == PS_FORMAT) {
416
fprintf(prstream, "%%%%Page: 1 1\n");
419
return RETURN_SUCCESS;
428
if (pen.color != ps_color || pen.pattern != ps_pattern) {
429
if (ps_level2 == TRUE) {
430
if (pen.pattern == 1) {
431
if (ps_grayscale == TRUE) {
432
fprintf(prstream, "[/DeviceGray] SCS\n");
434
fprintf(prstream, "[/DeviceRGB] SCS\n");
436
fprintf(prstream, "Color%d SC\n", pen.color);
438
if (ps_grayscale == TRUE) {
439
fprintf(prstream, "[/Pattern /DeviceGray] SCS\n");
441
fprintf(prstream, "[/Pattern /DeviceRGB] SCS\n");
444
"Color%d Pattern%d SC\n", pen.color, pen.pattern);
447
if (ps_grayscale == TRUE) {
448
fprintf(prstream, "Color%d SGRY\n", pen.color);
450
fprintf(prstream, "Color%d SRGB\n", pen.color);
453
ps_color = pen.color;
454
ps_pattern = pen.pattern;
458
void ps_setdrawbrush(void)
467
lw = MAX2(getlinewidth(), pixel_size);
469
if (ls != ps_lines || lw != ps_linew) {
470
fprintf(prstream, "[");
472
for (i = 0; i < dash_array_length[ls]; i++) {
473
fprintf(prstream, "%.4f ", lw*dash_array[ls][i]);
476
fprintf(prstream, "] 0 SD\n");
477
fprintf(prstream, "%.4f SLW\n", lw);
483
void ps_setlineprops(void)
490
if (lc != ps_linecap) {
493
fprintf(prstream, "0 SLC\n");
496
fprintf(prstream, "1 SLC\n");
499
fprintf(prstream, "2 SLC\n");
505
if (lj != ps_linejoin) {
508
fprintf(prstream, "0 SLJ\n");
511
fprintf(prstream, "1 SLJ\n");
514
fprintf(prstream, "2 SLJ\n");
521
void ps_drawpixel(VPoint vp)
525
if (ps_linew != pixel_size) {
526
fprintf(prstream, "%.4f SLW\n", pixel_size);
527
ps_linew = pixel_size;
529
if (ps_linecap != LINECAP_ROUND) {
530
fprintf(prstream, "1 SLC\n");
531
ps_linecap = LINECAP_ROUND;
534
fprintf(prstream, "[] 0 SD\n");
538
fprintf(prstream, "%.4f %.4f PXL\n", vp.x, vp.y);
541
void ps_drawpolyline(VPoint *vps, int n, int mode)
549
fprintf(prstream, "n\n");
550
fprintf(prstream, "%.4f %.4f m\n", vps[0].x, vps[0].y);
551
for (i = 1; i < n; i++) {
552
fprintf(prstream, "%.4f %.4f l\n", vps[i].x, vps[i].y);
554
if (mode == POLYLINE_CLOSED) {
555
fprintf(prstream, "%.4f %.4f l\n", vps[0].x, vps[0].y);
556
fprintf(prstream, "c\n");
558
fprintf(prstream, "s\n");
561
void ps_fillpolygon(VPoint *vps, int nc)
566
if (pen.pattern == 0 || nc < 3) {
570
fprintf(prstream, "n\n");
571
fprintf(prstream, "%.4f %.4f m\n", vps[0].x, vps[0].y);
572
for (i = 1; i < nc; i++) {
573
fprintf(prstream, "%.4f %.4f l\n", vps[i].x, vps[i].y);
575
fprintf(prstream, "c\n");
577
/* fill bg first if the pattern != solid */
578
if (pen.pattern != 1 && ps_level2 == TRUE) {
579
fprintf(prstream, "GS\n");
580
if (ps_grayscale == TRUE) {
581
if (ps_pattern != 1) {
582
fprintf(prstream, "[/DeviceGray] SCS\n");
584
fprintf(prstream, "Color%d SGRY\n", getbgcolor());
586
if (ps_pattern != 1) {
587
fprintf(prstream, "[/DeviceRGB] SCS\n");
589
fprintf(prstream, "Color%d SRGB\n", getbgcolor());
591
if (getfillrule() == FILLRULE_WINDING) {
592
fprintf(prstream, "fill\n");
594
fprintf(prstream, "eofill\n");
596
fprintf(prstream, "GR\n");
600
if (getfillrule() == FILLRULE_WINDING) {
601
fprintf(prstream, "fill\n");
603
fprintf(prstream, "eofill\n");
607
void ps_drawarc(VPoint vp1, VPoint vp2, int a1, int a2)
614
vpc.x = (vp1.x + vp2.x)/2;
615
vpc.y = (vp1.y + vp2.y)/2;
616
rx = fabs(vp2.x - vp1.x)/2;
617
ry = fabs(vp2.y - vp1.y)/2;
619
fprintf(prstream, "n %.4f %.4f %.4f %.4f %d %d EARC s\n",
620
vpc.x, vpc.y, rx, ry, a1, a2);
623
void ps_fillarc(VPoint vp1, VPoint vp2, int a1, int a2, int mode)
629
if (pen.pattern == 0) {
633
vpc.x = (vp1.x + vp2.x)/2;
634
vpc.y = (vp1.y + vp2.y)/2;
635
rx = fabs(vp2.x - vp1.x)/2;
636
ry = fabs(vp2.y - vp1.y)/2;
638
fprintf(prstream, "n\n");
640
if (mode == ARCFILL_PIESLICE) {
641
fprintf(prstream, "%.4f %.4f m\n", vpc.x, vpc.y);
643
fprintf(prstream, "%.4f %.4f %.4f %.4f %d %d EARC c\n",
644
vpc.x, vpc.y, rx, ry, a1, a2);
646
/* fill bg first if the pattern != solid */
647
if (pen.pattern != 1 && ps_level2 == TRUE) {
648
fprintf(prstream, "GS\n");
649
if (ps_grayscale == TRUE) {
650
if (ps_pattern != 1) {
651
fprintf(prstream, "[/DeviceGray] SCS\n");
653
fprintf(prstream, "Color%d SGRY\n", getbgcolor());
655
if (ps_pattern != 1) {
656
fprintf(prstream, "[/DeviceRGB] SCS\n");
658
fprintf(prstream, "Color%d SRGB\n", getbgcolor());
660
fprintf(prstream, "fill\n");
661
fprintf(prstream, "GR\n");
665
fprintf(prstream, "fill\n");
668
void ps_putpixmap(VPoint vp, int width, int height,
669
char *databits, int pixmap_bpp, int bitmap_pad, int pixmap_type)
676
unsigned char tmpbyte;
681
fprintf(prstream, "GS\n");
682
fprintf(prstream, "%.4f %.4f translate\n", vp.x, vp.y);
683
fprintf(prstream, "%.4f %.4f scale\n", (float) width/page_scale,
684
(float) height/page_scale);
685
if (pixmap_bpp != 1) {
686
if (pixmap_type == PIXMAP_TRANSPARENT) {
689
if (ps_grayscale == TRUE) {
690
fprintf(prstream, "/picstr %d string def\n", width);
691
fprintf(prstream, "%d %d %d\n", width, height, 8);
693
fprintf(prstream, "/picstr %d string def\n", 3*width);
694
fprintf(prstream, "%d %d %d\n", width, height, GRACE_BPP);
696
fprintf(prstream, "[%d 0 0 %d 0 0]\n", width, -height);
697
fprintf(prstream, "{currentfile picstr readhexstring pop}\n");
698
if (ps_grayscale == TRUE || ps_level2 == FALSE) {
699
/* No color images in Level1 */
700
fprintf(prstream, "image\n");
702
fprintf(prstream, "false 3\n");
703
fprintf(prstream, "colorimage\n");
705
for (k = 0; k < height; k++) {
707
for (j = 0; j < width; j++) {
708
cindex = (databits)[k*width+j];
709
if (ps_grayscale == TRUE || ps_level2 == FALSE) {
710
linelen += fprintf(prstream,"%02x",
711
(int) (255*get_colorintensity(cindex)));
713
rgb = get_rgb(cindex);
714
linelen += fprintf(prstream, "%02x%02x%02x",
715
rgb->red, rgb->green, rgb->blue);
717
if (linelen >= MAX_PS_LINELEN) {
718
fprintf(prstream, "\n");
722
fprintf(prstream, "\n");
724
} else { /* monocolor bitmap */
725
paddedW = PAD(width, bitmap_pad);
726
if (pixmap_type == PIXMAP_OPAQUE) {
727
if (ps_grayscale == TRUE) {
728
fprintf(prstream,"%.4f SGRY\n",
729
get_colorintensity(getbgcolor()));
731
frgb = get_frgb(getbgcolor());
732
fprintf(prstream,"%.4f %.4f %.4f SRGB\n",
733
frgb->red, frgb->green, frgb->blue);
735
fprintf(prstream, "0 0 1 -1 rectfill\n");
737
if (ps_grayscale == TRUE) {
738
fprintf(prstream,"%.4f SGRY\n", get_colorintensity(getcolor()));
740
frgb = get_frgb(getcolor());
741
fprintf(prstream,"%.4f %.4f %.4f SRGB\n",
742
frgb->red, frgb->green, frgb->blue);
744
fprintf(prstream, "/picstr %d string def\n", paddedW/8);
745
fprintf(prstream, "%d %d true\n", paddedW, height);
746
fprintf(prstream, "[%d 0 0 %d 0 0]\n", paddedW, -height);
747
fprintf(prstream, "{currentfile picstr readhexstring pop}\n");
748
fprintf(prstream, "imagemask\n");
749
for (k = 0; k < height; k++) {
751
for (j = 0; j < paddedW/bitmap_pad; j++) {
752
tmpbyte = reversebits((unsigned char) (databits)[k*paddedW/bitmap_pad + j]);
753
linelen += fprintf(prstream, "%02x", tmpbyte);
754
if (linelen >= MAX_PS_LINELEN) {
755
fprintf(prstream, "\n");
759
fprintf(prstream, "\n");
762
fprintf(prstream, "GR\n");
765
void ps_puttext(VPoint vp, char *s, int len, int font,
766
TextMatrix *tm, int underline, int overline, int kerning)
774
if (psfont_status[font] == FALSE) {
775
fontname = get_fontalias(font);
776
encscheme = get_encodingscheme(font);
777
fprintf(prstream, "/%s findfont\n", fontname);
778
if (strcmp(encscheme, "FontSpecific") != 0) {
779
fprintf(prstream, "dup length dict begin\n");
780
fprintf(prstream, " {1 index /FID ne {def} {pop pop} ifelse} forall\n");
781
fprintf(prstream, " /Encoding DefEncoding def\n");
782
fprintf(prstream, " currentdict\n");
783
fprintf(prstream, "end\n");
785
fprintf(prstream, "/Font%d exch definefont pop\n", font);
786
psfont_status[font] = TRUE;
788
fprintf(prstream, "/Font%d FFSF\n", font);
792
fprintf(prstream, "%.4f %.4f m\n", vp.x, vp.y);
793
fprintf(prstream, "GS\n");
794
fprintf(prstream, "[%.4f %.4f %.4f %.4f 0 0] CC\n",
795
tm->cxx, tm->cyx, tm->cxy, tm->cyy);
798
kvector = get_kerning_vector(s, len, font);
805
linelen += fprintf(prstream, "[");
806
for (i = 0; i < len - 1; i++) {
807
linelen += fprintf(prstream, "%.4f ", kvector[i]);
808
if (linelen >= MAX_PS_LINELEN) {
809
fprintf(prstream, "\n");
813
fprintf(prstream, "] KINIT\n");
814
fprintf(prstream, "{KPROC}\n");
817
put_string(prstream, s, len);
819
if (underline | overline) {
820
double w, pos, kcomp;
823
kcomp = kvector[len - 1];
827
w = get_textline_width(font);
829
pos = get_underline_pos(font);
830
fprintf(prstream, " %.4f %.4f %.4f TL", pos, w, kcomp);
833
pos = get_overline_pos(font);
834
fprintf(prstream, " %.4f %.4f %.4f TL", pos, w, kcomp);
839
fprintf(prstream, " kshow\n");
842
fprintf(prstream, " show\n");
845
fprintf(prstream, "GR\n");
849
void ps_leavegraphics(void)
854
if (curformat == PS_FORMAT) {
855
fprintf(prstream, "showpage\n");
856
fprintf(prstream, "%%%%PageTrailer\n");
858
fprintf(prstream, "%%%%Trailer\n");
860
if (tight_bb == TRUE) {
861
v = get_bbox(BBOX_TYPE_GLOB);
862
if (page_orientation == PAGE_ORIENT_LANDSCAPE) {
863
fprintf(prstream, "%%%%BoundingBox: %d %d %d %d\n",
864
(int) (page_scalef*(1.0 - v.yv2)) - 1,
865
(int) (page_scalef*v.xv1) - 1,
866
(int) (page_scalef*(1.0 - v.yv1)) + 2,
867
(int) (page_scalef*v.xv2) + 2);
869
fprintf(prstream, "%%%%BoundingBox: %d %d %d %d\n",
870
(int) (page_scalef*v.xv1) - 1,
871
(int) (page_scalef*v.yv1) - 1,
872
(int) (page_scalef*v.xv2) + 2,
873
(int) (page_scalef*v.yv2) + 2);
878
for (i = 0; i < number_of_fonts(); i++) {
879
if (psfont_status[i] == TRUE) {
881
fprintf(prstream, "%%%%DocumentNeededResources: font %s\n",
885
fprintf(prstream, "%%%%+ font %s\n", get_fontalias(i));
890
fprintf(prstream, "%%%%EOF\n");
893
static int is7bit(unsigned char uc)
895
if (uc >= 0x1b && uc <= 0x7e) {
902
static int is8bit(unsigned char uc)
904
if (is7bit(uc) || uc >= 0x80) {
912
* Put a NOT NULL-terminated string escaping parentheses and backslashes
914
static void put_string(FILE *fp, char *s, int len)
920
for (i = 0; i < len; i++) {
922
unsigned char uc = (unsigned char) c;
923
if (c == '(' || c == ')' || c == '\\') {
927
if ((docdata == DOCDATA_7BIT && !is7bit(uc)) ||
928
(docdata == DOCDATA_8BIT && !is8bit(uc))) {
929
linelen += fprintf(fp, "\\%03o", uc);
934
if (linelen >= MAX_PS_LINELEN) {
935
fprintf(prstream, "\\\n");
942
int psprintinitgraphics(void)
946
ps_grayscale = ps_setup_grayscale;
947
ps_level2 = ps_setup_level2;
948
docdata = ps_setup_docdata;
949
result = ps_initgraphics(PS_FORMAT);
951
if (result == RETURN_SUCCESS) {
952
curformat = PS_FORMAT;
958
int epsinitgraphics(void)
962
ps_grayscale = eps_setup_grayscale;
963
ps_level2 = eps_setup_level2;
964
docdata = eps_setup_docdata;
965
result = ps_initgraphics(EPS_FORMAT);
967
if (result == RETURN_SUCCESS) {
968
curformat = EPS_FORMAT;
974
int ps_op_parser(char *opstring)
976
if (!strcmp(opstring, "grayscale")) {
977
ps_setup_grayscale = TRUE;
978
return RETURN_SUCCESS;
979
} else if (!strcmp(opstring, "color")) {
980
ps_setup_grayscale = FALSE;
981
return RETURN_SUCCESS;
982
} else if (!strcmp(opstring, "level2")) {
983
ps_setup_level2 = TRUE;
984
return RETURN_SUCCESS;
985
} else if (!strcmp(opstring, "level1")) {
986
ps_setup_level2 = FALSE;
987
return RETURN_SUCCESS;
988
} else if (!strcmp(opstring, "docdata:7bit")) {
989
ps_setup_docdata = DOCDATA_7BIT;
990
return RETURN_SUCCESS;
991
} else if (!strcmp(opstring, "docdata:8bit")) {
992
ps_setup_docdata = DOCDATA_8BIT;
993
return RETURN_SUCCESS;
994
} else if (!strcmp(opstring, "docdata:binary")) {
995
ps_setup_docdata = DOCDATA_BINARY;
996
return RETURN_SUCCESS;
997
} else if (!strncmp(opstring, "xoffset:", 8)) {
998
ps_setup_offset_x = atoi(opstring + 8);
999
return RETURN_SUCCESS;
1000
} else if (!strncmp(opstring, "yoffset:", 8)) {
1001
ps_setup_offset_y = atoi(opstring + 8);
1002
return RETURN_SUCCESS;
1003
} else if (!strcmp(opstring, "hwresolution:on")) {
1004
ps_setup_hwres = TRUE;
1005
return RETURN_SUCCESS;
1006
} else if (!strcmp(opstring, "hwresolution:off")) {
1007
ps_setup_hwres = FALSE;
1008
return RETURN_SUCCESS;
1009
} else if (!strcmp(opstring, "mediafeed:auto")) {
1010
ps_setup_feed = MEDIA_FEED_AUTO;
1011
return RETURN_SUCCESS;
1012
} else if (!strcmp(opstring, "mediafeed:match")) {
1013
ps_setup_feed = MEDIA_FEED_MATCH;
1014
return RETURN_SUCCESS;
1015
} else if (!strcmp(opstring, "mediafeed:manual")) {
1016
ps_setup_feed = MEDIA_FEED_MANUAL;
1017
return RETURN_SUCCESS;
1019
return RETURN_FAILURE;
1023
int eps_op_parser(char *opstring)
1025
if (!strcmp(opstring, "grayscale")) {
1026
eps_setup_grayscale = TRUE;
1027
return RETURN_SUCCESS;
1028
} else if (!strcmp(opstring, "color")) {
1029
eps_setup_grayscale = FALSE;
1030
return RETURN_SUCCESS;
1031
} else if (!strcmp(opstring, "level2")) {
1032
eps_setup_level2 = TRUE;
1033
return RETURN_SUCCESS;
1034
} else if (!strcmp(opstring, "level1")) {
1035
eps_setup_level2 = FALSE;
1036
return RETURN_SUCCESS;
1037
} else if (!strcmp(opstring, "docdata:7bit")) {
1038
eps_setup_docdata = DOCDATA_7BIT;
1039
return RETURN_SUCCESS;
1040
} else if (!strcmp(opstring, "docdata:8bit")) {
1041
eps_setup_docdata = DOCDATA_8BIT;
1042
return RETURN_SUCCESS;
1043
} else if (!strcmp(opstring, "docdata:binary")) {
1044
eps_setup_docdata = DOCDATA_BINARY;
1045
return RETURN_SUCCESS;
1046
} else if (!strcmp(opstring, "bbox:tight")) {
1047
eps_setup_tight_bb = TRUE;
1048
return RETURN_SUCCESS;
1049
} else if (!strcmp(opstring, "bbox:page")) {
1050
eps_setup_tight_bb = FALSE;
1051
return RETURN_SUCCESS;
1053
return RETURN_FAILURE;
1059
static void update_ps_setup_frame(void);
1060
static int set_ps_setup_proc(void *data);
1062
static Widget ps_setup_frame;
1063
static Widget ps_setup_grayscale_item;
1064
static Widget ps_setup_level2_item;
1065
static SpinStructure *ps_setup_offset_x_item;
1066
static SpinStructure *ps_setup_offset_y_item;
1067
static OptionStructure *ps_setup_feed_item;
1068
static Widget ps_setup_hwres_item;
1069
static OptionStructure *ps_setup_docdata_item;
1071
void ps_gui_setup(void)
1075
if (ps_setup_frame == NULL) {
1076
Widget ps_setup_rc, fr, rc;
1077
OptionItem op_items[3] = {
1078
{MEDIA_FEED_AUTO, "Automatic" },
1079
{MEDIA_FEED_MATCH, "Match size"},
1080
{MEDIA_FEED_MANUAL, "Manual" }
1082
OptionItem docdata_op_items[3] = {
1083
{DOCDATA_7BIT, "7bit" },
1084
{DOCDATA_8BIT, "8bit"},
1085
{DOCDATA_BINARY, "Binary" }
1088
ps_setup_frame = CreateDialogForm(app_shell, "PS options");
1090
ps_setup_rc = CreateVContainer(ps_setup_frame);
1092
fr = CreateFrame(ps_setup_rc, "PS options");
1093
rc = CreateVContainer(fr);
1094
ps_setup_grayscale_item = CreateToggleButton(rc, "Grayscale output");
1095
ps_setup_level2_item = CreateToggleButton(rc, "PS Level 2");
1096
ps_setup_docdata_item =
1097
CreateOptionChoice(rc, "Document data:", 1, 3, docdata_op_items);
1099
fr = CreateFrame(ps_setup_rc, "Page offsets (pt)");
1100
rc = CreateHContainer(fr);
1101
ps_setup_offset_x_item = CreateSpinChoice(rc,
1102
"X: ", 4, SPIN_TYPE_INT, -999.0, 999.0, 10.0);
1103
ps_setup_offset_y_item = CreateSpinChoice(rc,
1104
"Y: ", 4, SPIN_TYPE_INT, -999.0, 999.0, 10.0);
1106
fr = CreateFrame(ps_setup_rc, "Hardware");
1107
rc = CreateVContainer(fr);
1108
ps_setup_feed_item = CreateOptionChoice(rc, "Media feed:", 1, 3, op_items);
1109
ps_setup_hwres_item = CreateToggleButton(rc, "Set hardware resolution");
1111
CreateAACDialog(ps_setup_frame, ps_setup_rc, set_ps_setup_proc, NULL);
1113
update_ps_setup_frame();
1115
RaiseWindow(GetParent(ps_setup_frame));
1116
unset_wait_cursor();
1119
static void update_ps_setup_frame(void)
1121
if (ps_setup_frame) {
1122
SetToggleButtonState(ps_setup_grayscale_item, ps_setup_grayscale);
1123
SetToggleButtonState(ps_setup_level2_item, ps_setup_level2);
1124
SetSpinChoice(ps_setup_offset_x_item, (double) ps_setup_offset_x);
1125
SetSpinChoice(ps_setup_offset_y_item, (double) ps_setup_offset_y);
1126
SetOptionChoice(ps_setup_feed_item, ps_setup_feed);
1127
SetToggleButtonState(ps_setup_hwres_item, ps_setup_hwres);
1128
SetOptionChoice(ps_setup_docdata_item, ps_setup_docdata);
1132
static int set_ps_setup_proc(void *data)
1134
ps_setup_grayscale = GetToggleButtonState(ps_setup_grayscale_item);
1135
ps_setup_level2 = GetToggleButtonState(ps_setup_level2_item);
1136
ps_setup_offset_x = (int) GetSpinChoice(ps_setup_offset_x_item);
1137
ps_setup_offset_y = (int) GetSpinChoice(ps_setup_offset_y_item);
1138
ps_setup_feed = GetOptionChoice(ps_setup_feed_item);
1139
ps_setup_hwres = GetToggleButtonState(ps_setup_hwres_item);
1140
ps_setup_docdata = GetOptionChoice(ps_setup_docdata_item);
1142
return RETURN_SUCCESS;
1145
static void update_eps_setup_frame(void);
1146
static int set_eps_setup_proc(void *data);
1147
static Widget eps_setup_frame;
1148
static Widget eps_setup_grayscale_item;
1149
static Widget eps_setup_level2_item;
1150
static Widget eps_setup_tight_bb_item;
1151
static OptionStructure *eps_setup_docdata_item;
1153
void eps_gui_setup(void)
1157
if (eps_setup_frame == NULL) {
1159
OptionItem docdata_op_items[3] = {
1160
{DOCDATA_7BIT, "7bit" },
1161
{DOCDATA_8BIT, "8bit"},
1162
{DOCDATA_BINARY, "Binary" }
1165
eps_setup_frame = CreateDialogForm(app_shell, "EPS options");
1167
fr = CreateFrame(eps_setup_frame, "EPS options");
1168
rc = CreateVContainer(fr);
1169
eps_setup_grayscale_item = CreateToggleButton(rc, "Grayscale output");
1170
eps_setup_level2_item = CreateToggleButton(rc, "PS Level 2");
1171
eps_setup_tight_bb_item = CreateToggleButton(rc, "Tight BBox");
1172
eps_setup_docdata_item =
1173
CreateOptionChoice(rc, "Document data:", 1, 3, docdata_op_items);
1174
CreateAACDialog(eps_setup_frame, fr, set_eps_setup_proc, NULL);
1176
update_eps_setup_frame();
1177
RaiseWindow(GetParent(eps_setup_frame));
1179
unset_wait_cursor();
1182
static void update_eps_setup_frame(void)
1184
if (eps_setup_frame) {
1185
SetToggleButtonState(eps_setup_grayscale_item, eps_setup_grayscale);
1186
SetToggleButtonState(eps_setup_level2_item, eps_setup_level2);
1187
SetToggleButtonState(eps_setup_tight_bb_item, eps_setup_tight_bb);
1188
SetOptionChoice(eps_setup_docdata_item, eps_setup_docdata);
1192
static int set_eps_setup_proc(void *data)
1194
eps_setup_grayscale = GetToggleButtonState(eps_setup_grayscale_item);
1195
eps_setup_level2 = GetToggleButtonState(eps_setup_level2_item);
1196
eps_setup_tight_bb = GetToggleButtonState(eps_setup_tight_bb_item);
1197
eps_setup_docdata = GetOptionChoice(eps_setup_docdata_item);
1199
return RETURN_SUCCESS;