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 test -d "$cachedir/fonts" || mkdir
"$cachedir/fonts"
21 cat >"$cachedir/fonts/text" <<EOF
22 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
23 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
24 minim veniam, quis nostrud exercitation ullamco laboris nisi ut
25 aliquip ex ea commodo consequat. Duis aute irure dolor in
26 reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
27 pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
28 culpa qui officia deserunt mollit anim id est laborum.
29 Posting Soccer Goals On Vine Is Illegal, Say England's Premier League
30 abcdefghizklmnopqrstwxyz
31 ABCDEFGHIZKLMNOPQRSTWXYZ
40 trap 'test -n "$casp" && rm -f "$casp"' 0
42 while getopts m
:t
:f opt
; do
47 ?
) die
"usage: $0 [-m mime/type] [-t filter] [-f] [path|url]";;
50 shift $
(($OPTIND - 1))
51 test -z "$1" && die
"usage $0: path"
53 if test ! -e "$1" && expr >/dev
/null
"$1" : "\(ftp\|https\?\)://"; then
54 if executable_p wget
; then
56 wget
-q -c -nc $1 -O $2
58 elif executable_p curl
; then
63 die
"no program to fetch remote urls found"
66 md5of
="$cachedir/$(basename "$1")"
67 dl
"$1" "$md5of" ||
test -e "$md5of"
68 set -- "$md5of" ${2+"@"}
74 ft
=$
(file -L --mime-type -b "$1") || die
"$ft"
78 application
/x-gzip | application
/x-compress
) dc=zcat
;;
79 application
/x-xz
) dc=xzcat
;;
80 application
/x-bzip2
) dc=bzcat
;;
84 filt
='"${dc-cat}" "$1" |'
86 if test -z "$type"; then
87 test -z "$dc" || ft
=$
(file -L --mime-type -bz "$1") || die
"$ft"
91 application
/postscript
) type=ps
;;
92 application
/pdf
) type=pdf
;;
93 image
/vnd.djvu
) type=djvu
;;
94 text
/html
) type=html
;;
95 application
/msword
) type=word
;;
96 application
/vnd.openxmlformats-officedocument.
* \
97 | application
/vnd.ms-powerpoint \
98 | application
/vnd.ms-excel \
99 | application
/vnd.oasis.opendocument.
*) type=uno
;;
100 image
/svg
+xml
) type=svg
;;
101 image
/png | image
/jpeg
) test -n "$dc" && type="image" ||
type="image2";;
102 image
/*) type=image
;;
103 application
/x-dvi
) type=dvi
;;
104 application
/x-font-ttf | application
/vnd.ms-opentype
) type=font
;;
105 *) die
"unhandled file type: '$mime'";;
110 ps
) conv
='ps2pdf - "$casp"';;
111 image2|pdf
) test -z "$dc" && exec llpp
"$@" || conv
='cat >"$casp"';;
112 djvu
) conv
='djvups - | ps2pdf - "$casp"';;
114 test -n "$dc" && die
"cannot convert compressed '$mime'"
116 conv
='prince "$1" -o "$casp"'
119 if executable_p unoconv
&& test -z "$dc"; then
121 conv
='unoconv -o "$casp" "$1"'
123 conv
='antiword -m 8859-1.txt -a a4 - >"$casp"'
127 test -n "$dc" && die
"cannot convert compressed '$mime'"
129 conv
='unoconv -o "$casp" "$1"'
132 executable_p rsvg-convert \
133 && conv
='rsvg-convert -f pdf -o "$casp"' \
134 || conv
='inkscape -z -A "$casp" -'
137 if test -e "$2"; then
140 arg
="--waterfall $cachedir/fonts/text"
143 # https://mail.gnome.org/archives/gtk-i18n-list/2010-June/msg00000.html
144 eval $filt cat >$cachedir/fonts
/font
145 cat >$cachedir/fonts
/fonts.conf
<<EOF
146 <?xml version="1.0"?>
147 <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
149 <dir>$cachedir/fonts/</dir>
150 <cachedir>$cachedir/fonts/</cachedir>
155 conv
='FONTCONFIG_PATH=$cachedir/fonts/ pango-view -q $arg -o $casp'
159 if test -e "$2"; then
162 arg
="--waterfall $cachedir/fonts/text"
165 conv
='pango-view --font="$1" -q $arg -o $casp'
171 image
) conv
='convert - pdf:"$casp"';;
173 test -n "$dc" && die
"cannot convert compressed '$mime'"
175 conv
='dvipdf "$1" "$casp"'
177 *) die
"unhandled filter type: '$type'";;
180 hash=$
(md5sum "$md5of") || die
"$hash"
181 casp
=$cachedir/${hash%% *}$caspsuf
182 (test -n "$force" -o ! -e "$casp") && eval "$filt" "$conv"
184 exec llpp
-origin "$@" "$casp"