5 CACHEDIR
=$HOME/.cache
/llpp
15 command -v "$1" >/dev
/null
2>&1
19 cat >"$CACHEDIR/fonts/text" <<EOF
20 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
21 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
22 minim veniam, quis nostrud exercitation ullamco laboris nisi ut
23 aliquip ex ea commodo consequat. Duis aute irure dolor in
24 reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
25 pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
26 culpa qui officia deserunt mollit anim id est laborum.
27 abcdefghizklmnopqrstwxyz
28 ABCDEFGHIZKLMNOPQRSTWXYZ
38 trap 'test -n "$casp" && rm -f "$casp"' 0
40 test -d "$CACHEDIR" || die
"cache directory '$CACHEDIR' does not exist"
41 while getopts m
:t
:f opt
; do
46 ?
) die
"usage: $0 [-m mime/type] [-t filter] [-f] path";;
49 shift $
(($OPTIND - 1))
50 test -z "$1" && die
"usage $0: path"
53 $ft=$
(file -L --mime-type -b "$1") || die
"$ft"
57 application
/x-gzip | application
/x-compress
) dc=zcat
;;
58 application
/x-xz
) dc=xzcat
;;
59 application
/x-bzip2
) dc=bzcat
;;
63 filt
='"${dc-cat}" "$1" |'
65 if test -z "$type"; then
66 test -z "$dc" || ft
=$
(file -L --mime-type -bz "$1") || die
"$ft"
70 application
/postscript
) type=ps
;;
71 application
/pdf
) type=pdf
;;
72 image
/vnd.djvu
) type=djvu
;;
73 text
/html
) type=html
;;
74 application
/msword
) type=word
;;
75 application
/vnd.openxmlformats-officedocument.
* \
76 | application
/vnd.ms-powerpoint \
77 | application
/vnd.ms-excel \
78 | application
/vnd.oasis.opendocument.
*) type=uno
;;
79 image
/svg
+xml
) type=svg
;;
80 image
/png | image
/jpeg
) test -n "$dc" && type="image" ||
type="image2";;
82 application
/x-dvi
) type=dvi
;;
83 application
/x-font-ttf | application
/vnd.ms-opentype
) type=font
;;
84 *) die
"unhandled file type: '$mime'";;
89 ps
) conv
='ps2pdf - "$casp"';;
90 image2|pdf
) test -z "$dc" && exec llpp
"$@" || conv
='cat >"$casp"';;
91 djvu
) conv
='djvups - | ps2pdf - "$casp"';;
93 test -n "$dc" && die
"can not convert compressed '$mime'"
95 conv
='prince "$1" -o "$casp"'
98 if executable_p unoconv
&& test -z "$dc"; then
100 conv
='unoconv -o "$casp" "$1"'
102 conv
='antiword -m 8859-1.txt -a a4 - >"$casp"'
106 test -n "$dc" && die
"can not convert compressed '$mime'"
108 conv
='unoconv -o "$casp" "$1"'
111 executable_p rsvg-convert \
112 && conv
='rsvg-convert -f pdf -o "$casp"' \
113 || conv
='inkscape -z -A "$casp" -'
116 if test -e "$2"; then
119 arg
="--waterfall $CACHEDIR/fonts/text"
122 # https://mail.gnome.org/archives/gtk-i18n-list/2010-June/msg00000.html
123 eval $filt cat >$CACHEDIR/fonts
/font
124 cat >$CACHEDIR/fonts
/fonts.conf
<<EOF
125 <?xml version="1.0"?>
126 <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
128 <dir>$CACHEDIR/fonts/</dir>
129 <cachedir>$CACHEDIR/fonts/</cachedir>
134 conv
='FONTCONFIG_PATH=$CACHEDIR/fonts/ pango-view -q $arg -o $casp'
138 if test -e "$2"; then
141 arg
="--waterfall $CACHEDIR/fonts/text"
144 conv
='pango-view --font="$1" -q $arg -o $casp'
150 image
) conv
='convert - pdf:"$casp"';;
152 test -n "$dc" && die
"can not convert compressed '$mime'"
154 conv
='dvipdf "$1" "$casp"'
156 *) die
"unhandled filter type: '$type'";;
159 hash=$
(md5sum "$md5of") || die
"$hash"
160 casp
=$CACHEDIR/${hash%% *}$caspsuf
161 (test -n "$force" -o ! -e "$casp") && eval "$filt" "$conv"
163 exec llpp
-origin "$@" "$casp"