jävla svenskar
[llpp.git] / misc / llppac
blob280209b444a3c7aec9520ff6500020d9c39ec7ed
1 #!/bin/sh
2 set -e
4 die() {
5 echo "$1" >&2
6 exit 1
9 cachedir="${XDG_CACHE_HOME:-$HOME/.cache}/llpp"
10 test -d "$cachedir" || die "cache directory '$cachedir' does not exist"
12 caspsuf=
13 type=
15 executable_p() {
16 command -v "$1" >/dev/null 2>&1
19 missing() {
20 executable_p $1 || \
21 eval "$1() { die \"$2 is needed for \$type conversion\"; }"
24 text() {
25 # ibm plex mono = ~ S9 З3 align
26 # droid sans mono = ~ S9 З3
27 # input mono = S9 З3 -Wvla didn't
28 # fira mono = S9
29 # pt mono = ~ plan
30 # anonymous pro = life З3
31 # camingo code = S9
32 # roboto mono
33 # | anonymous pro = ЁЖЗ
34 # source code pro = S9
35 # tex gyre cursor = ~
36 # ubuntu mono = ~ S9 З3
37 # go mono = З3 align
38 # everson mono = З3 life 0 ~
39 cat <<EOF
40 <pre style="font-size: ${1}pt;">
41 === $1 ===
42 S9 З3 align
44 ЁЖЗ
46 abcdefghizklmnopqrstwxyz
47 ABCDEFGHIZKLMNOPQRSTWXYZ
48 абвгдеёжзийклмнопрстуфхцчшщэюя
49 АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЭЮЯ
50 \`1234567890-=\\
51 ~!@#\$$%^&*()_+|
52 [];',./
53 {}:"&lt;&gt;?"
54 S in S9 59 S9 is like 5
55 3ЗЭэзээз3ЗqgO0o ijklI1| bgqpykvwlliliiijil1
56 01234567890 3ДС ЗДС
57 rnrmnnmrrrnmmr
58 Apay Арау
59 - - (~-) ~ ~ (-~)
60 curly vs plain braces {} () {}
62 kerning
63 echo \${@:5}
64 life [l i fe]
65 weird [we i rd]
66 Before [Bef ore, Be for e]
67 higher [gh, h i gher, hi gher]
68 multi [mu lti]
69 language [an]
70 plan [la]
71 when [wh]
72 kerning [rn]
73 мне [мн е]
74 oiled [oi led]
75 mkfifo [mk f i fo, mk f i fo]
76 didn't [di dn't]
77 argumnet (sic) []
78 more [mo re]
79 CmmCall [CmmC a l l]
80 -Wvla [-Wv la]
81 align [a l i gn]
83 almost kerning
84 hope doesn't
85 Illegal
86 automatically effective
88 (from UTF8-demo.txt)
89 Box drawing alignment tests: █
90
91 ╔══╦══╗ ┌──┬──┐ ╭──┬──╮ ╭──┬──╮ ┏━━┳━━┓ ┎┒┏┑ ╷ ╻ ┏┯┓ ┌┰┐ ▊ ╱╲╱╲╳╳╳
92 ║┌─╨─┐║ │╔═╧═╗│ │╒═╪═╕│ │╓─╁─╖│ ┃┌─╂─┐┃ ┗╃╄┙ ╶┼╴╺╋╸┠┼┨ ┝╋┥ ▋ ╲╱╲╱╳╳╳
93 ║│╲ ╱│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╿ │┃ ┍╅╆┓ ╵ ╹ ┗┷┛ └┸┘ ▌ ╱╲╱╲╳╳╳
94 ╠╡ ╳ ╞╣ ├╢ ╟┤ ├┼─┼─┼┤ ├╫─╂─╫┤ ┣┿╾┼╼┿┫ ┕┛┖┚ ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳
95 ║│╱ ╲│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╽ │┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▎
96 ║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏
97 ╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ ▗▄▖▛▀▜ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█
98 ▝▀▘▙▄▟
99 </pre>
103 maketext() {
104 # https://github.com/react-boilerplate/react-boilerplate/issues/1340
105 test -d "$cachedir/fonts" || mkdir "$cachedir/fonts"
106 filename="$(basename $1)"
107 cat >"$cachedir/fonts/text.html" <<EOF
108 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
109 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
110 <html>
111 <head>
112 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
113 <title>$filename</title>
114 <style type="text/css">
115 @font-face {
116 font-family: moo;
117 src: url('$1');
119 pre {
120 font-family: moo;
122 </style>
123 </head>
124 $filename
125 <body>
127 #for size in 8; do
128 for size in 6 8 10 12 4 2; do
129 text $size >>"$cachedir/fonts/text.html"
130 done;
131 cat >>"$cachedir/fonts/text.html" <<EOF
132 <br/>
133 $(fc-scan -f '%{fullname} %{style} %{slant} %{file} %{fontversion} %{capability} %{lang}' "$1" || file "$1")
134 </body>
135 </html>
139 trap 'test -n "$casp" && rm -f "$casp"' 0
141 while getopts c:m:t:fu opt; do
142 case $opt in
143 m) mime=$OPTARG;;
144 t) type=$OPTARG;;
145 f) force=true;;
146 c) css="-s $OPTARG";;
147 u) usemupdf=true;;
148 ?) die "usage: $0 [-c css] [-m mime/type] [-t filter] [-f] [path|url]";;
149 esac
150 done
151 shift $(($OPTIND - 1))
152 test -z "$1" && die "usage $0: path"
154 origin="$1"
155 if ${force-test ! -e "$1"} && expr >/dev/null "$1" : "\(ftp\|https\?\)://"; then
156 if executable_p wget; then
157 dl() {
158 wget -q $1 -O $2
160 elif executable_p curl; then
161 dl() {
162 curl $1 -o $2
164 else
165 die "no program to fetch remote urls found"
168 md5of="$cachedir/$(basename "$1")"
169 dl "$1" "$md5of" || test -e "$md5of"
170 shift
171 set -- "$md5of" "$@"
172 else
173 md5of="$1"
176 test -z "$type" && {
177 ft=$(file -L --mime-type -b "$1") || die "$ft"
180 case $ft in
181 application/x-gzip | application/x-compress) dc=zcat;;
182 application/x-xz) dc=xzcat;;
183 application/x-bzip2) dc=bzcat;;
184 *) unset dc || true;;
185 esac
187 filt='"${dc-cat}" "$1" |'
189 if test -z "$type"; then
190 test -z "$mime" && mime=$(file -L --mime-type -bz "$1" || die "$mime")
191 case $mime in
192 application/postscript) type=ps;;
193 application/pdf) type=pdf;;
194 image/vnd.djvu) type=djvu;;
195 text/html) type=html;;
196 text/plain) type=text;;
197 application/msword) type=word;;
198 application/vnd.openxmlformats-officedocument.* \
199 | application/vnd.ms-powerpoint \
200 | application/vnd.ms-excel \
201 | application/vnd.oasis.opendocument.*) type=uno;;
202 image/svg+xml) type=svg;;
203 image/png | image/jpeg) test -n "$dc" && type="image" || type="image2";;
204 image/*) type=image;;
205 application/x-dvi) type=dvi;;
206 application/x-font-ttf \
207 | application/vnd.ms-opentype \
208 | application/font-sfnt) type=font;;
209 *) die "unhandled file type: '$mime'";;
210 esac
213 caspsuf=".pdf"
214 case $type in
215 ps) conv='ps2pdf - "$casp"';;
216 image2|pdf) test -z "$dc" && exec llpp "$@" || conv='cat >"$casp"';;
217 texi) {
218 missing texi2html "texi2html(http://www.nongnu.org/texi2html/)"
219 missing prince "PrinceXML(http://www.princexml.com/)"
220 conv='texi2html - -o - | prince $css - -o "$casp"'
222 djvu) {
223 missing ddjvu "ddjvu(http://djvu.sourceforge.net/doc/man/ddjvu.html)"
224 conv='ddjvu -format=pdf - "$casp"'
226 html) {
227 missing prince "PrinceXML(http://www.princexml.com/)"
228 conv='prince $css - -o "$casp"'
230 html2epub) {
231 missing pandoc "pandoc(http://pandoc.org)"
232 caspsuf=".epub"
233 conv='pandoc -r html - -w epub -o "$casp"'
235 word) {
236 if executable_p unoconv && test -z "$dc"; then
237 unset filt
238 conv='unoconv -o "$casp" "$1"'
239 else
240 missing antiword "antiword or unoconv"
241 conv='antiword -m 8859-1.txt -a a4 - >"$casp"'
244 uno) {
245 test -n "$dc" && die "cannot convert compressed '$mime'"
246 unset filt
247 missing unoconv "unoconv(http://dag.wiee.rs/home-made/unoconv/)"
248 conv='unoconv -o "$casp" "$1"'
250 svg) {
251 if executable_p inkscape && test -z "$dc"; then
252 unset filt
253 conv='inkscape -z -A "$casp" "$1"'
254 else
255 missing rsvg-convert "rsvg-convert"
256 conv='rsvg-convert -f pdf -o "$casp"'
259 font) {
260 if test -z $usemupdf; then
261 v="llpp -origin $1"
262 else
263 mupdf=$HOME/x/rcs/git/mupdf/build/native/mupdf-gl
264 executable_p $mupdf || v=mupdf-gl && v=$mupdf
266 maketext "$1"
267 exec $v "$cachedir/fonts/text.html"
269 image) {
270 missing convert "convert(http://www.imagemagick.org/script/convert.php)"
271 conv='convert - pdf:"$casp"'
273 dvi) {
274 test -n "$dc" && die "cannot convert compressed '$mime'"
275 unset filt
276 missing dvipdf "dvipdf(http://ghostscript.com/)"
277 conv='dvipdf "$1" "$casp"'
279 text) {
280 missing pandoc "pandoc(http://pandoc.org/)"
281 conv='pandoc -t epub - -o "$casp"'
282 caspsuf=.epub
284 *) die "unhandled filter type: '$type'";;
285 esac
287 hash=$(md5sum "$md5of") || die "$hash"
288 casp=$cachedir/${hash%% *}$caspsuf
290 { test -n "$force" || test ! -e "$casp"; } && eval "$filt" "$conv"
291 shift
293 exec llpp -origin $origin "$@" "$casp"