9fans / plan9port

Plan 9 from User Space
https://9fans.github.io/plan9port/
Other
1.64k stars 326 forks source link

Typical process to use a third party font in troff? #460

Closed aosync closed 3 years ago

aosync commented 3 years ago

I recently decided that I would learn to use troff and I don't really understand how different font families can be used. Resources I found online are few and don't seem to describe explicitly enough how to use non-builtin fonts.

Let's say I have true type font files for a font family that I like; what would be the typical process to be able to start using it in troff (if I understand correctly, getting its font-width table file, and postcript files) and generate ps and pdf documents from it?

rsc commented 3 years ago

It's a lot of trouble to get new fonts working in Plan 9 troff. You have to generate metrics files separate from the actual postscript fonts. For example, DejaVuSans metrics are in /usr/local/plan9/troff/font/devutf/DejaVuSans, and then /usr/local/plan9/postscript/troff/DejaVuSans says how to map Unicode ranges to specific 256-glyph Type1 fonts, which are in turn in /usr/local/plan9/postscript/font/dejavu. And it has to be Type 1, which is getting hard to find. Tr2post doesn't know about TrueType or OpenType. I don't remember how I did all the DejaVu setup. It was a pain.

You would be far better off using Heirloom Troff (http://heirloom.sourceforge.net/doctools.html, https://github.com/n-t-roff/heirloom-doctools), which has a much smoother process and supports TrueType, OpenType, and all their bells and whistles. With that, you just set \$TROFFFONTS to the directory where your fonts are and then name font files directly with the .fp directive. No other support files necessary. Here is the font setup for the PDFs I use on my blog:

.\"
.\" ask heirloom troff for long names
.\"
.do xflag 3
.\"
.\" fonts
.\"
.fp 1 R MinionPro-Regular.otf
.feature R +tnum
.fp 2 I MinionPro-It.otf
.fp 3 B MinionPro-Bold.otf
.fp 4 BI MinionPro-BoldIt.otf
.\" .fp 5 C Go-Mono.ttf
.\" .fzoom 5 .83
.fp 5 C InconsolataGo-Regular.ttf
.fspacewidth C
.fp 6 CB InconsolataGo-Bold.ttf
.fspacewidth CB
.fp 7 SC MinionPro-Regular.otf
.feature SC +smcp +onum
.flig SC 0
.fp 9 SP MinionPro-Regular.otf
.feature SP +sups
.\" .fp 8 BL MinionStd-Black.otf
.\" Use vertically centered tilde, circumflex
.ftr R ~\[asciitilde]
.ftr I ~\[asciitilde]
.ftr B ~\[asciitilde]
.ftr BI ~\[asciitilde]
.ftr C ~\[asciitilde]
.ftr R ^\[asciicircum]
.ftr I ^\[asciicircum]
.ftr B ^\[asciicircum]
.ftr BI ^\[asciicircum]
.ftr C ^\[asciicircum]
.\"
wbehrens-on-gh commented 3 years ago

I noticed that many font files like to include spaces in their names, how would one go about including those?