1#! @SCRIPT_SH@
2#	$Id$
3#
4# HylaFAX Facsimile Software
5#
6# Copyright (c) 1990-1996 Sam Leffler
7# Copyright (c) 1991-1996 Silicon Graphics, Inc.
8# HylaFAX is a trademark of Silicon Graphics
9#
10# Permission to use, copy, modify, distribute, and sell this software and
11# its documentation for any purpose is hereby granted without fee, provided
12# that (i) the above copyright notices and this permission notice appear in
13# all copies of the software and related documentation, and (ii) the names of
14# Sam Leffler and Silicon Graphics may not be used in any advertising or
15# publicity relating to the software without the specific, prior written
16# permission of Sam Leffler and Silicon Graphics.
17#
18# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
19# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
20# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
21#
22# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
23# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
24# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
25# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
26# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
27# OF THIS SOFTWARE.
28#
29
30#
31# Convert PCL to facsimile.
32#
33# pcl2fax [-o output] [-l pagelength] [-w pagewidth]
34#	[-r resolution] [-m maxpages] [-*] files ...
35#
36# NB: this shell script is assumed to be run from the
37#     top of the spooling hierarchy -- s.t. the etc directory
38#     is present.
39#
40
41test -f etc/setup.cache || {
42    SPOOL=`pwd`
43    cat<<EOF
44
45FATAL ERROR: $SPOOL/etc/setup.cache is missing!
46
47The file $SPOOL/etc/setup.cache is not present.  This
48probably means the machine has not been setup using the faxsetup(@MANNUM1_8@)
49command.  Read the documentation on setting up HylaFAX before you
50startup a server system.
51
52EOF
53    exit 1
54}
55. etc/setup.cache
56
57if [ ! -x "$PCL6CMD" ]; then
58    echo "PCL documents are not (currently) supported."
59    exit 254			# causes document to be rejected
60fi
61
62out=pcl.fax		# default output filename
63pagewidth=1728		# standard fax width (pixels)
64pagelength=297		# default to A4 (mm)
65vres=98			# default to low res
66device=tiffg3		# default to 1D
67unlimitedlength=no	# default to fixed length-pages
68jobid=
69out=pcl.fax				# default output filename
70files=
71opt=
72while test $# != 0
73do case "$1" in
74    -o) shift; out=$1 ;;
75    -w) shift; pagewidth="$1" ;;
76    -l) shift; pagelength="$1" ;;
77    -r) shift; vres="$1" ;;
78    -m) shift;;				# NB: not implemented
79    -U) unlimitedlength=yes ;;
80    -1) device=tiffg3 ;;
81    -2) ($PCL -h | grep tiffg32d >/dev/null 2>&1) \
82            && { device=tiffg32d; } \
83            || { device=tiffg3; }
84        ;;
85    -3) ($PCL -h | grep tiffg4 >/dev/null 2>&1) \
86            && { device=tiffg4; } \
87            || { device=tiffg3; }
88        ;;
89    -*) ;;
90    *)  files="$files $1" ;;
91    esac
92    shift
93done
94
95test -z "$files" && {
96    echo "$0: No input file specified."
97    exit 255
98}
99
100pagelength=${pagelength%%.*}
101test "$pagewidth" = "1734" && pagewidth=1728
102
103case "${pagewidth}x${pagelength}" in
1041728x280|1728x279|2592x280|2592x279|3456x280|3456x279)  # 279.4mm is actually correct...
105    paper=letter;;
1061728x364|2592x364|3456x364)
107    paper=legal;;
108*x296|*x297)                    # more roundoff problems...
109    paper=a4;;
110*x364)
111    paper=b4;;
1122432x*|3648x*|4864x*)
113    paper=a3;;
114*)
115    echo "$0: Unsupported page size: $pagewidth x $pagelength";
116    exit 254;;                  # causes document to be rejected
117esac
118#
119# The image must end up with a pixel width according to T.32 Table 21.
120# Ghostscript contains code to fixate a4 and letter to 1728 pixels
121# when using 196-204 dpi and tiffg3/4, it supposedly does the same for
122# B4 but not for A3, thus the floats are needed (for A3's benefit).
123#
124# See ghostscript/doc/Devices.htm under -dAdjustWidth=1 (default).
125# Use -dAdjustWidth=0 to disable.  With the right patch,
126# http://bugs.ghostscript.com/show_bug.cgi?id=688064
127# AdjustWidth can be made to specify the pagewidth directly and
128# replace -dFIXEDMEDIA to permit TIFFs to be produced with
129# varied lengths.
130#
131case "$paper" in
132    a4)
133        case "$pagewidth" in
134            2592) hres=313.65;;         # VR_300X300
135            3456) hres=418.20;;         # VR_R16
136            *) hres=209.10;;            # everything else, 1728 pixels
137        esac;;
138    b4)
139        case "$pagewidth" in
140            3072) hres=311.97;;         # VR_300X300
141            4096) hres=415.95;;         # VR_R16
142            *) hres=207.98;;            # everything else, 2048 pixels
143        esac;;
144    a3)
145        case "$pagewidth" in
146            3648) hres=311.94;;         # VR_300X300
147            4864) hres=415.93;;         # VR_R16
148            *) hres=207.96;;            # everything else, 2432 pixels
149        esac;;
150    *)                                  # letter, legal
151        case "$pagewidth" in
152            2592) hres=304.94;;         # VR_300X300
153            3456) hres=406.59;;         # VR_R16
154            *) hres=203.29;;            # everything else, 1728 pixels
155        esac;;
156esac
157
158#
159# The sed work fixes bug in Windows-generated
160# PostScript that causes certain international
161# character marks to be placed incorrectly.
162#
163#    | $SED -e 's/yAscent Ascent def/yAscent 0 def/g' \
164#
165# NB: unfortunately it appears to break valid PostScript;
166#     so it's been disabled.
167
168#
169# Suggestion from "Alan Sparks" <asparks@nss.harris.com>,
170# Add the -DFIXEDMEDIA argument to the last command in pcl2fax.
171# This prevents page sizing within the documents from altering
172# the command-line page size specification.  This prevents
173# TIFFs to be made with pages of varied lengths, however.
174# See the comments on AdjustWidth above.
175#
176FIXEDWIDTH="-dFIXEDMEDIA"
177
178#
179# Apply customizations such as watermarking.
180#
181if [ -f etc/FaxModify ]; then
182    . etc/FaxModify
183fi
184
185# For debuging
186false && echo $PCL6 \
187    -sDEVICE=$device \
188    -dNOPAUSE \
189    -dSAFER=true \
190    -sPAPERSIZE=$paper \
191    $FIXEDWIDTH \
192    -r$hres\x$vres \
193    "-sOutputFile=$out" \
194    "$files"
195
196if [ ! "$PCLFONTSOURCE" -a -n "$FONTPATH" ] ; then
197    PCLFONTSOURCE=$FONTPATH
198fi
199if [ -n "$PCLFONTSOURCE" ] ; then
200    export PCLFONTSOURCE
201fi
202
203$CAT $files | $PCL6 \
204    -sDEVICE=$device \
205    -dNOPAUSE \
206    -dSAFER=true \
207    -sPAPERSIZE=$paper \
208    $FIXEDWIDTH \
209    -r$hres\x$vres \
210    "-sOutputFile=$out" \
211    -
212
213exit 0
214