~ubuntu-branches/ubuntu/gutsy/foo2zjs/gutsy-updates

« back to all changes in this revision

Viewing changes to foo2qpdl-wrapper.in

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2007-06-25 17:25:17 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070625172517-hfgsrqo8mmvtylad
Tags: 20070625-0ubuntu1
* New upstream release
  - Added support for Samsung CLP-300, CLP-600, CLX-3160, Xerox Phaser
    6110, 6115MFP, Konica Minolta magicolor 2480, 2490, 2530.
  - Bug fixes.
  debian/patches/10-makefile.dpatch: Regenerated to adapt to new foo2zjs
  version.
* Do not fail if building of manual.pdf fails. This file is not important
  and should not hold back releases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
#* Copyright (C) 2003-2006  Rick Richardson
 
4
#*
 
5
#* This program is free software; you can redistribute it and/or modify
 
6
#* it under the terms of the GNU General Public License as published by
 
7
#* the Free Software Foundation; either version 2 of the License, or
 
8
#* (at your option) any later version.
 
9
#*
 
10
#* This program is distributed in the hope that it will be useful,
 
11
#* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
#* GNU General Public License for more details.
 
14
#*
 
15
#* You should have received a copy of the GNU General Public License
 
16
#* along with this program; if not, write to the Free Software
 
17
#* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
#*
 
19
#* Authors: Rick Richardson <rick.richardson@comcast.net>
 
20
 
 
21
VERSION='$Id: foo2qpdl-wrapper.in,v 1.15 2007/06/11 00:48:32 rick Exp $'
 
22
 
 
23
#
 
24
# Printer Notes:
 
25
#
 
26
# Samsung CLP-300
 
27
# Samsung CLP-600
 
28
# Samsung CLX-3160
 
29
# Xerox Phaser 6110
 
30
#
 
31
 
 
32
PROGNAME="$0"
 
33
BASENAME=`basename $PROGNAME`
 
34
PREFIX=/usr
 
35
SHARE=$PREFIX/share/foo2qpdl
 
36
PATH=$PATH:/sw/bin:/opt/local/bin
 
37
 
 
38
#
 
39
#       Log the command line, for debugging and problem reports
 
40
#
 
41
if [ -x /usr/bin/logger ]; then
 
42
    logger -t "$BASENAME" -p lpr.info -- "$BASENAME $@" </dev/null
 
43
fi
 
44
 
 
45
usage() {
 
46
        cat <<EOF
 
47
Usage:
 
48
        $BASENAME [options] [ps-file]
 
49
 
 
50
        Foomatic printer wrapper for the foo2qpdl printer driver.
 
51
        This script reads a Postscript ps-file or standard input
 
52
        and converts it to a Samsung QPDL stream (CLP-600).
 
53
 
 
54
Normal Options:
 
55
-c                Print in color (else monochrome)
 
56
-d duplex         Duplex code to send to printer [$DUPLEX]
 
57
                    1=off, 2=longedge, 3=shortedge
 
58
-m media          Media code to send to printer [$MEDIA]
 
59
                    1=standard, 2=transparency, 3=glossy, 257=envelope,
 
60
                    259=letterhead, 261=thickstock, 262=postcard, 263=labels
 
61
-p paper          Paper code [$PAPER]
 
62
                    0=letter, 5=legal, 7=executive, 9=A4, 11=A5, 13=B5
 
63
                    20=env#10, 27=envDL 28=envC5 34=envB5 37=envMonarch
 
64
-n copies         Number of copies [$COPIES]
 
65
-r <xres>x<yres>  Set device resolution in pixels/inch [$RES]
 
66
-s source         Source code to send to printer [$SOURCE]
 
67
                    1=upper, 2=lower, 4=manual, 7=auto
 
68
                    Code numbers may vary with printer model.
 
69
-t                Draft mode.  Every other pixel is white.
 
70
-2/-3/-4/-6/-8/-10/-12/-14/-15/-16/-18
 
71
                  Print with N-up (requires psutils)
 
72
-o orient         For N-up: -op is portrait, -ol is landscape, -os is seascape.
 
73
 
 
74
Printer Tweaking Options:
 
75
-u <xoff>x<yoff>  Set offset of upper left printable in pixels [varies]
 
76
-l <xoff>x<yoff>  Set offset of lower right printable in pixels [varies]
 
77
-L mask           Send logical clipping values from -u/-l in ZjStream [3]
 
78
                  0=no, 1=Y, 2=X, 3=XY
 
79
-P                Do not output START_PLANE codes.  May be needed by some
 
80
                  monochrome-only printers.
 
81
-X padlen         Add extra zero padding to the end of BID segments [16]
 
82
-z model          Model: 0=CLP-300 1=CLP-600
 
83
 
 
84
Color Tweaking Options:
 
85
-g gsopts         Additional options to pass to Ghostscript, such as
 
86
                  -dDITHERPPI=nnn, etc.  May appear more than once. []
 
87
-G profile.icm    Convert profile.icm to a Postscript CRD using icc2ps and
 
88
                  adjust colors using the setcolorrendering PS operator.
 
89
                  $SHARE/icm/ will be searched for profile.icm.
 
90
-I intent         Select profile intent from ICM file [$INTENT]
 
91
                  0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute
 
92
-G gamma-file.ps  Prepend gamma-file to the Postscript input to perform
 
93
                  color correction using the setcolortransfer PS operator.
 
94
 
 
95
Debugging Options:
 
96
-S plane          Output just a single color plane from a color print [all]
 
97
                  1=Cyan, 2=Magenta, 3=Yellow, 4=Black
 
98
-D lvl            Set Debug level [$DEBUG]
 
99
-V                $VERSION
 
100
EOF
 
101
 
 
102
        exit 1
 
103
}
 
104
 
 
105
#
 
106
#       Report an error and exit
 
107
#
 
108
error() {
 
109
        echo "$BASENAME: $1" >&2
 
110
        exit 1
 
111
}
 
112
 
 
113
dbgcmd() {
 
114
        if [ $DEBUG -ge 1 ]; then
 
115
            echo "$@" >&2
 
116
        fi
 
117
        "$@"
 
118
}
 
119
 
 
120
#
 
121
#       N-up-ify the job.  Requires psnup from psutils package
 
122
#
 
123
nup() {
 
124
    case "$NUP" in
 
125
    [2368]|1[0458])
 
126
        tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.3in -p$paper -q
 
127
        ;;
 
128
    [49]|1[26])
 
129
        tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.5in -p$paper -q
 
130
        ;;
 
131
    *)
 
132
        error "Illegal call to nup()."
 
133
        ;;
 
134
    esac
 
135
}
 
136
 
 
137
#
 
138
#       Process the options
 
139
#
 
140
 
 
141
# Try to use a local copy of GhostScript 8.54, if available.  Otherwise,
 
142
# fallback to whatever the Linux distro has installed (usually 7.07)
 
143
#
 
144
# N.B. := operator used here, when :- would be better, because "ash"
 
145
# doesn't have :-
 
146
if gs8 -v >/dev/null 2>&1; then
 
147
        GSBIN=${GSBIN:-gs8}
 
148
else
 
149
        GSBIN=${GSBIN:-gs}
 
150
fi
 
151
 
 
152
CMDLINE="$*"
 
153
DEBUG=0
 
154
DUPLEX=1
 
155
COLOR=
 
156
COLORMODE=default
 
157
MODEL=0
 
158
QUALITY=1
 
159
QUALITY=wts
 
160
MEDIA=0
 
161
COPIES=1
 
162
PAPER=0
 
163
RES=1200x600
 
164
SOURCE=1
 
165
NUP=
 
166
CLIP_UL=
 
167
CLIP_LR=
 
168
CLIP_LOG=
 
169
BC=
 
170
AIB=
 
171
NOPLANES=
 
172
COLOR2MONO=
 
173
GAMMAFILE=default
 
174
INTENT=0
 
175
GSOPTS=
 
176
EXTRAPAD=
 
177
SAVETONER=
 
178
NUP_ORIENT=
 
179
GSDEV=-sDEVICE=pbmraw
 
180
# What mode to use if the user wants us to pick the "best" mode
 
181
case `$GSBIN --version` in
 
182
7*)     DEFAULTCOLORMODE=10
 
183
        DEFAULTCOLORMODE=1
 
184
        ;;
 
185
*)      DEFAULTCOLORMODE=1
 
186
        ;;
 
187
esac
 
188
while getopts "1:23456789o:b:cC:d:g:l:u:L:m:n:p:q:r:s:tz:ABS:D:G:I:PX:Vh?" opt
 
189
do
 
190
        case $opt in
 
191
        b)      GSBIN="$OPTARG";;
 
192
        c)      COLOR=-c;;
 
193
        d)      DUPLEX="$OPTARG";;
 
194
        g)      GSOPTS="$GSOPTS $OPTARG";;
 
195
        m)      MEDIA="$OPTARG";;
 
196
        n)      COPIES="$OPTARG";;
 
197
        p)      PAPER="$OPTARG";;
 
198
        q)      QUALITY="$OPTARG";;
 
199
        r)      RES="$OPTARG";;
 
200
        s)      SOURCE="$OPTARG";;
 
201
        t)      SAVETONER="-t";;
 
202
        z)      MODEL="$OPTARG";;
 
203
        l)      CLIP_LR="-l $OPTARG";;
 
204
        u)      CLIP_UL="-u $OPTARG";;
 
205
        L)      CLIP_LOG="-L $OPTARG";;
 
206
        A)      AIB=-A;;
 
207
        B)      BC=-B;;
 
208
        C)      COLORMODE="$OPTARG";;
 
209
        S)      COLOR2MONO="-S$OPTARG";;
 
210
        D)      DEBUG="$OPTARG";;
 
211
        G)      GAMMAFILE="$OPTARG";;
 
212
        I)      INTENT="$OPTARG";;
 
213
        P)      NOPLANES=-P;;
 
214
        X)      EXTRAPAD="-X $OPTARG";;
 
215
        [234689])       NUP="$opt";;
 
216
        [57])   error "Can't find acceptable layout for $opt-up";;
 
217
        1)      case "$OPTARG" in
 
218
                [024568])       NUP="1$OPTARG";;
 
219
                *)      error "Can't find acceptable layout for 1$OPTARG-up";;
 
220
                esac
 
221
                ;;
 
222
        o)      case "$OPTARG" in
 
223
                l*)     NUP_ORIENT=-l;;
 
224
                s*)     NUP_ORIENT=-r;;
 
225
                p*|*)   NUP_ORIENT=;;
 
226
                esac;;
 
227
        V)      echo "$VERSION"; foo2qpdl -V; exit 0;;
 
228
        h|\?)
 
229
                if [ "$CMDLINE" != "-?" -a "$CMDLINE" != -h ]; then
 
230
                    echo "Illegal command:"
 
231
                    echo "      $0 $CMDLINE"
 
232
                    echo
 
233
                fi
 
234
                usage;;
 
235
        esac
 
236
done
 
237
shift `expr $OPTIND - 1`
 
238
 
 
239
#
 
240
# If there is an argument left, take it as the file to print.
 
241
# Else, the input comes from stdin.
 
242
#
 
243
if [ $# -ge 1 ]; then
 
244
    if [ "$LPJOB" = "" ]; then
 
245
        : # LPJOB="$1"
 
246
    fi
 
247
    exec < $1
 
248
fi
 
249
 
 
250
#
 
251
case "$QUALITY" in
 
252
0)
 
253
    GSOPTS="-dCOLORSCREEN $GSOPTS"
 
254
    ;;
 
255
1)
 
256
    GSOPTS="-dCOLORSCREEN $GSOPTS"
 
257
    ;;
 
258
2)
 
259
    GSOPTS="-dMaxBitMap=500000000 $GSOPTS"
 
260
    ;;
 
261
wts)
 
262
    GSOPTS="-dCOLORSCREEN $GSOPTS"
 
263
    ;;
 
264
esac
 
265
 
 
266
#
 
267
#       Validate model code
 
268
#
 
269
case "$MODEL" in
 
270
0|1)    ;;
 
271
*)      error "Unknown model code $MODEL";;
 
272
esac
 
273
 
 
274
#
 
275
#       Validate media code
 
276
#
 
277
case "$MEDIA" in
 
278
0|plain)        MEDIA=0;;
 
279
1|thick)        MEDIA=1;;
 
280
2|thin)         MEDIA=2;;
 
281
3|bond)         MEDIA=3;;
 
282
4|color)        MEDIA=4;;
 
283
5|card)         MEDIA=5;;
 
284
6|labels)       MEDIA=6;;
 
285
7|envelope)     MEDIA=7;;
 
286
8|preprinted)   MEDIA=8;;
 
287
9|cotton)       MEDIA=9;;
 
288
10|recycled)    MEDIA=10;;
 
289
[0-9]*)         ;;
 
290
*)              error "Unknown media code $MEDIA";;
 
291
esac
 
292
 
 
293
#
 
294
#       Validate source (InputSlot) code
 
295
#
 
296
case "$SOURCE" in
 
297
1|auto)         SOURCE=1;;
 
298
2|manual)       SOURCE=2;;
 
299
3|multi)        SOURCE=3;;
 
300
4|tray1)        SOURCE=4;;
 
301
[0-9]*)         ;;
 
302
*)              error "Unknown source code $SOURCE";;
 
303
esac
 
304
 
 
305
#
 
306
#       Validate Duplex code
 
307
#
 
308
case "$DUPLEX" in
 
309
1|off|none)     DUPLEX=1;;
 
310
2|long*)        DUPLEX=2;;
 
311
3|short*)       DUPLEX=3;;
 
312
[0-9]*)         ;;
 
313
*)              error "Unknown duplex code $DUPLEX";;
 
314
esac
 
315
 
 
316
#
 
317
#       Validate Resolution
 
318
#
 
319
case "$RES" in
 
320
600x600)        ;;
 
321
1200x600)       ;;
 
322
1200x1200)      ;;
 
323
*)              error "Illegal resolution $RES";;
 
324
esac
 
325
 
 
326
#
 
327
#       Figure out the paper dimensions in pixels/inch, and set the
 
328
#       default clipping region.  Unfortunately, this is a trouble
 
329
#       area for ZjStream printers.  Various versions of ZjS print
 
330
#       engines react differently when asked to print into their
 
331
#       unprintable regions.
 
332
#
 
333
set_clipping() {
 
334
    ulx=$1; uly=$2
 
335
    lrx=$3; lry=$4
 
336
 
 
337
    # Set clipping region if it isn't already set
 
338
    if [ "$CLIP_UL" = "" ]; then
 
339
        case "$RES" in
 
340
        600x600)        ulx=`expr $ulx / 2`;;
 
341
        2400x600)       ulx=`expr $ulx \* 2`;;
 
342
        esac
 
343
        CLIP_UL="-u ${ulx}x${uly}"
 
344
    fi
 
345
    if [ "$CLIP_LR" = "" ]; then
 
346
        case "$RES" in
 
347
        600x600)        lrx=`expr $lrx / 2`;;
 
348
        2400x600)       lrx=`expr $lrx \* 2`;;
 
349
        esac
 
350
        CLIP_LR="-l ${lrx}x${lry}"
 
351
    fi
 
352
}
 
353
 
 
354
case "$PAPER" in
 
355
Custom*)
 
356
                #%%BeginFeature: *CustomPageSize True
 
357
                #216
 
358
                #360
 
359
                #0
 
360
                #0
 
361
                #0
 
362
                #pop pop pop pop pop
 
363
 
 
364
                TMPFILE=/tmp/cus$$
 
365
                cat >$TMPFILE
 
366
                exec <$TMPFILE
 
367
 
 
368
                XDIM=`head -n 1000 $TMPFILE | sed -n '/CustomPageSize/{n;p;}'`
 
369
                case "$XDIM" in
 
370
                ""|0*)
 
371
                    rm -f $TMPFILE
 
372
                    error "Custom page size XDIM != 1-99999"
 
373
                    ;;
 
374
                esac
 
375
                XDIM=`dc -e "$XDIM 1200* 72/p"`
 
376
 
 
377
                YDIM=`head -n 1000 $TMPFILE | sed -n '/CustomPageSize/{n;n;p;}'`
 
378
                case "$YDIM" in
 
379
                ""|0*)
 
380
                    rm -f $TMPFILE
 
381
                    error "Custom page size YDIM != 1-99999"
 
382
                    ;;
 
383
                esac
 
384
                YDIM=`dc -e "$YDIM 600* 72/p"`
 
385
                PAPER=21;        paper=letter;
 
386
                set_clipping 2 100     2 100
 
387
                ;;
 
388
0|letter)       PAPER=0;        paper=letter;    XDIM="10200"; YDIM="6600"
 
389
                set_clipping 150 100    150 100
 
390
                ;;
 
391
1|legal)        PAPER=1;        paper=legal;     XDIM="10200"; YDIM="8400"
 
392
                set_clipping 150 100    150 100
 
393
                ;;
 
394
3|executive)    PAPER=3;        paper=executive; XDIM="8700";  YDIM="6300"
 
395
                set_clipping 150 100    150 100
 
396
                ;;
 
397
2|a4|A4)        PAPER=2;        paper=a4;        XDIM="9920";  YDIM="7016"
 
398
                set_clipping 150 100    150 100
 
399
                ;;
 
400
16|a5|A5)       PAPER=16;       paper=a5;        XDIM="6992";  YDIM="4960"
 
401
                set_clipping 150 100    150 100
 
402
                ;;
 
403
11|b5jis|B5jis) PAPER=11;       paper=b5;        XDIM="8598";  YDIM="6070"
 
404
                set_clipping 150 100    150 100
 
405
                ;;
 
406
24|folio)       PAPER=24;       paper=folio;     XDIM="10200"; YDIM="7800"
 
407
                set_clipping 150 100    150 100
 
408
                ;;
 
409
26|"env#9")     PAPER=26;       paper=env9;      XDIM="4496";  YDIM="5324"
 
410
                set_clipping 150 100    150 100
 
411
                ;;
 
412
6|"env#10")     PAPER=6;        paper=env10;     XDIM="4950";  YDIM="5700"
 
413
                set_clipping 150 100    150 100
 
414
                ;;
 
415
9|envDL)        PAPER=9;        paper=envDL;     XDIM="5200";  YDIM="5200"
 
416
                set_clipping 150 100    150 100
 
417
                ;;
 
418
8|envC5)        PAPER=8;        paper=envC5;     XDIM="7650";  YDIM="5408"
 
419
                set_clipping 150 100    150 100
 
420
                ;;
 
421
23|envC6)       PAPER=23;       paper=envC6;     XDIM="5386";  YDIM="3826"
 
422
                set_clipping 150 100    150 100
 
423
                ;;
 
424
12|b5iso|B5iso) PAPER=12;       paper=b5;        XDIM="8314";  YDIM="5906"
 
425
                set_clipping 150 100    150 100
 
426
                ;;
 
427
7|envMonarch)   PAPER=7;        paper=envMonarch;XDIM="4650";  YDIM="4500"
 
428
                set_clipping 150 100    150 100
 
429
                ;;
 
430
25|env6.75)     PAPER=25;       paper=env6.75;   XDIM="4348";  YDIM="3900"
 
431
                set_clipping 150 100    150 100
 
432
                ;;
 
433
17|a6|A6)       PAPER=17;       paper=a6;        XDIM="4960";  YDIM="3496"
 
434
                set_clipping 150 100    150 100
 
435
                ;;
 
436
28|oficio)      PAPER=28;       paper=a6;        XDIM="10200"; YDIM="8100"
 
437
                set_clipping 150 100    150 100
 
438
                ;;
 
439
*)              error "Unimplemented paper code $PAPER";;
 
440
esac
 
441
# e.g. /usr/share/ghostscript/7.07/lib/gs_statd.ps
 
442
PAPERSIZE="-sPAPERSIZE=$paper";
 
443
 
 
444
case "$RES" in
 
445
600x600)        XDIM=`expr $XDIM / 2`;;
 
446
1200x600)       ;;
 
447
1200x1200)      YDIM=`expr $YDIM \* 2`;;
 
448
esac
 
449
DIM="${XDIM}x${YDIM}"
 
450
 
 
451
#
 
452
# Filter thru psnup if N-up printing has been requested
 
453
#
 
454
case $NUP in
 
455
[234689]|1[024568])     PREFILTER="nup";;
 
456
*)                      PREFILTER=cat;;
 
457
esac
 
458
 
 
459
#
 
460
#       Overload -G.  If the file name ends with ".icm" or ".ICM"
 
461
#       then convert the ICC color profile to a Postscript CRD,
 
462
#       then prepend it to the users job.  Select the intent
 
463
#       using the -I option.
 
464
#
 
465
 
 
466
create_crd() {
 
467
    #
 
468
    # Create a Postscript CRD
 
469
    #
 
470
    ICC2PS=$PREFIX/bin/foo2zjs-icc2ps
 
471
    if [ -x $ICC2PS ]; then
 
472
        case "$GAMMAFILE" in
 
473
        none | none.icm | */none.icm)
 
474
            ;;
 
475
        *)
 
476
            $ICC2PS -o $GAMMAFILE -t$INTENT > $ICCTMP.crd.ps 2>$ICCTMP.log \
 
477
            || error "Problem converting .ICM file to Postscript"
 
478
            ;;
 
479
        esac
 
480
 
 
481
        cat > $ICCTMP.usecie.ps <<-EOF
 
482
                %!PS-Adobe-3.0
 
483
                <</UseCIEColor true>>setpagedevice
 
484
        EOF
 
485
        if [ "$QUALITY" = wts ]; then
 
486
            cat >> $ICCTMP.usecie.ps <<-EOF
 
487
                << /UseWTS true >> setuserparams
 
488
                <<
 
489
                    /AccurateScreens true
 
490
                    /HalftoneType 1
 
491
                    /HalftoneName (Round Dot Screen) cvn
 
492
                    /SpotFunction { 180 mul cos exch 180 mul cos add 2 div}
 
493
                    /Frequency 137
 
494
                    /Angle 37
 
495
                >> sethalftone
 
496
                EOF
 
497
        fi
 
498
        cat > $ICCTMP.selcrd.ps <<-EOF
 
499
                /Current /ColorRendering findresource setcolorrendering
 
500
        EOF
 
501
        case "$GAMMAFILE" in
 
502
        none | none.icm | */none.icm) GAMMAFILE="$ICCTMP.usecie.ps";;
 
503
        *)      GAMMAFILE="$ICCTMP.usecie.ps $ICCTMP.crd.ps $ICCTMP.selcrd.ps";;
 
504
        esac
 
505
    else
 
506
        GAMMFILE=
 
507
    fi
 
508
}
 
509
 
 
510
if [ $DEBUG -gt 0 ]; then
 
511
    ICCTMP=/tmp/icc
 
512
else
 
513
    ICCTMP=/tmp/icc$$
 
514
fi
 
515
 
 
516
if [ "" = "$COLOR" ]; then
 
517
    COLORMODE=
 
518
    GAMMAFILE=
 
519
else
 
520
    case "$COLORMODE" in
 
521
    default)    COLORMODE=$DEFAULTCOLORMODE;;
 
522
    esac
 
523
fi
 
524
 
 
525
CRDBASE="$PREFIX/share/foo2qpdl/crd"
 
526
case "$MODEL" in
 
527
    0)  model=CLP-300;;
 
528
    1)  model=CLP-600;;
 
529
esac
 
530
case "$RES" in
 
531
    600x600)    SCREEN=$model-600x600cms2;;
 
532
    1200x600)   SCREEN=$model-1200x600cms2;;
 
533
    1200x1200)  SCREEN=$model-1200x1200cms2;;
 
534
esac
 
535
 
 
536
case "$COLORMODE" in
 
537
0|"")
 
538
    # Monochrome
 
539
    ;;
 
540
10|icm)
 
541
    # Use old ICM method
 
542
    AIB=-A
 
543
    BC=-B
 
544
    case "$GAMMAFILE" in
 
545
    none | none.icm | */none.icm)
 
546
        create_crd
 
547
        ;;
 
548
    *.icm|*.ICM|*.icc|*.ICC)
 
549
        #
 
550
        # Its really an .ICM file, not a gamma file.
 
551
        #
 
552
        # The file can be a full path name, or the name of a file in $SHARE/icm/
 
553
        #
 
554
        if [ -r "$GAMMAFILE" ]; then
 
555
            create_crd
 
556
        elif [ -r "$SHARE/icm/$GAMMAFILE" ]; then
 
557
            GAMMAFILE="$SHARE/icm/$GAMMAFILE"
 
558
            create_crd
 
559
        else
 
560
            GAMMAFILE=
 
561
        fi
 
562
        ;;
 
563
    esac
 
564
    ;;
 
565
1|crd)
 
566
    # CRD
 
567
    GAMMAFILE=""
 
568
    GAMMAFILE="$GAMMAFILE $CRDBASE/${model}cms"
 
569
    GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
 
570
    # Black text...
 
571
    TMPFILE2=/tmp/black$$
 
572
    cat $CRDBASE/black-text.ps - >$TMPFILE2
 
573
    exec <$TMPFILE2
 
574
    ;;
 
575
*.crd)
 
576
    GAMMAFILE="$CRDBASE/prolog.ps"
 
577
    if [ -f $COLORMODE ]; then
 
578
        GAMMAFILE="$GAMMAFILE $COLORMODE"
 
579
    elif [ -f $CRDBASE/$COLORMODE ]; then
 
580
        GAMMAFILE="$GAMMAFILE $CRDBASE/$COLORMODE"
 
581
    else
 
582
        error "Can't find CRD '$COLORMODE' in . or in $CRDBASE"
 
583
    fi
 
584
    GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
 
585
    ;;
 
586
*)
 
587
    error "Unknown color method '$COLORMODE'"
 
588
    ;;
 
589
esac
 
590
 
 
591
if [ "" != "$COLOR" ]; then
 
592
    if [ "" = "$AIB" -a "" = "$BC" ]; then
 
593
        # Faster, but can't handle AllIsBlack or BlackClears
 
594
        GSDEV=-sDEVICE=pksmraw
 
595
    else
 
596
        # Can't handle different size pages
 
597
        GSDEV=-sDEVICE=bitcmyk
 
598
    fi
 
599
fi
 
600
 
 
601
#
 
602
#       Figure out USERNAME
 
603
#
 
604
if [ "$LPUSER" != "" ]; then
 
605
    USER="$LPUSER@$LPHOST"
 
606
else
 
607
    USER=""
 
608
fi
 
609
 
 
610
#
 
611
#       Main Program, just cobble together the pipeline and run it
 
612
#
 
613
#       The malarky with file descriptors 1 and 3 is to avoid a bug in
 
614
#       (some versions?) of Ghostscript where Postscript's stdout gets
 
615
#       intermingled with the printer drivers output, resulting in
 
616
#       corrupted image data.
 
617
#
 
618
GS="$GSBIN -q -dBATCH -dSAFER -dQUIET -dNOPAUSE"
 
619
 
 
620
sed 's#^[^/]*cupsPSLevel2#false#' | \
 
621
$PREFILTER \
 
622
| ($GS $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS \
 
623
    -sOutputFile="|cat 1>&3" $GAMMAFILE - >/dev/null) 3>&1 \
 
624
| foo2qpdl -r$RES -g$DIM -p$PAPER -m$MEDIA -n$COPIES -d$DUPLEX -s$SOURCE \
 
625
            $COLOR $CLIP_UL $CLIP_LR $CLIP_LOG $SAVETONER \
 
626
            -J "$LPJOB" -U "$USER" \
 
627
            $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD -D$DEBUG
 
628
 
 
629
#
 
630
#       Log the command line, for debugging and problem reports
 
631
#
 
632
if [ -x /usr/bin/logger ]; then
 
633
    logger -t "$BASENAME" -p lpr.info -- \
 
634
        "$GSBIN $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS $GAMMAFILE"
 
635
    logger -t "$BASENAME" -p lpr.info -- \
 
636
        "foo2qpdl -r$RES -g$DIM -p$PAPER -m$MEDIA \
 
637
-n$COPIES -d$DUPLEX -s$SOURCE $COLOR $CLIP_UL $CLIP_LR $CLIP_LOG \
 
638
$SAVETONER $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD"
 
639
fi
 
640
 
 
641
#
 
642
#       Remove cruft
 
643
#
 
644
if [ $DEBUG -eq 0 ]; then
 
645
    for i in crd.ps log usecie.ps selcrd.ps
 
646
    do
 
647
        file="$ICCTMP.$i"
 
648
        [ -f $file ] && rm -f $file
 
649
    done
 
650
    [ -f "$TMPFILE" ] && rm -f $TMPFILE
 
651
    [ -f "$TMPFILE2" ] && rm -f $TMPFILE2
 
652
fi
 
653
 
 
654
exit 0