~ubuntu-branches/debian/experimental/cups-filters/experimental

« back to all changes in this revision

Viewing changes to filter/pstopdf

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2012-07-22 18:57:32 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20120722185732-26kkte5p1lth3rt5
Tags: 1.0.20-0bzr1
* New upstream release
   - pdftops: Added another workaround for Kyocera printers: Some
     models get very slow on images which request interpolation,
     so now we remove the image interpolation requests by additional
     PostScript code only inserted for Kyocera printers (LP: #1026974).
   - Made the Poppler-based filters pdftopdf and pdftoopvp build with
     both Poppler 0.18.x and 0.20.x (Upstream bug #1055).
   - Fixes according to Coverity scan results (Upstream bug #1054).
   - Switched build system to autotools. This especially fixes several
     build problems in Gentoo. Also build-tested with CUPS 1.6.0b1.
   - Fixes for compatibility with clang/gcc-4.7.
   - textonly: Filter did not work as a pipe with copies=1 (Upstream bug
     #1032).
   - texttopdf: Avoid trimming the results of FcFontSort(), as this may
     miss some reasonable candidates under certain circumstances. BTW,
     fix passing a non-pointer as a pointer to "result" (Closes: #670055).
   - Corrected documentation. The option for the maximum image rendering
     resolution in pdftops is "pdftops-max-image-resolution", not
     "pdftops-max-image-resolution-default".
* debian/patches/fcfontsort-no-trim.patch: Removed, fixed upstream.
* debian/rules: Updated options for ./configure and make for the new autotools
  build system.
* debian/watch: Switched to bz2 upstream packages.
* debian/rules, debian/copyright, debian/cups-filters.docs: Updated for
  renamed documentation files.
* debian/control, debian/libfontembed1.install,
  debian/libfontembed-dev.install: Added new binary packages for libfontembed.
* debian/copyright: Updated for recent file additions, and rearrangement of
  directories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# $Id: pstopdf,v 1.3 2003/02/15 15:21:00 gurubert Exp $
 
4
#
 
5
# This is a Postscript to PDF filter for CUPS
 
6
#
 
7
# (C) 2003 Robert Sander <robert.sander@epigenomics.com>
 
8
# (C) 2008-2012 Till Kamppeter <till.kamppeter@gmail.com>
 
9
#
 
10
# Released under GPL
 
11
#
 
12
# NO WARRANTY AT ALL
 
13
#
 
14
 
 
15
set -e
 
16
 
 
17
PS2PS=`which ps2ps`
 
18
GS=`which gs`
 
19
 
 
20
PS2PS_OPTIONS="-dAutoRotatePages=/None -dAutoFilterColorImages=false \
 
21
               -dNOPLATFONTS -dPARANOIDSAFER -dNOINTERPOLATE -sstdout=%stderr"
 
22
PS2PDF_OPTIONS="-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.3"
 
23
PS2PDF_OPTIONS="$PS2PDF_OPTIONS $PS2PS_OPTIONS"
 
24
PS2PDF_OPTIONS="$PS2PDF_OPTIONS -dColorImageFilter=/FlateEncode \
 
25
                -dPDFSETTINGS=/printer \
 
26
                -dColorConversionStrategy=/LeaveColorUnchanged"
 
27
 
 
28
echo "DEBUG: pstopdf $# args: $@" >&2
 
29
echo "DEBUG: PPD: $PPD" >&2
 
30
 
 
31
if [ $# -lt 5 -o $# -gt 6 ]; then
 
32
 
 
33
  echo "ERROR: $0 job-id user title copies options [file]" >&2
 
34
  exit 1
 
35
 
 
36
fi
 
37
 
 
38
# Read from given file.
 
39
if [ -n "$6" ]; then
 
40
  exec <"$6"
 
41
fi
 
42
 
 
43
tempfiles=
 
44
trap 'rm -f $tempfiles' 0 1 2 13 15
 
45
 
 
46
infile=$(mktemp -t pstopdf.XXXXXX)
 
47
tempfiles="$tempfiles $infile"
 
48
 
 
49
cat >"$infile"
 
50
 
 
51
# Did CUPS already take care of the number of copies? If not, we have to do it
 
52
 
 
53
donumcopies=
 
54
numcopies="$4"
 
55
if test -z "$numcopies"; then
 
56
    numcopies=1
 
57
fi
 
58
if test "$numcopies" -le "1"; then
 
59
    donumcopies="-dDoNumCopies"
 
60
fi
 
61
 
 
62
# Apply PPD settings.
 
63
 
 
64
resolution=
 
65
eval "$(printf "%s" "$5" | sed -nre 's/.*(^|\s)Resolution=([0-9.]+(x[0-9.]+)?).*/resolution="${resolution:-\2}"/p')"
 
66
if test -e "$PPD"; then
 
67
  eval "$(sed -nre 's/^\*DefaultResolution:\s*([0-9.]+(x[0-9.]+)?).*/resolution="${resolution:-\1}"/p' "$PPD")"
 
68
fi
 
69
echo "DEBUG: Resolution: $resolution" >&2
 
70
 
 
71
if test -n "$resolution"; then
 
72
  # If the resolution is not symmetric, use the lower of the two,
 
73
  # Ghostscript developers recommend to use square resolutions for the
 
74
  # pdfwrite and ps2write output devices.
 
75
  # See http://bugs.ghostscript.com/show_bug.cgi?id=690504
 
76
  xres=
 
77
  yres=
 
78
  eval "$(printf "%s" "$resolution" | sed -nre 's/.*(^|\s)([0-9]+)x([0-9]+).*/xres="\2"; yres="\3"/p')"
 
79
  if test -n "$xres" && test -n "$yres"; then
 
80
    if [ "$xres" -lt "$yres" ]; then
 
81
      resolution=$xres
 
82
    else
 
83
      resolution=$yres
 
84
    fi
 
85
  fi
 
86
fi
 
87
 
 
88
width=
 
89
height=
 
90
bl_x=
 
91
bl_y=
 
92
tr_x=
 
93
tr_y=
 
94
margin_l=
 
95
margin_b=
 
96
margin_r=
 
97
margin_t=
 
98
pagesize=
 
99
unit=
 
100
customw=
 
101
customh=
 
102
eval "$(printf "%s" "$5" | sed -nre 's/.*(^|\s)(PageSize|PageRegion)=(\S+).*/pagesize="${pagesize:-\3}"/p')"
 
103
if test -e "$PPD"; then
 
104
    eval "$(sed -nre 's/^\*DefaultPageSize:\s*(\S+).*/pagesize="${pagesize:-\1}"/p' "$PPD")"
 
105
fi
 
106
echo "DEBUG: Page size: $pagesize" >&2
 
107
 
 
108
eval "$(printf "%s" "$pagesize" | sed -nre 's/^Custom\.([0-9\.]+)x([0-9\.]+)(\S*)$/customw="\1"; customh="\2"; unit="\3"/p')"
 
109
 
 
110
if test -n "$customw" && test -n "$customh"; then
 
111
    echo "DEBUG: Custom page size: $customw x $customh $unit" >&2
 
112
 
 
113
    if test "$unit" = "in"; then
 
114
        width="$(printf "scale=0; (%s)*(72.0)/(1.00)\n" "$customw" | bc)" 
 
115
        height="$(printf "scale=0; (%s)*(72.0)/(1.00)\n" "$customh" | bc)"
 
116
    elif test "$unit" = "cm"; then
 
117
        width="$(printf "scale=0; (%s)*(72.0)/(2.54)\n" "$customw" | bc)" 
 
118
        height="$(printf "scale=0; (%s)*(72.0)/(2.54)\n" "$customh" | bc)"
 
119
    elif test "$unit" = "mm"; then
 
120
        width="$(printf "scale=0; (%s)*(72.0)/(25.4)\n" "$customw" | bc)" 
 
121
        height="$(printf "scale=0; (%s)*(72.0)/(25.4)\n" "$customh" | bc)"
 
122
    else
 
123
        width="$(printf "scale=0; (%s)/(1.00)\n" "$customw" | bc)" 
 
124
        height="$(printf "scale=0; (%s)/(1.00)\n" "$customh" | bc)"
 
125
    fi
 
126
 
 
127
    if test -e "$PPD"; then
 
128
        eval "$(sed -nre 's|^\*HWMargins:\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*|bl_x="\1"; bl_y="\2"; tr_x="\3"; tr_y="\4"|p' "$PPD")"
 
129
 
 
130
        if test -n "$tr_x"; then
 
131
            tr_x="$(printf "scale=8; (%s)-(%s)\n" "$width" "$tr_x" | bc)"
 
132
        fi
 
133
        if test -n "$tr_y"; then
 
134
            tr_y="$(printf "scale=8; (%s)-(%s)\n" "$height" "$tr_y" | bc)"
 
135
        fi
 
136
    fi
 
137
elif test -n "$pagesize" && test -e "$PPD"; then
 
138
    eval "$(sed -nre 's|^\*PaperDimension\s+'"$pagesize"'(/[^:]+\|):\s*"(\S+)\s+(\S+)".*|width="\2"; height="\3"|p' "$PPD")"
 
139
 
 
140
    eval "$(sed -nre 's|^\*ImageableArea\s+'"$pagesize"'(/[^:]+\|):\s*"(\S+)\s+(\S+)\s+(\S+)\s+(\S+)".*|bl_x="\2"; bl_y="\3"; tr_x="\4"; tr_y="\5"|p' "$PPD")"
 
141
fi
 
142
 
 
143
test -n "$bl_x" || bl_x=0
 
144
test -n "$bl_y" || bl_y=0
 
145
test -n "$tr_x" || tr_x=$width
 
146
test -n "$tr_y" || tr_y=$height
 
147
 
 
148
echo "DEBUG: Width: $width, height: $height, absolute margins: $bl_x, $bl_y, $tr_x, $tr_y" >&2
 
149
 
 
150
if test -n "$width" && test -n "$height" && \
 
151
    test -n "$bl_x" && test -n "$bl_y" && \
 
152
    test -n "$tr_x" && test -n "$tr_y"; then
 
153
    margin_l="$bl_x"
 
154
    margin_b="$bl_y"
 
155
    margin_r="$(printf "scale=8; (%s)-(%s)\n" "$width" "$tr_x" | bc)"
 
156
    margin_t="$(printf "scale=8; (%s)-(%s)\n" "$height" "$tr_y" | bc)"
 
157
fi
 
158
echo "DEBUG: Relative margins: $margin_l, $margin_b, $margin_r, $margin_t" >&2
 
159
 
 
160
if test -n "$margin_l" && test -n "$margin_b" && \
 
161
    test -n "$margin_r" && test -n "$margin_t"; then
 
162
    inject_ps="<</.HWMargins[$margin_l $margin_b $margin_r $margin_t] /Margins[0 0]>>setpagedevice"
 
163
fi
 
164
 
 
165
ppd_opts=
 
166
if test -n "$resolution"; then
 
167
  ppd_opts="${ppd_opts:+$ppd_opts }-r$resolution"
 
168
fi
 
169
if test -n "$width"; then
 
170
  ppd_opts="${ppd_opts:+$ppd_opts }-dDEVICEWIDTHPOINTS=$width"
 
171
fi
 
172
if test -n "$height"; then
 
173
  ppd_opts="${ppd_opts:+$ppd_opts }-dDEVICEHEIGHTPOINTS=$height"
 
174
fi
 
175
echo "DEBUG: PPD options: $ppd_opts" >&2
 
176
 
 
177
# We do not supply the margins to the ps2pdf process, as this breaks
 
178
# full-bleed printing and also disturbs the printing if PPDs have too
 
179
# conservative margin definitions.
 
180
inject_ps=
 
181
 
 
182
# Injection
 
183
echo "DEBUG: PostScript to be injected: $inject_ps" >&2
 
184
if test -n "$inject_ps"; then
 
185
  echo "DEBUG: Injecting PostScript: $inject_ps" >&2
 
186
 
 
187
  orig_infile="$infile"
 
188
 
 
189
  infile=$(mktemp -t pstopdf.XXXXXX)
 
190
  tempfiles="$tempfiles $infile"
 
191
 
 
192
  perl -p -e 'if (! $did) { s:(^%!.*)$:\1\n'"$inject_ps"': && $did++; }' "$orig_infile" > "$infile"
 
193
fi
 
194
 
 
195
# DRM
 
196
 
 
197
DRM_MATCH='^%.*Removing the following.*lines is illegal.*Digital Copyright Act'
 
198
if egrep -q "$DRM_MATCH" "$infile"; then
 
199
  # This PS is DRM-infested. Normalize it with ps2ps first.
 
200
  echo "DEBUG: Normalizing Adobe Reader PostScript with ps2ps" >&2
 
201
 
 
202
  DRMFILTER="$PS2PS $PS2PS_OPTIONS $ppd_opts - -"
 
203
else
 
204
  DRMFILTER=cat
 
205
fi
 
206
 
 
207
echo "DEBUG: Running $DRMFILTER | $GS $PS2PDF_OPTIONS $donumcopies $ppd_opts -sOutputFile=- $OPTIONS -c .setpdfwrite -f -" >&2
 
208
cat "$infile" | $DRMFILTER | $GS $PS2PDF_OPTIONS $donumcopies $ppd_opts -sOutputFile=- $OPTIONS -c .setpdfwrite -f -