~ubuntu-branches/ubuntu/jaunty/cups/jaunty

« back to all changes in this revision

Viewing changes to debian/filters/pstopdf

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt, Till Kamppeter, Martin Pitt
  • Date: 2009-02-15 18:39:03 UTC
  • mfrom: (6.1.30 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090215183903-i0nhvqyqj4vyn52a
Tags: 1.3.9-13
[ Till Kamppeter ]
* debian/local/filters/pdf-filters/filter/imagetopdf.c: Added support for
  the new "fit-to-page" option (new, more intuitive name for "fitplot").
* debian/filters/pstopdf: Only apply paper size if the "fitplot" or the
  "fit-to-page" option is set.
* debian/local/filters/cpdftocps: Only the last digit of the number of
  copies was used (LP: #309314).
* debian/local/filters/pdf-filters/pdftopdf/pdftopdf.cxx: Do not preceed the
  PDF output with a newline (LP: #303691). Only impose the page size from
  the PPD file to all pages if the "fitplot" or the "fit-to-page" option is 
  set. This prevented from automatic paper tray switching to the correct paper
  sizes when a multiple-page-size document is printed (partial fix for
  LP: #310575).
* debian/patches/pdftops-cups-1.4.dpatch: Updated from CUPS 1.4 SVN. Contains
  fixes for multiple-page-size document printing (partial fix for
  LP: #310575).
* debian/patches/pdftops-dont_fail_on_cancel.dpatch: Removed, should be
  fixed in the new upstream version of pdftops.

[ Martin Pitt ]
* debian/patches/pdftops-cups-1.4.dpatch: Add definition of
  HAVE_PDFTOPS and CUPS_PDFTOPS, so that the filter actually gets
  again built with pdftops support. (Fixes Till's change from above).

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
set -e
15
15
 
16
 
PSTOPDF=/usr/bin/ps2pdf13
17
 
OPTIONS="-r150 -dAutoRotatePages=/None -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dNOPLATFONTS"
 
16
PS2PS=/usr/bin/ps2ps
 
17
PS2PDF=/usr/bin/ps2pdf13
 
18
PS2PS_OPTIONS="-dAutoRotatePages=/None -dAutoFilterColorImages=false \
 
19
               -dNOPLATFONTS -dPARANOIDSAFER -sstdout=%stderr"
 
20
PS2PDF_OPTIONS="$PS2PS_OPTIONS -dColorImageFilter=/FlateEncode \
 
21
               -dPDFSETTINGS=/printer"
18
22
 
19
 
echo "INFO: pstopdf argv[$#] = $@" >&2
 
23
echo "DEBUG: pstopdf $# args: $@" >&2
 
24
echo "DEBUG: PPD: $PPD" >&2
20
25
 
21
26
if [ $# -lt 5 -o $# -gt 6 ]; then
22
27
 
25
30
 
26
31
fi
27
32
 
28
 
jobid="$1"
29
 
outfile=$(mktemp "${TMPDIR:-/tmp}/$jobid.pstopdf.out.XXXXXX")
30
 
trap 'rm -f "$outfile"' 0 1 2 13 15
31
 
 
32
 
infile="${6:--}"
33
 
 
34
 
$PSTOPDF $OPTIONS "$infile" "$outfile" >&2
35
 
 
36
 
cat "$outfile"
37
 
 
 
33
# Read from given file.
 
34
if [ -n "$6" ]; then
 
35
  exec <"$6"
 
36
fi
 
37
 
 
38
tempfiles=
 
39
trap 'rm -f $tempfiles' 0 1 2 13 15
 
40
 
 
41
infile=$(mktemp -t pstopdf.XXXXXX)
 
42
tempfiles="$tempfiles $infile"
 
43
 
 
44
cat >"$infile"
 
45
 
 
46
# Apply PPD settings.
 
47
 
 
48
resolution=
 
49
eval "$(printf "%s" "$5" | sed -nre 's/.*(^|\s)Resolution=([0-9.]+(x[0-9.]+)?).*/resolution="${resolution:-\2}"/p')"
 
50
if test -e "$PPD"; then
 
51
  eval "$(sed -nre 's/^\*DefaultResolution:\s+([0-9.]+(x[0-9.]+)?).*/resolution="${resolution:-\1}"/p' "$PPD")"
 
52
fi
 
53
echo "DEBUG: Resolution: $resolution" >&2
 
54
 
 
55
width=
 
56
height=
 
57
bl_x=
 
58
bl_y=
 
59
tr_x=
 
60
tr_y=
 
61
margin_l=
 
62
margin_b=
 
63
margin_r=
 
64
margin_t=
 
65
# Apply a paper size to the conversion process only if the "fitplot" or
 
66
# "fit-to-page" option is supplied
 
67
if echo "$5" | egrep -q '\b(fitplot|fit-to-page)\b'; then
 
68
    pagesize=
 
69
    eval "$(printf "%s" "$5" | sed -nre 's/.*(^|\s)(media|PageSize)=(\S+).*/pagesize="${pagesize:-\3}"/p')"
 
70
    if test -e "$PPD"; then
 
71
        eval "$(sed -nre 's/^\*DefaultPageSize:\s+(\S+).*/pagesize="${pagesize:-\1}"/p' "$PPD")"
 
72
    fi
 
73
    echo "DEBUG: Page size: $pagesize" >&2
 
74
 
 
75
    if test -n "$pagesize" && test -e "$PPD"; then
 
76
        eval "$(sed -nre 's|^\*PaperDimension\s+'"$pagesize"'/[^:]+:\s+"(\S+)\s+(\S+)".*|width="\1"; height="\2"|p' "$PPD")"
 
77
 
 
78
        eval "$(sed -nre 's|^\*ImageableArea\s+'"$pagesize"'/[^:]+:\s+"(\S+)\s+(\S+)\s+(\S+)\s+(\S+)".*|bl_x="\1"; bl_y="\2"; tr_x="\3"; tr_y="\4"|p' "$PPD")"
 
79
    fi
 
80
    echo "DEBUG: Width: $width, height: $height, absolute margins: $bl_x, $bl_y, $tr_x, $tr_y" >&2
 
81
 
 
82
    if test -n "$width" && test -n "$height" && \
 
83
        test -n "$bl_x" && test -n "$bl_y" && \
 
84
        test -n "$tr_x" && test -n "$tr_y"; then
 
85
        margin_l="$bl_x"
 
86
        margin_b="$bl_y"
 
87
        margin_r="$(printf "scale=8; (%s)-(%s)\n" "$width" "$tr_x" | bc)"
 
88
        margin_t="$(printf "scale=8; (%s)-(%s)\n" "$height" "$tr_y" | bc)"
 
89
    fi
 
90
    echo "DEBUG: Relative margins: $margin_l, $margin_b, $margin_r, $margin_t" >&2
 
91
 
 
92
    if test -n "$margin_l" && test -n "$margin_b" && \
 
93
        test -n "$margin_r" && test -n "$margin_t"; then
 
94
        inject_ps="<</.HWMargins[$margin_l $margin_b $margin_r $margin_t] /Margins[0 0]>>setpagedevice"
 
95
    fi
 
96
fi
 
97
 
 
98
ppd_opts=
 
99
if test -n "$resolution"; then
 
100
  ppd_opts="${ppd_opts:+$ppd_opts }-r$resolution"
 
101
fi
 
102
if test -n "$width"; then
 
103
  ppd_opts="${ppd_opts:+$ppd_opts }-dDEVICEWIDTHPOINTS=$width"
 
104
fi
 
105
if test -n "$height"; then
 
106
  ppd_opts="${ppd_opts:+$ppd_opts }-dDEVICEHEIGHTPOINTS=$height"
 
107
fi
 
108
echo "DEBUG: PPD options: $ppd_opts" >&2
 
109
 
 
110
# We do not supply the margins to the ps2pdf process, as this breaks
 
111
# full-bleed printing and also disturbs the printing if PPDs have too
 
112
# conservative margin definitions.
 
113
inject_ps=
 
114
 
 
115
# Injection
 
116
echo "DEBUG: PostScript to be injected: $inject_ps" >&2
 
117
if test -n "$inject_ps"; then
 
118
  echo "DEBUG: Injecting PostScript: $inject_ps" >&2
 
119
 
 
120
  orig_infile="$infile"
 
121
 
 
122
  infile=$(mktemp -t pstopdf.XXXXXX)
 
123
  tempfiles="$tempfiles $infile"
 
124
 
 
125
  perl -p -e 'if (! $did) { s:(^%!.*)$:\1\n'"$inject_ps"': && $did++; }' "$orig_infile" > "$infile"
 
126
fi
 
127
 
 
128
# DRM
 
129
 
 
130
DRM_MATCH='^%.*Removing the following.*lines is illegal.*Digital Copyright Act'
 
131
if egrep -q "$DRM_MATCH" "$infile"; then
 
132
  # This PS is DRM-infested. Normalize it with ps2ps first.
 
133
  echo "DEBUG: Normalizing Adobe Reader PostScript with ps2ps" >&2
 
134
 
 
135
  DRMFILTER="$PS2PS $PS2PS_OPTIONS $ppd_opts - -"
 
136
else
 
137
  DRMFILTER=cat
 
138
fi
 
139
 
 
140
echo "DEBUG: Running $DRMFILTER | $PS2PDF $PS2PDF_OPTIONS $ppd_opts - -" >&2
 
141
cat "$infile" | $DRMFILTER | $PS2PDF $PS2PDF_OPTIONS $ppd_opts - -