~ubuntu-branches/ubuntu/karmic/grace/karmic

« back to all changes in this revision

Viewing changes to src/psdrv.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-19 14:19:58 UTC
  • Revision ID: james.westby@ubuntu.com-20020319141958-5gxna6vo1ek3zjml
Tags: upstream-5.1.7
ImportĀ upstreamĀ versionĀ 5.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Grace - GRaphing, Advanced Computation and Exploration of data
 
3
 * 
 
4
 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
 
5
 * 
 
6
 * Copyright (c) 1991-1995 Paul J Turner, Portland, OR
 
7
 * Copyright (c) 1996-2002 Grace Development Team
 
8
 * 
 
9
 * Maintained by Evgeny Stambulchik <fnevgeny@plasma-gate.weizmann.ac.il>
 
10
 * 
 
11
 * 
 
12
 *                           All Rights Reserved
 
13
 * 
 
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.
 
18
 * 
 
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.
 
23
 * 
 
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.
 
27
 */
 
28
 
 
29
/*
 
30
 *  GRACE PostScript driver
 
31
 */
 
32
 
 
33
#include <config.h>
 
34
#include <cmath.h>
 
35
 
 
36
#include <stdio.h>
 
37
#include <unistd.h>
 
38
#include <stdlib.h>
 
39
#include <string.h>
 
40
#include <time.h>
 
41
 
 
42
#include "defines.h"
 
43
#include "utils.h"
 
44
#include "draw.h"
 
45
#include "device.h"
 
46
#include "devlist.h"
 
47
#include "patterns.h"
 
48
#include "psdrv.h"
 
49
#include "protos.h"
 
50
 
 
51
#ifndef NONE_GUI
 
52
#  include "motifinc.h"
 
53
#endif
 
54
 
 
55
extern FILE *prstream;
 
56
 
 
57
static void put_string(FILE *fp, char *s, int len);
 
58
 
 
59
static int curformat = DEFAULT_PS_FORMAT;
 
60
 
 
61
static unsigned long page_scale;
 
62
static double pixel_size;
 
63
static float page_scalef;
 
64
static int page_orientation;
 
65
 
 
66
static int *psfont_status = NULL;
 
67
 
 
68
static int ps_color;
 
69
static int ps_pattern;
 
70
static double ps_linew;
 
71
static int ps_lines;
 
72
static int ps_linecap;
 
73
static int ps_linejoin;
 
74
 
 
75
static int ps_grayscale = FALSE;
 
76
static int ps_level2 = TRUE;
 
77
static int docdata = DOCDATA_8BIT;
 
78
 
 
79
static int ps_setup_offset_x = 0;
 
80
static int ps_setup_offset_y = 0;
 
81
 
 
82
static int ps_setup_grayscale = FALSE;
 
83
static int ps_setup_level2 = TRUE;
 
84
static int ps_setup_docdata = DOCDATA_8BIT;
 
85
 
 
86
static int ps_setup_feed = MEDIA_FEED_AUTO;
 
87
static int ps_setup_hwres = FALSE;
 
88
 
 
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;
 
93
 
 
94
static int tight_bb;
 
95
 
 
96
static Device_entry dev_ps = {DEVICE_PRINT,
 
97
          "PostScript",
 
98
          psprintinitgraphics,
 
99
          ps_op_parser,
 
100
          ps_gui_setup,
 
101
          "ps",
 
102
          TRUE,
 
103
          FALSE,
 
104
          {3300, 2550, 300.0},
 
105
          NULL
 
106
         };
 
107
 
 
108
static Device_entry dev_eps = {DEVICE_FILE,
 
109
          "EPS",
 
110
          epsinitgraphics,
 
111
          eps_op_parser,
 
112
          eps_gui_setup,
 
113
          "eps",
 
114
          TRUE,
 
115
          FALSE,
 
116
          {2500, 2500, 300.0},
 
117
          NULL
 
118
         };
 
119
 
 
120
int register_ps_drv(void)
 
121
{
 
122
    return register_device(dev_ps);
 
123
}
 
124
 
 
125
int register_eps_drv(void)
 
126
{
 
127
    return register_device(dev_eps);
 
128
}
 
129
 
 
130
static int ps_initgraphics(int format)
 
131
{
 
132
    int i, j;
 
133
    Page_geometry pg;
 
134
    fRGB *frgb;
 
135
    int width_pp, height_pp, page_offset_x, page_offset_y;
 
136
    char **enc;
 
137
    
 
138
    time_t time_value;
 
139
    
 
140
    curformat = format;
 
141
    
 
142
    /* device-dependent routines */
 
143
    devupdatecmap = NULL;
 
144
    
 
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;
 
152
    
 
153
    devleavegraphics = ps_leavegraphics;
 
154
 
 
155
    pg = get_page_geometry();
 
156
    
 
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;
 
160
 
 
161
    if (curformat == PS_FORMAT && pg.height < pg.width) {
 
162
        page_orientation = PAGE_ORIENT_LANDSCAPE;
 
163
    } else {
 
164
        page_orientation = PAGE_ORIENT_PORTRAIT;
 
165
    }
 
166
    
 
167
    /* undefine all graphics state parameters */
 
168
    ps_color = -1;
 
169
    ps_pattern = -1;
 
170
    ps_linew = -1.0;
 
171
    ps_lines = -1;
 
172
    ps_linecap = -1;
 
173
    ps_linejoin = -1;
 
174
 
 
175
    /* Font status table */
 
176
    if (psfont_status != NULL) {
 
177
        xfree(psfont_status);
 
178
    }
 
179
    psfont_status = xmalloc(number_of_fonts()*SIZEOF_INT);
 
180
    for (i = 0; i < number_of_fonts(); i++) {
 
181
        psfont_status[i] = FALSE;
 
182
    }
 
183
    
 
184
    switch (curformat) {
 
185
    case PS_FORMAT:
 
186
        fprintf(prstream, "%%!PS-Adobe-3.0\n");
 
187
        tight_bb = FALSE;
 
188
        page_offset_x = ps_setup_offset_x;
 
189
        page_offset_y = ps_setup_offset_y;
 
190
        break;
 
191
    case EPS_FORMAT:
 
192
        fprintf(prstream, "%%!PS-Adobe-3.0 EPSF-3.0\n");
 
193
        tight_bb = eps_setup_tight_bb;
 
194
        page_offset_x = 0;
 
195
        page_offset_y = 0;
 
196
        break;
 
197
    default:
 
198
        errmsg("Invalid PS format");
 
199
        return RETURN_FAILURE;
 
200
    }
 
201
    
 
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);
 
205
    } else {
 
206
        width_pp  = (int) rint(72.0*pg.width/pg.dpi);
 
207
        height_pp = (int) rint(72.0*pg.height/pg.dpi);
 
208
    }
 
209
    
 
210
    if (tight_bb == TRUE) {
 
211
        fprintf(prstream, "%%%%BoundingBox: (atend)\n");
 
212
    } else {
 
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);
 
216
    }
 
217
    
 
218
    if (ps_level2 == TRUE) {
 
219
        fprintf(prstream, "%%%%LanguageLevel: 2\n");
 
220
    } else {
 
221
        fprintf(prstream, "%%%%LanguageLevel: 1\n");
 
222
    }
 
223
    
 
224
    fprintf(prstream, "%%%%Creator: %s\n", bi_version_string());
 
225
 
 
226
    time(&time_value);
 
227
    fprintf(prstream, "%%%%CreationDate: %s", ctime(&time_value));
 
228
    switch (docdata) {
 
229
    case DOCDATA_7BIT:
 
230
        fprintf(prstream, "%%%%DocumentData: Clean7Bit\n");
 
231
        break;
 
232
    case DOCDATA_8BIT:
 
233
        fprintf(prstream, "%%%%DocumentData: Clean8Bit\n");
 
234
        break;
 
235
    default:
 
236
        fprintf(prstream, "%%%%DocumentData: Binary\n");
 
237
        break;
 
238
    }
 
239
    if (page_orientation == PAGE_ORIENT_LANDSCAPE) {
 
240
        fprintf(prstream, "%%%%Orientation: Landscape\n");
 
241
    } else {
 
242
        fprintf(prstream, "%%%%Orientation: Portrait\n");
 
243
    }
 
244
    
 
245
    if (curformat == PS_FORMAT) {
 
246
        fprintf(prstream, "%%%%Pages: 1\n");
 
247
        fprintf(prstream, "%%%%PageOrder: Ascend\n");
 
248
    }
 
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");
 
253
 
 
254
    /* Definitions */
 
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);
 
259
    }
 
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");
 
279
    
 
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));
 
284
        } else {
 
285
            frgb = get_frgb(i);
 
286
            if (frgb != NULL) {
 
287
                fprintf(prstream, "%.4f %.4f %.4f",
 
288
                                    frgb->red,frgb->green, frgb->blue);
 
289
            }
 
290
        }
 
291
        fprintf(prstream,"} def\n");
 
292
    }
 
293
       
 
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]);
 
314
            }
 
315
            fprintf(prstream, "> PTRN} bind def\n");
 
316
        }
 
317
    }
 
318
    
 
319
    /* Elliptic arc */
 
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");
 
337
 
 
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");
 
349
 
 
350
    /* Kerning stuff */
 
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");
 
363
 
 
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]);
 
369
    }
 
370
    fprintf(prstream, "] def\n");
 
371
 
 
372
    fprintf(prstream, "%%%%EndProlog\n");
 
373
 
 
374
    fprintf(prstream, "%%%%BeginSetup\n");
 
375
    if (ps_level2 == TRUE && curformat == PS_FORMAT) {
 
376
        /* page size feed */
 
377
        switch (ps_setup_feed) {
 
378
        case MEDIA_FEED_AUTO:
 
379
            break;
 
380
        case MEDIA_FEED_MATCH:
 
381
            fprintf(prstream, "%%%%BeginFeature: *PageSize\n");
 
382
            fprintf(prstream,
 
383
                "<</PageSize [%d %d] /ImagingBBox null>> setpagedevice\n",
 
384
                width_pp, height_pp);
 
385
            fprintf(prstream, "%%%%EndFeature\n");
 
386
            break;
 
387
        case MEDIA_FEED_MANUAL:
 
388
            fprintf(prstream, "%%%%BeginFeature: *ManualFeed\n");
 
389
            fprintf(prstream, "<</ManualFeed true>> setpagedevice\n");
 
390
            fprintf(prstream, "%%%%EndFeature\n");
 
391
            break;
 
392
        }
 
393
        
 
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");
 
400
        }
 
401
    }
 
402
    
 
403
    /* compensate for printer page offsets */
 
404
    if (curformat == PS_FORMAT) {
 
405
        fprintf(prstream, "PAGE_OFFSET_X PAGE_OFFSET_Y translate\n");
 
406
    }
 
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");
 
412
    }
 
413
    fprintf(prstream, "%%%%EndSetup\n");
 
414
 
 
415
    if (curformat == PS_FORMAT) {
 
416
        fprintf(prstream, "%%%%Page: 1 1\n");
 
417
    }
 
418
 
 
419
    return RETURN_SUCCESS;
 
420
}
 
421
 
 
422
void ps_setpen(void)
 
423
{
 
424
    Pen pen;
 
425
    
 
426
    pen = getpen();
 
427
    
 
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");
 
433
                } else {
 
434
                    fprintf(prstream, "[/DeviceRGB] SCS\n");
 
435
                }
 
436
                fprintf(prstream, "Color%d SC\n", pen.color);
 
437
            } else {
 
438
                if (ps_grayscale == TRUE) {
 
439
                    fprintf(prstream, "[/Pattern /DeviceGray] SCS\n");
 
440
                } else {
 
441
                    fprintf(prstream, "[/Pattern /DeviceRGB] SCS\n");
 
442
                }
 
443
                fprintf(prstream,
 
444
                    "Color%d Pattern%d SC\n", pen.color, pen.pattern);
 
445
            }
 
446
        } else {
 
447
            if (ps_grayscale == TRUE) {
 
448
                fprintf(prstream, "Color%d SGRY\n", pen.color);
 
449
            } else {
 
450
                fprintf(prstream, "Color%d SRGB\n", pen.color);
 
451
            }
 
452
        }
 
453
        ps_color = pen.color;
 
454
        ps_pattern = pen.pattern;
 
455
    }
 
456
}
 
457
 
 
458
void ps_setdrawbrush(void)
 
459
{
 
460
    int i;
 
461
    int ls;
 
462
    double lw;
 
463
    
 
464
    ps_setpen();
 
465
 
 
466
    ls = getlinestyle();
 
467
    lw = MAX2(getlinewidth(), pixel_size);
 
468
    
 
469
    if (ls != ps_lines || lw != ps_linew) {    
 
470
        fprintf(prstream, "[");
 
471
        if (ls > 1) {
 
472
            for (i = 0; i < dash_array_length[ls]; i++) {
 
473
                fprintf(prstream, "%.4f ", lw*dash_array[ls][i]);
 
474
            }
 
475
        }
 
476
        fprintf(prstream, "] 0 SD\n");
 
477
        fprintf(prstream, "%.4f SLW\n", lw);
 
478
        ps_linew = lw;
 
479
        ps_lines = ls;
 
480
    }
 
481
}
 
482
 
 
483
void ps_setlineprops(void)
 
484
{
 
485
    int lc, lj;
 
486
    
 
487
    lc = getlinecap();
 
488
    lj = getlinejoin();
 
489
    
 
490
    if (lc != ps_linecap) {
 
491
        switch (lc) {
 
492
        case LINECAP_BUTT:
 
493
            fprintf(prstream, "0 SLC\n");
 
494
            break;
 
495
        case LINECAP_ROUND:
 
496
            fprintf(prstream, "1 SLC\n");
 
497
            break;
 
498
        case LINECAP_PROJ:
 
499
            fprintf(prstream, "2 SLC\n");
 
500
            break;
 
501
        }
 
502
        ps_linecap = lc;
 
503
    }
 
504
 
 
505
    if (lj != ps_linejoin) {
 
506
        switch (lj) {
 
507
        case LINEJOIN_MITER:
 
508
            fprintf(prstream, "0 SLJ\n");
 
509
            break;
 
510
        case LINEJOIN_ROUND:
 
511
            fprintf(prstream, "1 SLJ\n");
 
512
            break;
 
513
        case LINEJOIN_BEVEL:
 
514
            fprintf(prstream, "2 SLJ\n");
 
515
            break;
 
516
        }
 
517
        ps_linejoin = lj;
 
518
    }
 
519
}
 
520
 
 
521
void ps_drawpixel(VPoint vp)
 
522
{
 
523
    ps_setpen();
 
524
    
 
525
    if (ps_linew != pixel_size) {
 
526
        fprintf(prstream, "%.4f SLW\n", pixel_size);
 
527
        ps_linew = pixel_size;
 
528
    }
 
529
    if (ps_linecap != LINECAP_ROUND) {
 
530
        fprintf(prstream, "1 SLC\n");
 
531
        ps_linecap = LINECAP_ROUND;
 
532
    }
 
533
    if (ps_lines != 1) {
 
534
        fprintf(prstream, "[] 0 SD\n");
 
535
        ps_lines = 1;
 
536
    }
 
537
    
 
538
    fprintf(prstream, "%.4f %.4f PXL\n", vp.x, vp.y);
 
539
}
 
540
 
 
541
void ps_drawpolyline(VPoint *vps, int n, int mode)
 
542
{
 
543
    int i;
 
544
    
 
545
    ps_setdrawbrush();
 
546
    
 
547
    ps_setlineprops();
 
548
    
 
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);
 
553
    }
 
554
    if (mode == POLYLINE_CLOSED) {
 
555
        fprintf(prstream, "%.4f %.4f l\n", vps[0].x, vps[0].y);
 
556
        fprintf(prstream, "c\n");
 
557
    }
 
558
    fprintf(prstream, "s\n");
 
559
}
 
560
 
 
561
void ps_fillpolygon(VPoint *vps, int nc)
 
562
{
 
563
    int i;
 
564
    Pen pen = getpen();
 
565
    
 
566
    if (pen.pattern == 0 || nc < 3) {
 
567
        return;
 
568
    }
 
569
    
 
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);
 
574
    }
 
575
    fprintf(prstream, "c\n");
 
576
 
 
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");
 
583
            }
 
584
            fprintf(prstream, "Color%d SGRY\n", getbgcolor());
 
585
        } else {
 
586
            if (ps_pattern != 1) {
 
587
                fprintf(prstream, "[/DeviceRGB] SCS\n");
 
588
            }
 
589
            fprintf(prstream, "Color%d SRGB\n", getbgcolor());
 
590
        }
 
591
        if (getfillrule() == FILLRULE_WINDING) {
 
592
            fprintf(prstream, "fill\n");
 
593
        } else {
 
594
            fprintf(prstream, "eofill\n");
 
595
        }
 
596
        fprintf(prstream, "GR\n");
 
597
    }
 
598
    
 
599
    ps_setpen();
 
600
    if (getfillrule() == FILLRULE_WINDING) {
 
601
        fprintf(prstream, "fill\n");
 
602
    } else {
 
603
        fprintf(prstream, "eofill\n");
 
604
    }
 
605
}
 
606
 
 
607
void ps_drawarc(VPoint vp1, VPoint vp2, int a1, int a2)
 
608
{
 
609
    VPoint vpc;
 
610
    double rx, ry;
 
611
    
 
612
    ps_setdrawbrush();
 
613
 
 
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;
 
618
    
 
619
    fprintf(prstream, "n %.4f %.4f %.4f %.4f %d %d EARC s\n",
 
620
                       vpc.x, vpc.y, rx, ry, a1, a2);
 
621
}
 
622
 
 
623
void ps_fillarc(VPoint vp1, VPoint vp2, int a1, int a2, int mode)
 
624
{
 
625
    VPoint vpc;
 
626
    double rx, ry;
 
627
    Pen pen = getpen();
 
628
    
 
629
    if (pen.pattern == 0) {
 
630
        return;
 
631
    }
 
632
 
 
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;
 
637
    
 
638
    fprintf(prstream, "n\n");
 
639
    
 
640
    if (mode == ARCFILL_PIESLICE) {
 
641
        fprintf(prstream, "%.4f %.4f m\n", vpc.x, vpc.y);
 
642
    }
 
643
    fprintf(prstream, "%.4f %.4f %.4f %.4f %d %d EARC c\n",
 
644
                       vpc.x, vpc.y, rx, ry, a1, a2);
 
645
 
 
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");
 
652
            }
 
653
            fprintf(prstream, "Color%d SGRY\n", getbgcolor());
 
654
        } else {
 
655
            if (ps_pattern != 1) {
 
656
                fprintf(prstream, "[/DeviceRGB] SCS\n");
 
657
            }
 
658
            fprintf(prstream, "Color%d SRGB\n", getbgcolor());
 
659
        }
 
660
        fprintf(prstream, "fill\n");
 
661
        fprintf(prstream, "GR\n");
 
662
    }
 
663
 
 
664
    ps_setpen();
 
665
    fprintf(prstream, "fill\n");
 
666
}
 
667
 
 
668
void ps_putpixmap(VPoint vp, int width, int height, 
 
669
     char *databits, int pixmap_bpp, int bitmap_pad, int pixmap_type)
 
670
{
 
671
    int j, k;
 
672
    int cindex;
 
673
    int paddedW;
 
674
    RGB *rgb;
 
675
    fRGB *frgb;
 
676
    unsigned char tmpbyte;
 
677
    int linelen;
 
678
 
 
679
    ps_setpen();
 
680
    
 
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) {
 
687
            /* TODO: mask */
 
688
        }
 
689
        if (ps_grayscale == TRUE) {
 
690
            fprintf(prstream, "/picstr %d string def\n", width);
 
691
            fprintf(prstream, "%d %d %d\n", width, height, 8);
 
692
        } else {
 
693
            fprintf(prstream, "/picstr %d string def\n", 3*width);
 
694
            fprintf(prstream, "%d %d %d\n", width, height, GRACE_BPP);
 
695
        }
 
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");
 
701
        } else {
 
702
            fprintf(prstream, "false 3\n");
 
703
            fprintf(prstream, "colorimage\n");
 
704
        }
 
705
        for (k = 0; k < height; k++) {
 
706
            linelen = 0;
 
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)));
 
712
                } else {
 
713
                    rgb = get_rgb(cindex);
 
714
                    linelen += fprintf(prstream, "%02x%02x%02x",
 
715
                                       rgb->red, rgb->green, rgb->blue);
 
716
                }
 
717
                if (linelen >= MAX_PS_LINELEN) {
 
718
                    fprintf(prstream, "\n");
 
719
                    linelen = 0;
 
720
                }
 
721
            }
 
722
            fprintf(prstream, "\n");
 
723
        }
 
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()));
 
730
            } else {
 
731
                frgb = get_frgb(getbgcolor());
 
732
                fprintf(prstream,"%.4f %.4f %.4f SRGB\n",
 
733
                                  frgb->red, frgb->green, frgb->blue);
 
734
            }
 
735
            fprintf(prstream, "0 0 1 -1 rectfill\n");
 
736
        }
 
737
        if (ps_grayscale == TRUE) {
 
738
            fprintf(prstream,"%.4f SGRY\n", get_colorintensity(getcolor()));
 
739
        } else {
 
740
            frgb = get_frgb(getcolor());
 
741
            fprintf(prstream,"%.4f %.4f %.4f SRGB\n",
 
742
                              frgb->red, frgb->green, frgb->blue);
 
743
        }
 
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++) {
 
750
            linelen = 0;
 
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");
 
756
                    linelen = 0;
 
757
                }
 
758
            }
 
759
            fprintf(prstream, "\n");
 
760
        }
 
761
    }
 
762
    fprintf(prstream, "GR\n");
 
763
}
 
764
 
 
765
void ps_puttext(VPoint vp, char *s, int len, int font,
 
766
     TextMatrix *tm, int underline, int overline, int kerning)
 
767
{
 
768
    char *fontname;
 
769
    char *encscheme;
 
770
    double *kvector;
 
771
    int i;
 
772
    int linelen;
 
773
    
 
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");
 
784
        }
 
785
        fprintf(prstream, "/Font%d exch definefont pop\n", font);
 
786
        psfont_status[font] = TRUE;
 
787
    }
 
788
    fprintf(prstream, "/Font%d FFSF\n", font);
 
789
 
 
790
    ps_setpen();
 
791
    
 
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);
 
796
    
 
797
    if (kerning) {
 
798
        kvector = get_kerning_vector(s, len, font);
 
799
    } else {
 
800
        kvector = NULL;
 
801
    }
 
802
    
 
803
    if (kvector) {
 
804
        linelen = 0;
 
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");
 
810
                linelen = 0;
 
811
            }
 
812
        }
 
813
        fprintf(prstream, "] KINIT\n");
 
814
        fprintf(prstream, "{KPROC}\n");
 
815
    }
 
816
    
 
817
    put_string(prstream, s, len);
 
818
 
 
819
    if (underline | overline) {
 
820
        double w, pos, kcomp;
 
821
        
 
822
        if (kvector) {
 
823
            kcomp = kvector[len - 1];
 
824
        } else {
 
825
            kcomp = 0.0;
 
826
        }
 
827
        w = get_textline_width(font);
 
828
        if (underline) {
 
829
            pos = get_underline_pos(font);
 
830
            fprintf(prstream, " %.4f %.4f %.4f TL", pos, w, kcomp);
 
831
        }
 
832
        if (overline) {
 
833
            pos = get_overline_pos(font);
 
834
            fprintf(prstream, " %.4f %.4f %.4f TL", pos, w, kcomp);
 
835
        }
 
836
    }
 
837
    
 
838
    if (kvector) {
 
839
        fprintf(prstream, " kshow\n");
 
840
        xfree(kvector);
 
841
    } else {
 
842
        fprintf(prstream, " show\n");
 
843
    }
 
844
    
 
845
    fprintf(prstream, "GR\n");
 
846
}
 
847
 
 
848
 
 
849
void ps_leavegraphics(void)
 
850
{
 
851
    view v;
 
852
    int i, first;
 
853
    
 
854
    if (curformat == PS_FORMAT) {
 
855
        fprintf(prstream, "showpage\n");
 
856
        fprintf(prstream, "%%%%PageTrailer\n");
 
857
    }
 
858
    fprintf(prstream, "%%%%Trailer\n");
 
859
    
 
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);
 
868
        } else {
 
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);
 
874
        }
 
875
    }
 
876
    
 
877
    first = TRUE;
 
878
    for (i = 0; i < number_of_fonts(); i++) {
 
879
        if (psfont_status[i] == TRUE) {
 
880
            if (first) {
 
881
                fprintf(prstream, "%%%%DocumentNeededResources: font %s\n",
 
882
                    get_fontalias(i));
 
883
                first = FALSE;
 
884
            } else {
 
885
                fprintf(prstream, "%%%%+ font %s\n", get_fontalias(i));
 
886
            }
 
887
        }
 
888
    }
 
889
 
 
890
    fprintf(prstream, "%%%%EOF\n");
 
891
}
 
892
 
 
893
static int is7bit(unsigned char uc)
 
894
{
 
895
    if (uc >= 0x1b && uc <= 0x7e) {
 
896
        return TRUE;
 
897
    } else {
 
898
        return FALSE;
 
899
    }
 
900
}
 
901
 
 
902
static int is8bit(unsigned char uc)
 
903
{
 
904
    if (is7bit(uc) || uc >= 0x80) {
 
905
        return TRUE;
 
906
    } else {
 
907
        return FALSE;
 
908
    }
 
909
}
 
910
 
 
911
/*
 
912
 * Put a NOT NULL-terminated string escaping parentheses and backslashes
 
913
 */
 
914
static void put_string(FILE *fp, char *s, int len)
 
915
{
 
916
    int i, linelen = 0;
 
917
    
 
918
    fputc('(', fp);
 
919
    linelen++;
 
920
    for (i = 0; i < len; i++) {
 
921
        char c = s[i];
 
922
        unsigned char uc = (unsigned char) c;
 
923
        if (c == '(' || c == ')' || c == '\\') {
 
924
            fputc('\\', fp);
 
925
            linelen++;
 
926
        }
 
927
        if ((docdata == DOCDATA_7BIT && !is7bit(uc)) ||
 
928
            (docdata == DOCDATA_8BIT && !is8bit(uc))) {
 
929
            linelen += fprintf(fp, "\\%03o", uc);
 
930
        } else {
 
931
            fputc(c, fp);
 
932
            linelen++;
 
933
        }
 
934
        if (linelen >= MAX_PS_LINELEN) {
 
935
            fprintf(prstream, "\\\n");
 
936
            linelen = 0;
 
937
        }
 
938
    }
 
939
    fputc(')', fp);
 
940
}
 
941
 
 
942
int psprintinitgraphics(void)
 
943
{
 
944
    int result;
 
945
    
 
946
    ps_grayscale = ps_setup_grayscale;
 
947
    ps_level2 = ps_setup_level2;
 
948
    docdata = ps_setup_docdata;
 
949
    result = ps_initgraphics(PS_FORMAT);
 
950
    
 
951
    if (result == RETURN_SUCCESS) {
 
952
        curformat = PS_FORMAT;
 
953
    }
 
954
    
 
955
    return (result);
 
956
}
 
957
 
 
958
int epsinitgraphics(void)
 
959
{
 
960
    int result;
 
961
    
 
962
    ps_grayscale = eps_setup_grayscale;
 
963
    ps_level2 = eps_setup_level2;
 
964
    docdata = eps_setup_docdata;
 
965
    result = ps_initgraphics(EPS_FORMAT);
 
966
    
 
967
    if (result == RETURN_SUCCESS) {
 
968
        curformat = EPS_FORMAT;
 
969
    }
 
970
    
 
971
    return (result);
 
972
}
 
973
 
 
974
int ps_op_parser(char *opstring)
 
975
{
 
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;
 
1018
    } else {
 
1019
        return RETURN_FAILURE;
 
1020
    }
 
1021
}
 
1022
 
 
1023
int eps_op_parser(char *opstring)
 
1024
{
 
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;
 
1052
    } else {
 
1053
        return RETURN_FAILURE;
 
1054
    }
 
1055
}
 
1056
 
 
1057
#ifndef NONE_GUI
 
1058
 
 
1059
static void update_ps_setup_frame(void);
 
1060
static int set_ps_setup_proc(void *data);
 
1061
 
 
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;
 
1070
 
 
1071
void ps_gui_setup(void)
 
1072
{
 
1073
    set_wait_cursor();
 
1074
    
 
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"    }
 
1081
        };
 
1082
        OptionItem docdata_op_items[3] = {
 
1083
            {DOCDATA_7BIT,   "7bit" },
 
1084
            {DOCDATA_8BIT,   "8bit"},
 
1085
            {DOCDATA_BINARY, "Binary"    }
 
1086
        };
 
1087
        
 
1088
        ps_setup_frame = CreateDialogForm(app_shell, "PS options");
 
1089
 
 
1090
        ps_setup_rc = CreateVContainer(ps_setup_frame);
 
1091
 
 
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);
 
1098
 
 
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);
 
1105
 
 
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");
 
1110
 
 
1111
        CreateAACDialog(ps_setup_frame, ps_setup_rc, set_ps_setup_proc, NULL);
 
1112
    }
 
1113
    update_ps_setup_frame();
 
1114
    
 
1115
    RaiseWindow(GetParent(ps_setup_frame));
 
1116
    unset_wait_cursor();
 
1117
}
 
1118
 
 
1119
static void update_ps_setup_frame(void)
 
1120
{
 
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);
 
1129
    }
 
1130
}
 
1131
 
 
1132
static int set_ps_setup_proc(void *data)
 
1133
{
 
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);
 
1141
    
 
1142
    return RETURN_SUCCESS;
 
1143
}
 
1144
 
 
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;
 
1152
 
 
1153
void eps_gui_setup(void)
 
1154
{
 
1155
    set_wait_cursor();
 
1156
    
 
1157
    if (eps_setup_frame == NULL) {
 
1158
        Widget fr, rc;
 
1159
        OptionItem docdata_op_items[3] = {
 
1160
            {DOCDATA_7BIT,   "7bit" },
 
1161
            {DOCDATA_8BIT,   "8bit"},
 
1162
            {DOCDATA_BINARY, "Binary"    }
 
1163
        };
 
1164
        
 
1165
        eps_setup_frame = CreateDialogForm(app_shell, "EPS options");
 
1166
 
 
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);
 
1175
    }
 
1176
    update_eps_setup_frame();
 
1177
    RaiseWindow(GetParent(eps_setup_frame));
 
1178
    
 
1179
    unset_wait_cursor();
 
1180
}
 
1181
 
 
1182
static void update_eps_setup_frame(void)
 
1183
{
 
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);
 
1189
    }
 
1190
}
 
1191
 
 
1192
static int set_eps_setup_proc(void *data)
 
1193
{
 
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);
 
1198
    
 
1199
    return RETURN_SUCCESS;
 
1200
}
 
1201
 
 
1202
#endif