4 CACHEDIR
=$HOME/.cache
/llpp
14 command -v "$1" >/dev
/null
2>&1
18 cat >"$CACHEDIR/fonts/text" <<EOF
19 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
20 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
21 minim veniam, quis nostrud exercitation ullamco laboris nisi ut
22 aliquip ex ea commodo consequat. Duis aute irure dolor in
23 reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
24 pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
25 culpa qui officia deserunt mollit anim id est laborum.
26 abcdefghizklmnopqrstwxyz
27 ABCDEFGHIZKLMNOPQRSTWXYZ
37 trap 'test -n "$casp" && rm -f "$casp"' 0
39 test -d "$CACHEDIR" || die
"cache directory '$CACHEDIR' does not exist"
40 while getopts m
:t
:f opt
; do
45 ?
) die
"usage: $0 [-m mime/type] [-t filter] [-f] path";;
48 shift $
(($OPTIND - 1))
49 test -z "$1" && die
"usage $0: path"
52 ft
=$
(file -L --mime-type -b "$1") || die
"$ft"
56 application
/x-gzip | application
/x-compress
) dc=zcat
;;
57 application
/x-xz
) dc=xzcat
;;
58 application
/x-bzip2
) dc=bzcat
;;
62 filt
='"${dc-cat}" "$1" |'
64 if test -z "$type"; then
65 test -z "$dc" || ft
=$
(file -L --mime-type -bz "$1") || die
"$ft"
69 application
/postscript
) type=ps
;;
70 application
/pdf
) type=pdf
;;
71 image
/vnd.djvu
) type=djvu
;;
72 text
/html
) type=html
;;
73 application
/msword
) type=word
;;
74 application
/vnd.openxmlformats-officedocument.
* \
75 | application
/vnd.ms-powerpoint \
76 | application
/vnd.ms-excel \
77 | application
/vnd.oasis.opendocument.
*) type=uno
;;
78 image
/svg
+xml
) type=svg
;;
79 image
/png | image
/jpeg
) test -n "$dc" && type="image" ||
type="image2";;
81 application
/x-dvi
) type=dvi
;;
82 application
/x-font-ttf | application
/vnd.ms-opentype
) type=font
;;
83 *) die
"unhandled file type: '$mime'";;
88 ps
) conv
='ps2pdf - "$casp"';;
89 image2|pdf
) test -z "$dc" && exec llpp
"$@" || conv
='cat >"$casp"';;
90 djvu
) conv
='djvups - | ps2pdf - "$casp"';;
92 test -n "$dc" && die
"can not convert compressed '$mime'"
94 conv
='prince "$1" -o "$casp"'
97 if executable_p unoconv
&& test -z "$dc"; then
99 conv
='unoconv -o "$casp" "$1"'
101 conv
='antiword -m 8859-1.txt -a a4 - >"$casp"'
105 test -n "$dc" && die
"can not convert compressed '$mime'"
107 conv
='unoconv -o "$casp" "$1"'
110 executable_p rsvg-convert \
111 && conv
='rsvg-convert -f pdf -o "$casp"' \
112 || conv
='inkscape -z -A "$casp" -'
115 if test -e "$2"; then
118 arg
="--waterfall $CACHEDIR/fonts/text"
121 # https://mail.gnome.org/archives/gtk-i18n-list/2010-June/msg00000.html
122 eval $filt cat >$CACHEDIR/fonts
/font
123 cat >$CACHEDIR/fonts
/fonts.conf
<<EOF
124 <?xml version="1.0"?>
125 <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
127 <dir>$CACHEDIR/fonts/</dir>
128 <cachedir>$CACHEDIR/fonts/</cachedir>
133 conv
='FONTCONFIG_PATH=$CACHEDIR/fonts/ pango-view -q $arg -o $casp'
137 if test -e "$2"; then
140 arg
="--waterfall $CACHEDIR/fonts/text"
143 conv
='pango-view --font="$1" -q $arg -o $casp'
149 image
) conv
='convert - pdf:"$casp"';;
151 test -n "$dc" && die
"can not convert compressed '$mime'"
153 conv
='dvipdf "$1" "$casp"'
155 *) die
"unhandled filter type: '$type'";;
158 hash=$
(md5sum "$md5of") || die
"$hash"
159 casp
=$CACHEDIR/${hash%% *}$caspsuf
160 (test -n "$force" -o ! -e "$casp") && eval "$filt" "$conv"
162 exec llpp
-origin "$@" "$casp"