Comment
[llpp.git] / misc / llppac
blob0ca812640915d34062569780b9467587fe5ceaff
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 cat <<EOF
26 <pre style="font-size: ${1}pt;">
27 === $1 ===
28 EOF
29 test -n "$2" && cat $2 || cat <<EOF
30 S9 З3 align
32 ЁЖЗ
34 abcdefghijklmnopqrstwxyz
35 ABCDEFGHIJKLMNOPQRSTWXYZ
36 абвгдеёжзийклмнопрстуфхцчшщэюя
37 АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЭЮЯ
38 инпипнишпнипшнипнпншпнпинпипнпипщнпипипин
39 иннициатива
40 Σομε πσθδο γρεεκ
41 \`1234567890-=\\
42 ~!@#\$$%^&*()_+|
43 [];',./
44 {}:"&lt;&gt;?"
45 S in S9 59 S9 is like 5
46 final fjord flair ft
47 3ЗЭэзээз3ЗqgO0o ijklI1| bgqpykvwlliliiijil1 lLLl
48 01234567890 3ДС ЗДС
49 rnrmnnmrrrnmmr
50 Apay Арау
51 - - (~-) ~ ~ (-~)
52 curly vs plain braces {} () {}
54 kerning
55 echo \${@:5}
56 life [l i fe]
57 weird [we i rd]
58 Before [Bef ore, Be for e]
59 higher [gh, h i gher, hi gher]
60 multi [mu lti]
61 till [ti ll]
62 language [an]
63 plan [la]
64 when [wh]
65 kerning [rn | ng]
66 мне [мн е]
67 oiled [oi led]
68 mkfifo [mk f i fo, mk f i fo]
69 didn't [di dn't]
70 argumnet (sic) []
71 more [mo re]
72 CmmCall [CmmC a l l]
73 -Wvla [-Wv la]
74 align [a l i gn]
75 Compiling [Co mp iling]
76 print [pr int]
77 fcmono [f cmono]
78 Mail [M ail]
79 xsrc [x src]
80 Pokorna
81 buildglyphs.js [buil dg lyphs]
82 Dollar [Do ll ar]
83 signed [s i gned]
84 Pine [Pi ne]
85 right [r i ght]
86 ugliness
88 almost kerning
89 hope doesn't
90 Illegal
91 automatically effective
92 Ilium is the Latin for Ilion.
94 (from UTF8-demo.txt)
95 Box drawing alignment tests: █
96
97 ╔══╦══╗ ┌──┬──┐ ╭──┬──╮ ╭──┬──╮ ┏━━┳━━┓ ┎┒┏┑ ╷ ╻ ┏┯┓ ┌┰┐ ▊ ╱╲╱╲╳╳╳
98 ║┌─╨─┐║ │╔═╧═╗│ │╒═╪═╕│ │╓─╁─╖│ ┃┌─╂─┐┃ ┗╃╄┙ ╶┼╴╺╋╸┠┼┨ ┝╋┥ ▋ ╲╱╲╱╳╳╳
99 ║│╲ ╱│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╿ │┃ ┍╅╆┓ ╵ ╹ ┗┷┛ └┸┘ ▌ ╱╲╱╲╳╳╳
100 ╠╡ ╳ ╞╣ ├╢ ╟┤ ├┼─┼─┼┤ ├╫─╂─╫┤ ┣┿╾┼╼┿┫ ┕┛┖┚ ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳
101 ║│╱ ╲│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╽ │┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▎
102 ║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏
103 ╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ ▗▄▖▛▀▜ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█
104 ▝▀▘▙▄▟
106 https://mirrors.zju.edu.cn/CTAN/fonts/gofonts/doc/gofonts.pdf (page 2)
108 DIN Legibility Standard
110 The recent German DIN 1450 legibility standard
111 recommends several features for font legibility, including
112 differentiation of letter shapes to reduce confusion. The Go fonts
113 conform to the 1450 standard by carefully differentiating zero from
114 capital O; numeral 1 from capital I (eye) and lowercase l (ell);
115 numeral 5 from capital S; and numeral 8 from capital B. The shapes of
116 bowls of b d p q follow the natural asymmetries of legible Renaissance
117 handwriting, aiding differentiation to reduce confusion. [5]
120 Mistaking S for a 5 (at certain sizes) is more of a problem... but... Ze Germans
122 (https://en.wikipedia.org/wiki/Jabberwocky
123 Idea from the aforementioned gofonts paper)
125 Бе сгладне и честлинните комбурси Það leið að stekju, og slýgir greðlar
126 търляха се и сврецваха във плите; sig snældu og böluðu um slöffruna,
127 съвсем окласни бяха тук щурпите og angurvært sungu sópfiðrungar
128 и отма равапсатваха прасурси. við sífgelt týðmana svíræna.
131 (https://en.wikipedia.org/wiki/Typeface)
133 For the rational mind, type design can be a maddening game
134 of drawing things differently in order to make them appear the
135 same.
136 </pre>
140 maketext() {
141 # https://github.com/react-boilerplate/react-boilerplate/issues/1340
142 test -d "$cachedir/fonts" || mkdir "$cachedir/fonts"
143 filename="$(basename "$1")"
144 textfilename="$2"
145 cat >"$cachedir/fonts/text.html" <<EOF
146 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
147 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
148 <html>
149 <head>
150 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
151 <title>$filename</title>
152 <style type="text/css">
153 @font-face {
154 font-family: moo;
155 src: url('$1');
157 pre {
158 font-family: moo;
160 </style>
161 </head>
162 $filename
163 <body>
165 for size in 6 8 10 12 4 2; do
166 text $size $textfilename >>"$cachedir/fonts/text.html"
167 done
168 cat >>"$cachedir/fonts/text.html" <<EOF
169 <br/>
170 $(fc-scan -f '%{fullname} %{style} %{slant} %{file} %{fontversion} %{capability} %{lang}' "$1" || file "$1")
171 </body>
172 </html>
176 trap 'test -n "$casp" && rm -f "$casp"' 0
178 while getopts s:c:m:t:fu opt; do
179 case $opt in
180 m) mime=$OPTARG;;
181 t) type=$OPTARG;;
182 f) force=true;;
183 c) css="-s $OPTARG";;
184 u) usemupdf=true;;
185 s) textfilename="$OPTARG";;
186 ?) die "usage: $0 [-c css] [-m mime/type] [-t filter] [-f] [-s textfile] [path|url]";;
187 esac
188 done
189 shift $(($OPTIND - 1))
190 test -z "$1" && die "usage $0: path"
192 origin="$1"
193 if ${force-test ! -e "$1"} && expr >/dev/null "$1" : "\(ftp\|https\?\)://"; then
194 if executable_p wget; then
195 dl() {
196 wget -q $1 -O $2
198 elif executable_p curl; then
199 dl() {
200 curl $1 -o $2
202 else
203 die "no program to fetch remote urls found"
206 md5of="$cachedir/$(basename "$1")"
207 dl "$1" "$md5of" || test -e "$md5of"
208 shift
209 set -- "$md5of" "$@"
210 else
211 md5of="$1"
214 test -z "$type" && {
215 ft=$(file -L --mime-type -b "$1") || die "$ft"
218 case $ft in
219 application/x-gzip | application/x-compress) dc=zcat;;
220 application/x-xz) dc=xzcat;;
221 application/x-bzip2) dc=bzcat;;
222 *) unset dc || true;;
223 esac
225 filt='"${dc-cat}" "$1" |'
227 typeofmime() {
228 case "$1" in
229 application/postscript) type=ps;;
230 application/pdf) type=pdf;;
231 image/vnd.djvu) type=djvu;;
232 text/html) type=html;;
233 text/plain) type=text;;
234 application/msword) type=word;;
235 application/vnd.openxmlformats-officedocument.* \
236 | application/vnd.ms-powerpoint \
237 | application/vnd.ms-excel \
238 | application/vnd.oasis.opendocument.*) type=uno;;
239 image/svg+xml) type=svg;;
240 image/png | image/jpeg) test -n "$dc" && type="image" || type="image2";;
241 image/*) type=image;;
242 application/x-dvi) type=dvi;;
243 application/x-font-ttf \
244 | application/vnd.ms-opentype \
245 | application/font-sfnt) type=font;;
246 *) return 1;;
247 esac
248 return 0
251 if test -z "$type"; then
252 test -z "$mime" && \
253 mime=$(file -L --mime-type -b "$1" || die "$mime") || \
254 $(file -L --mime-type -bz "$1" || die "$mime")
255 typeofmime "$mime" || die "unhandled file type: '$mime'"
258 caspsuf=".pdf"
259 case $type in
260 ps) conv='ps2pdf - "$casp"';;
261 image2|pdf) test -z "$dc" && exec llpp "$@" || conv='cat >"$casp"';;
262 texi) {
263 missing texi2html "texi2html(http://www.nongnu.org/texi2html/)"
264 missing prince "PrinceXML(http://www.princexml.com/)"
265 conv='texi2html - -o - | prince $css - -o "$casp"'
267 djvu) {
268 missing ddjvu "ddjvu(http://djvu.sourceforge.net/doc/man/ddjvu.html)"
269 conv='ddjvu -format=pdf - "$casp"'
271 html) {
272 missing prince "PrinceXML(http://www.princexml.com/)"
273 conv='prince $css - -o "$casp"'
275 html2epub) {
276 missing pandoc "pandoc(http://pandoc.org)"
277 caspsuf=".epub"
278 conv='pandoc -r html - -w epub -o "$casp"'
280 word) {
281 if executable_p unoconv && test -z "$dc"; then
282 unset filt
283 conv='unoconv -o "$casp" "$1"'
284 else
285 missing antiword "antiword or unoconv"
286 conv='antiword -m 8859-1.txt -a a4 - >"$casp"'
289 uno) {
290 test -n "$dc" && die "cannot convert compressed '$mime'"
291 unset filt
292 missing unoconv "unoconv(http://dag.wiee.rs/home-made/unoconv/)"
293 conv='unoconv -o "$casp" "$1"'
295 svg) {
296 if executable_p inkscape && test -z "$dc"; then
297 unset filt
298 conv='inkscape -z -A "$casp" "$1"'
299 else
300 missing rsvg-convert "rsvg-convert"
301 conv='rsvg-convert -f pdf -o "$casp"'
304 font) {
305 if test -z $usemupdf; then
306 v="llpp -origin $1 -layout-height 0"
307 else
308 mupdf=$HOME/x/rcs/git/mupdf/build/native/mupdf-gl
309 executable_p $mupdf || v=mupdf-gl && v=$mupdf
310 v="$v -H 0"
312 maketext "$1" "$textfilename"
313 exec $v "$cachedir/fonts/text.html"
315 image) {
316 missing convert "convert(http://www.imagemagick.org/script/convert.php)"
317 conv='convert - pdf:"$casp"'
319 dvi) {
320 test -n "$dc" && die "cannot convert compressed '$mime'"
321 unset filt
322 missing dvipdf "dvipdf(http://ghostscript.com/)"
323 conv='dvipdf "$1" "$casp"'
325 text) {
326 missing pandoc "pandoc(http://pandoc.org/)"
327 conv='pandoc -t epub - -o "$casp"'
328 caspsuf=.epub
330 *) die "unhandled filter type: '$type'";;
331 esac
333 hash=$(md5sum "$md5of") || die "$hash"
334 casp=$cachedir/${hash%% *}$caspsuf
336 { test -n "$force" || test ! -e "$casp"; } && eval "$filt" "$conv"
337 shift
339 exec llpp -origin $origin "$@" "$casp"