3
#* Copyright (C) 2003-2006 Rick Richardson
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.
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.
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.
19
#* Authors: Rick Richardson <rick.richardson@comcast.net>
21
VERSION='$Id: foo2qpdl-wrapper.in,v 1.15 2007/06/11 00:48:32 rick Exp $'
33
BASENAME=`basename $PROGNAME`
35
SHARE=$PREFIX/share/foo2qpdl
36
PATH=$PATH:/sw/bin:/opt/local/bin
39
# Log the command line, for debugging and problem reports
41
if [ -x /usr/bin/logger ]; then
42
logger -t "$BASENAME" -p lpr.info -- "$BASENAME $@" </dev/null
48
$BASENAME [options] [ps-file]
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).
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.
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]
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
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.
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]
106
# Report an error and exit
109
echo "$BASENAME: $1" >&2
114
if [ $DEBUG -ge 1 ]; then
121
# N-up-ify the job. Requires psnup from psutils package
126
tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.3in -p$paper -q
129
tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.5in -p$paper -q
132
error "Illegal call to nup()."
138
# Process the options
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)
144
# N.B. := operator used here, when :- would be better, because "ash"
146
if gs8 -v >/dev/null 2>&1; then
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
185
*) DEFAULTCOLORMODE=1
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
193
d) DUPLEX="$OPTARG";;
194
g) GSOPTS="$GSOPTS $OPTARG";;
196
n) COPIES="$OPTARG";;
198
q) QUALITY="$OPTARG";;
200
s) SOURCE="$OPTARG";;
203
l) CLIP_LR="-l $OPTARG";;
204
u) CLIP_UL="-u $OPTARG";;
205
L) CLIP_LOG="-L $OPTARG";;
208
C) COLORMODE="$OPTARG";;
209
S) COLOR2MONO="-S$OPTARG";;
211
G) GAMMAFILE="$OPTARG";;
212
I) INTENT="$OPTARG";;
214
X) EXTRAPAD="-X $OPTARG";;
215
[234689]) NUP="$opt";;
216
[57]) error "Can't find acceptable layout for $opt-up";;
218
[024568]) NUP="1$OPTARG";;
219
*) error "Can't find acceptable layout for 1$OPTARG-up";;
227
V) echo "$VERSION"; foo2qpdl -V; exit 0;;
229
if [ "$CMDLINE" != "-?" -a "$CMDLINE" != -h ]; then
230
echo "Illegal command:"
237
shift `expr $OPTIND - 1`
240
# If there is an argument left, take it as the file to print.
241
# Else, the input comes from stdin.
243
if [ $# -ge 1 ]; then
244
if [ "$LPJOB" = "" ]; then
253
GSOPTS="-dCOLORSCREEN $GSOPTS"
256
GSOPTS="-dCOLORSCREEN $GSOPTS"
259
GSOPTS="-dMaxBitMap=500000000 $GSOPTS"
262
GSOPTS="-dCOLORSCREEN $GSOPTS"
267
# Validate model code
271
*) error "Unknown model code $MODEL";;
275
# Validate media code
285
7|envelope) MEDIA=7;;
286
8|preprinted) MEDIA=8;;
288
10|recycled) MEDIA=10;;
290
*) error "Unknown media code $MEDIA";;
294
# Validate source (InputSlot) code
302
*) error "Unknown source code $SOURCE";;
306
# Validate Duplex code
309
1|off|none) DUPLEX=1;;
313
*) error "Unknown duplex code $DUPLEX";;
317
# Validate Resolution
323
*) error "Illegal resolution $RES";;
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.
337
# Set clipping region if it isn't already set
338
if [ "$CLIP_UL" = "" ]; then
340
600x600) ulx=`expr $ulx / 2`;;
341
2400x600) ulx=`expr $ulx \* 2`;;
343
CLIP_UL="-u ${ulx}x${uly}"
345
if [ "$CLIP_LR" = "" ]; then
347
600x600) lrx=`expr $lrx / 2`;;
348
2400x600) lrx=`expr $lrx \* 2`;;
350
CLIP_LR="-l ${lrx}x${lry}"
356
#%%BeginFeature: *CustomPageSize True
368
XDIM=`head -n 1000 $TMPFILE | sed -n '/CustomPageSize/{n;p;}'`
372
error "Custom page size XDIM != 1-99999"
375
XDIM=`dc -e "$XDIM 1200* 72/p"`
377
YDIM=`head -n 1000 $TMPFILE | sed -n '/CustomPageSize/{n;n;p;}'`
381
error "Custom page size YDIM != 1-99999"
384
YDIM=`dc -e "$YDIM 600* 72/p"`
385
PAPER=21; paper=letter;
386
set_clipping 2 100 2 100
388
0|letter) PAPER=0; paper=letter; XDIM="10200"; YDIM="6600"
389
set_clipping 150 100 150 100
391
1|legal) PAPER=1; paper=legal; XDIM="10200"; YDIM="8400"
392
set_clipping 150 100 150 100
394
3|executive) PAPER=3; paper=executive; XDIM="8700"; YDIM="6300"
395
set_clipping 150 100 150 100
397
2|a4|A4) PAPER=2; paper=a4; XDIM="9920"; YDIM="7016"
398
set_clipping 150 100 150 100
400
16|a5|A5) PAPER=16; paper=a5; XDIM="6992"; YDIM="4960"
401
set_clipping 150 100 150 100
403
11|b5jis|B5jis) PAPER=11; paper=b5; XDIM="8598"; YDIM="6070"
404
set_clipping 150 100 150 100
406
24|folio) PAPER=24; paper=folio; XDIM="10200"; YDIM="7800"
407
set_clipping 150 100 150 100
409
26|"env#9") PAPER=26; paper=env9; XDIM="4496"; YDIM="5324"
410
set_clipping 150 100 150 100
412
6|"env#10") PAPER=6; paper=env10; XDIM="4950"; YDIM="5700"
413
set_clipping 150 100 150 100
415
9|envDL) PAPER=9; paper=envDL; XDIM="5200"; YDIM="5200"
416
set_clipping 150 100 150 100
418
8|envC5) PAPER=8; paper=envC5; XDIM="7650"; YDIM="5408"
419
set_clipping 150 100 150 100
421
23|envC6) PAPER=23; paper=envC6; XDIM="5386"; YDIM="3826"
422
set_clipping 150 100 150 100
424
12|b5iso|B5iso) PAPER=12; paper=b5; XDIM="8314"; YDIM="5906"
425
set_clipping 150 100 150 100
427
7|envMonarch) PAPER=7; paper=envMonarch;XDIM="4650"; YDIM="4500"
428
set_clipping 150 100 150 100
430
25|env6.75) PAPER=25; paper=env6.75; XDIM="4348"; YDIM="3900"
431
set_clipping 150 100 150 100
433
17|a6|A6) PAPER=17; paper=a6; XDIM="4960"; YDIM="3496"
434
set_clipping 150 100 150 100
436
28|oficio) PAPER=28; paper=a6; XDIM="10200"; YDIM="8100"
437
set_clipping 150 100 150 100
439
*) error "Unimplemented paper code $PAPER";;
441
# e.g. /usr/share/ghostscript/7.07/lib/gs_statd.ps
442
PAPERSIZE="-sPAPERSIZE=$paper";
445
600x600) XDIM=`expr $XDIM / 2`;;
447
1200x1200) YDIM=`expr $YDIM \* 2`;;
449
DIM="${XDIM}x${YDIM}"
452
# Filter thru psnup if N-up printing has been requested
455
[234689]|1[024568]) PREFILTER="nup";;
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.
468
# Create a Postscript CRD
470
ICC2PS=$PREFIX/bin/foo2zjs-icc2ps
471
if [ -x $ICC2PS ]; then
473
none | none.icm | */none.icm)
476
$ICC2PS -o $GAMMAFILE -t$INTENT > $ICCTMP.crd.ps 2>$ICCTMP.log \
477
|| error "Problem converting .ICM file to Postscript"
481
cat > $ICCTMP.usecie.ps <<-EOF
483
<</UseCIEColor true>>setpagedevice
485
if [ "$QUALITY" = wts ]; then
486
cat >> $ICCTMP.usecie.ps <<-EOF
487
<< /UseWTS true >> setuserparams
489
/AccurateScreens true
491
/HalftoneName (Round Dot Screen) cvn
492
/SpotFunction { 180 mul cos exch 180 mul cos add 2 div}
498
cat > $ICCTMP.selcrd.ps <<-EOF
499
/Current /ColorRendering findresource setcolorrendering
502
none | none.icm | */none.icm) GAMMAFILE="$ICCTMP.usecie.ps";;
503
*) GAMMAFILE="$ICCTMP.usecie.ps $ICCTMP.crd.ps $ICCTMP.selcrd.ps";;
510
if [ $DEBUG -gt 0 ]; then
516
if [ "" = "$COLOR" ]; then
521
default) COLORMODE=$DEFAULTCOLORMODE;;
525
CRDBASE="$PREFIX/share/foo2qpdl/crd"
531
600x600) SCREEN=$model-600x600cms2;;
532
1200x600) SCREEN=$model-1200x600cms2;;
533
1200x1200) SCREEN=$model-1200x1200cms2;;
545
none | none.icm | */none.icm)
548
*.icm|*.ICM|*.icc|*.ICC)
550
# Its really an .ICM file, not a gamma file.
552
# The file can be a full path name, or the name of a file in $SHARE/icm/
554
if [ -r "$GAMMAFILE" ]; then
556
elif [ -r "$SHARE/icm/$GAMMAFILE" ]; then
557
GAMMAFILE="$SHARE/icm/$GAMMAFILE"
568
GAMMAFILE="$GAMMAFILE $CRDBASE/${model}cms"
569
GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
571
TMPFILE2=/tmp/black$$
572
cat $CRDBASE/black-text.ps - >$TMPFILE2
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"
582
error "Can't find CRD '$COLORMODE' in . or in $CRDBASE"
584
GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
587
error "Unknown color method '$COLORMODE'"
591
if [ "" != "$COLOR" ]; then
592
if [ "" = "$AIB" -a "" = "$BC" ]; then
593
# Faster, but can't handle AllIsBlack or BlackClears
594
GSDEV=-sDEVICE=pksmraw
596
# Can't handle different size pages
597
GSDEV=-sDEVICE=bitcmyk
602
# Figure out USERNAME
604
if [ "$LPUSER" != "" ]; then
605
USER="$LPUSER@$LPHOST"
611
# Main Program, just cobble together the pipeline and run it
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.
618
GS="$GSBIN -q -dBATCH -dSAFER -dQUIET -dNOPAUSE"
620
sed 's#^[^/]*cupsPSLevel2#false#' | \
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
630
# Log the command line, for debugging and problem reports
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"
644
if [ $DEBUG -eq 0 ]; then
645
for i in crd.ps log usecie.ps selcrd.ps
648
[ -f $file ] && rm -f $file
650
[ -f "$TMPFILE" ] && rm -f $TMPFILE
651
[ -f "$TMPFILE2" ] && rm -f $TMPFILE2