Glyphs in popular monospaced fonts
Latest update:
Linus Torvalds famously uses an ancient uemacs editor that he
updated to support UTF-8 some years ago. This post is not about
Torvalds or his editor but about the file named UTF-8-demo.txt
that
caught my attention while I was glancing through the above repo.
Chrome displays it almost correctly--except for the "formulas"
block. Judging from the shape of the glyphs, the default monospace
font I use in Fedora
$ fc-match monospace
LiberationMono-Regular.ttf: "Liberation Mono" "Regular"
doesn't contain all the characters from UTF-8-demo.txt
; hence,
Chrome does font fallback. In its devtools it reports:
Liberation Mono — Local file (5,438 glyphs)
DejaVu Sans — Local file (1,179 glyphs)
Droid Sans Thai — Local file (415 glyphs)
Droid Sans Ethiopic — Local file (320 glyphs)
Segoe UI Historic — Local file (45 glyphs)
Noto Sans Math — Local file (7 glyphs)
Droid Sans Fallback — Local file (5 glyphs)
Segoe UI Symbol — Local file (1 glyph)
Noto Color Emoji — Local file (1 glyph)
Times New Roman — Local file (1 glyph)
(Your list would be, of course, completely different.)
Interestingly, xterm, gvim and gedit
... render the file better than Chrome (they don't mangle the
"formulas" block) and Emacs 29.1 not only fails the "formulas" test
but incorrectly aligns pseudo-graphics at the end of the file.
Anyhow, I became curious about how many installed monospace fonts I
have can render that file without font substitution (spoiler: none).
Is there a way to disable font fallback? We can provide a custom
fontconfig config via
$ FONTCONFIG_FILE=~/tmp/lol.conf gedit
or convert UTF-8-demo.txt
to the pdf format using a tool that, by
default, doesn't know about font substitution:
# input output font
txt2pdf() {
awk '{print " " $0}' < "${1:-/dev/null}" | \
pandoc --pdf-engine=xelatex \
-V "monofont:${3:-Roboto Mono}" -V "mainfont:${3:-Roboto Mono}" \
-V geometry:"top=1cm,left=1cm,bottom=1.5cm,right=1cm" \
-t pdf -o "${2:-${1%.*}.pdf}"
}
(Yes, we trick pandoc into thinking the input is markdown; IRL you'd
probably want to add -V papersize=a4
and -V fontsize=12pt
options
to it.)
Then we can type:
$ txt2pdf UTF-8-demo.txt lol.pdf 'Ubuntu Mono'
and examine lol.pdf
to see that a typeface, created "to complement
the Ubuntu tone of voice", not only has "a contemporary style" but
also "conveys a precise, reliable and free attitude":
How to do the same for all installed fixed-width fonts? First, we
obtain the list of such fonts:
$ type fc.mono
fc.mono is aliased to `fc-list :mono family | awk -F, "{print \$1}" | sort -u'
$ fc.mono
Bitstream Vera Sans Mono
Courier 10 Pitch
Courier New
Cursor
DejaVu Sans Mono
Droid Sans Mono
Inconsolata
Liberation Mono
Ligconsolata
Material Icons
Material Icons Outlined
Material Icons Round
Material Icons Sharp
Material Icons Two Tone
Nimbus Mono PS
Noto Color Emoji
Source Code Pro
Terminus
Ubuntu Mono
(I have Roboto Mono v2 installed as well, but fontconfig doesn't
recognise it as a monospace font.)
then
$ (IFS=$'\n'; for fn in `fc.mono`; do txt2pdf UTF-8-demo.txt "$fn".pdf "$fn"; done)
$ ls *pdf -1
'Bitstream Vera Sans Mono.pdf'
'Courier New.pdf'
'DejaVu Sans Mono.pdf'
'Droid Sans Mono.pdf'
Inconsolata.pdf
'Liberation Mono.pdf'
Ligconsolata.pdf
'Nimbus Mono PS.pdf'
'Source Code Pro.pdf'
'Ubuntu Mono.pdf'
In my case, not every .txt→.pdf conversion was successful, but among
those that succeeded, 'DejaVu Sans Mono.pdf' produced the best
result, glyph-wise.
Tags: ойті
Authors: ag