9 cachedir
="${XDG_CACHE_HOME:-$HOME/.cache}/llpp"
10 test -d "$cachedir" || die
"cache directory '$cachedir' does not exist"
16 command -v "$1" >/dev
/null
2>&1
20 cat >"$cachedir/fonts/text" <<EOF
21 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
22 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
23 minim veniam, quis nostrud exercitation ullamco laboris nisi ut
24 aliquip ex ea commodo consequat. Duis aute irure dolor in
25 reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
26 pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
27 culpa qui officia deserunt mollit anim id est laborum.
28 Posting Soccer Goals On Vine Is Illegal, Say England's Premier League
29 abcdefghizklmnopqrstwxyz
30 ABCDEFGHIZKLMNOPQRSTWXYZ
39 trap 'test -n "$casp" && rm -f "$casp"' 0
41 while getopts m
:t
:f opt
; do
46 ?
) die
"usage: $0 [-m mime/type] [-t filter] [-f] [path|url]";;
49 shift $
(($OPTIND - 1))
50 test -z "$1" && die
"usage $0: path"
52 if test ! -e "$1" && expr >/dev
/null
"$1" : "\(ftp\|https\?\)://"; then
53 if executable_p wget
; then
55 wget
-q -c -nc $1 -O $2
57 elif executable_p curl
; then
62 die
"no program to fetch remote urls found"
65 md5of
="$cachedir/$(basename "$1")"
66 dl
"$1" "$md5of" ||
test -e "$md5of"
67 set -- "$md5of" ${2+"@"}
73 ft
=$
(file -L --mime-type -b "$1") || die
"$ft"
77 application
/x-gzip | application
/x-compress
) dc=zcat
;;
78 application
/x-xz
) dc=xzcat
;;
79 application
/x-bzip2
) dc=bzcat
;;
83 filt
='"${dc-cat}" "$1" |'
85 if test -z "$type"; then
86 test -z "$dc" || ft
=$
(file -L --mime-type -bz "$1") || die
"$ft"
90 application
/postscript
) type=ps
;;
91 application
/pdf
) type=pdf
;;
92 image
/vnd.djvu
) type=djvu
;;
93 text
/html
) type=html
;;
94 application
/msword
) type=word
;;
95 application
/vnd.openxmlformats-officedocument.
* \
96 | application
/vnd.ms-powerpoint \
97 | application
/vnd.ms-excel \
98 | application
/vnd.oasis.opendocument.
*) type=uno
;;
99 image
/svg
+xml
) type=svg
;;
100 image
/png | image
/jpeg
) test -n "$dc" && type="image" ||
type="image2";;
101 image
/*) type=image
;;
102 application
/x-dvi
) type=dvi
;;
103 application
/x-font-ttf | application
/vnd.ms-opentype
) type=font
;;
104 *) die
"unhandled file type: '$mime'";;
109 ps
) conv
='ps2pdf - "$casp"';;
110 image2|pdf
) test -z "$dc" && exec llpp
"$@" || conv
='cat >"$casp"';;
111 djvu
) conv
='djvups - | ps2pdf - "$casp"';;
113 test -n "$dc" && die
"cannot convert compressed '$mime'"
115 conv
='prince "$1" -o "$casp"'
118 if executable_p unoconv
&& test -z "$dc"; then
120 conv
='unoconv -o "$casp" "$1"'
122 conv
='antiword -m 8859-1.txt -a a4 - >"$casp"'
126 test -n "$dc" && die
"cannot convert compressed '$mime'"
128 conv
='unoconv -o "$casp" "$1"'
131 executable_p rsvg-convert \
132 && conv
='rsvg-convert -f pdf -o "$casp"' \
133 || conv
='inkscape -z -A "$casp" -'
136 if test -e "$2"; then
139 arg
="--waterfall $cachedir/fonts/text"
142 # https://mail.gnome.org/archives/gtk-i18n-list/2010-June/msg00000.html
143 eval $filt cat >$cachedir/fonts
/font
144 cat >$cachedir/fonts
/fonts.conf
<<EOF
145 <?xml version="1.0"?>
146 <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
148 <dir>$cachedir/fonts/</dir>
149 <cachedir>$cachedir/fonts/</cachedir>
154 conv
='FONTCONFIG_PATH=$cachedir/fonts/ pango-view -q $arg -o $casp'
158 if test -e "$2"; then
161 arg
="--waterfall $cachedir/fonts/text"
164 conv
='pango-view --font="$1" -q $arg -o $casp'
170 image
) conv
='convert - pdf:"$casp"';;
172 test -n "$dc" && die
"cannot convert compressed '$mime'"
174 conv
='dvipdf "$1" "$casp"'
176 *) die
"unhandled filter type: '$type'";;
179 hash=$
(md5sum "$md5of") || die
"$hash"
180 casp
=$cachedir/${hash%% *}$caspsuf
181 (test -n "$force" -o ! -e "$casp") && eval "$filt" "$conv"
183 exec llpp
-origin "$@" "$casp"