Update anonymous pro add input mono
[llpp.git] / misc / llppac
blob814d4d294c66b87369a7ced15bfa639fbe2b8a83
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 = ~
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 when [wh]
71 kerning [rn]
72 мне [мн е]
73 oiled [oi led]
74 mkfifo [mk f i fo, mk f i fo]
75 didn't [di dn't]
76 argumnet (sic) []
77 more [mo re]
78 CmmCall [CmmC a l l]
79 -Wvla [-Wv la]
80 align [a l i gn]
82 almost kerning
83 hope doesn't
84 Illegal
85 automatically effective
87 (from UTF8-demo.txt)
88 Box drawing alignment tests: █
89
90 ╔══╦══╗ ┌──┬──┐ ╭──┬──╮ ╭──┬──╮ ┏━━┳━━┓ ┎┒┏┑ ╷ ╻ ┏┯┓ ┌┰┐ ▊ ╱╲╱╲╳╳╳
91 ║┌─╨─┐║ │╔═╧═╗│ │╒═╪═╕│ │╓─╁─╖│ ┃┌─╂─┐┃ ┗╃╄┙ ╶┼╴╺╋╸┠┼┨ ┝╋┥ ▋ ╲╱╲╱╳╳╳
92 ║│╲ ╱│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╿ │┃ ┍╅╆┓ ╵ ╹ ┗┷┛ └┸┘ ▌ ╱╲╱╲╳╳╳
93 ╠╡ ╳ ╞╣ ├╢ ╟┤ ├┼─┼─┼┤ ├╫─╂─╫┤ ┣┿╾┼╼┿┫ ┕┛┖┚ ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳
94 ║│╱ ╲│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╽ │┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▎
95 ║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏
96 ╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ ▗▄▖▛▀▜ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█
97 ▝▀▘▙▄▟
98 </pre>
99 EOF
102 maketext() {
103 # https://github.com/react-boilerplate/react-boilerplate/issues/1340
104 test -d "$cachedir/fonts" || mkdir "$cachedir/fonts"
105 cat >"$cachedir/fonts/text.html" <<EOF
106 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
107 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
108 <html>
109 <head>
110 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
111 <title>test</title>
112 <style type="text/css">
113 @font-face {
114 font-family: moo;
115 src: url('$1');
117 pre {
118 font-family: moo;
120 </style>
121 </head>
123 $(basename $1)
125 #for size in 8; do
126 for size in 6 8 10 12 4 2; do
127 text $size >>"$cachedir/fonts/text.html"
128 done;
129 cat >>"$cachedir/fonts/text.html" <<EOF
130 </br>
131 $(fc-scan -f '%{fullname} %{style} %{slant} %{file} %{fontversion} %{capability} %{lang}' "$1" || file "$1")
132 </body>
133 </html>
137 trap 'test -n "$casp" && rm -f "$casp"' 0
139 while getopts c:m:t:fu opt; do
140 case $opt in
141 m) mime=$OPTARG;;
142 t) type=$OPTARG;;
143 f) force=true;;
144 c) css="-s $OPTARG";;
145 u) usemupdf=true;;
146 ?) die "usage: $0 [-c css] [-m mime/type] [-t filter] [-f] [path|url]";;
147 esac
148 done
149 shift $(($OPTIND - 1))
150 test -z "$1" && die "usage $0: path"
152 origin="$1"
153 if ${force-test ! -e "$1"} && expr >/dev/null "$1" : "\(ftp\|https\?\)://"; then
154 if executable_p wget; then
155 dl() {
156 wget -q $1 -O $2
158 elif executable_p curl; then
159 dl() {
160 curl $1 -o $2
162 else
163 die "no program to fetch remote urls found"
166 md5of="$cachedir/$(basename "$1")"
167 dl "$1" "$md5of" || test -e "$md5of"
168 shift
169 set -- "$md5of" "$@"
170 else
171 md5of="$1"
174 test -z "$type" && {
175 ft=$(file -L --mime-type -b "$1") || die "$ft"
178 case $ft in
179 application/x-gzip | application/x-compress) dc=zcat;;
180 application/x-xz) dc=xzcat;;
181 application/x-bzip2) dc=bzcat;;
182 *) unset dc || true;;
183 esac
185 filt='"${dc-cat}" "$1" |'
187 if test -z "$type"; then
188 test -z "$mime" && mime=$(file -L --mime-type -bz "$1" || die "$mime")
189 case $mime in
190 application/postscript) type=ps;;
191 application/pdf) type=pdf;;
192 image/vnd.djvu) type=djvu;;
193 text/html) type=html;;
194 text/plain) type=text;;
195 application/msword) type=word;;
196 application/vnd.openxmlformats-officedocument.* \
197 | application/vnd.ms-powerpoint \
198 | application/vnd.ms-excel \
199 | application/vnd.oasis.opendocument.*) type=uno;;
200 image/svg+xml) type=svg;;
201 image/png | image/jpeg) test -n "$dc" && type="image" || type="image2";;
202 image/*) type=image;;
203 application/x-dvi) type=dvi;;
204 application/x-font-ttf \
205 | application/vnd.ms-opentype \
206 | application/font-sfnt) type=font;;
207 *) die "unhandled file type: '$mime'";;
208 esac
211 caspsuf=".pdf"
212 case $type in
213 ps) conv='ps2pdf - "$casp"';;
214 image2|pdf) test -z "$dc" && exec llpp "$@" || conv='cat >"$casp"';;
215 texi) {
216 missing texi2html "texi2html(http://www.nongnu.org/texi2html/)"
217 missing prince "PrinceXML(http://www.princexml.com/)"
218 conv='texi2html - -o - | prince $css - -o "$casp"'
220 djvu) {
221 missing ddjvu "ddjvu(http://djvu.sourceforge.net/doc/man/ddjvu.html)"
222 conv='ddjvu -format=pdf - "$casp"'
224 html) {
225 missing prince "PrinceXML(http://www.princexml.com/)"
226 conv='prince $css - -o "$casp"'
228 html2epub) {
229 missing pandoc "pandoc(http://pandoc.org)"
230 caspsuf=".epub"
231 conv='pandoc -r html - -w epub -o "$casp"'
233 word) {
234 if executable_p unoconv && test -z "$dc"; then
235 unset filt
236 conv='unoconv -o "$casp" "$1"'
237 else
238 missing antiword "antiword or unoconv"
239 conv='antiword -m 8859-1.txt -a a4 - >"$casp"'
242 uno) {
243 test -n "$dc" && die "cannot convert compressed '$mime'"
244 unset filt
245 missing unoconv "unoconv(http://dag.wiee.rs/home-made/unoconv/)"
246 conv='unoconv -o "$casp" "$1"'
248 svg) {
249 if executable_p inkscape && test -z "$dc"; then
250 unset filt
251 conv='inkscape -z -A "$casp" "$1"'
252 else
253 missing rsvg-convert "rsvg-convert"
254 conv='rsvg-convert -f pdf -o "$casp"'
257 font) {
258 if test -z $usemupdf; then
259 v="llpp -origin $1"
260 else
261 mupdf=$HOME/x/rcs/git/mupdf/build/native/mupdf-gl
262 executable_p $mupdf || v=mupdf-gl && v=$mupdf
264 maketext "$1"
265 exec $v "$cachedir/fonts/text.html"
267 image) {
268 missing convert "convert(http://www.imagemagick.org/script/convert.php)"
269 conv='convert - pdf:"$casp"'
271 dvi) {
272 test -n "$dc" && die "cannot convert compressed '$mime'"
273 unset filt
274 missing dvipdf "dvipdf(http://ghostscript.com/)"
275 conv='dvipdf "$1" "$casp"'
277 text) {
278 missing pandoc "pandoc(http://pandoc.org/)"
279 conv='pandoc -t epub - -o "$casp"'
280 caspsuf=.epub
282 *) die "unhandled filter type: '$type'";;
283 esac
285 hash=$(md5sum "$md5of") || die "$hash"
286 casp=$cachedir/${hash%% *}$caspsuf
288 { test -n "$force" || test ! -e "$casp"; } && eval "$filt" "$conv"
289 shift
291 exec llpp -origin $origin "$@" "$casp"