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