extrafont
extrafont copied to clipboard
Seek replacement for `ttf2pt1` for extracting font metrics
I do not know how R handles fonts, but it appears that it only deals with Type1 postscript fonts for which we need a separate font metrics file, fontname.afm
.
extrafont
relies on ttf2pt1
to extract the afm. But it appears that ttf2pt1
is abandonware. (It certainly gives me a bunch of compiler warnings when built).
Possible options
From the extrafont source in truetype.r
we find the comment
Previously, I tried using ttf2afm to do the afm extraction, but the afm files created by ttf2afm didn't work with R. The command for ttf2afm was:
ttf2afm Impact.ttf -o Impact.afm
I am assuming that that is ttf2afm
from pdftex (source) but I am assuming that that was about the one that comes in common TeX installations.
There is a Rust crate that uses https://docs.rs/ttf-parser/0.14.0/ttf_parser/index.html I do not know enough about the structure of ttf and or afm to see how to use that to generate an afm from a ttf.
I did a quick test with ttf2afm
from pdftex and on first sight it might work out. At the moment pdf export seems to function properly on linux systems (I tested this also on Mac OS, but I did not install ghostscript).
I patched truetype.r
to use ttf2afm
in my fork: https://github.com/sjewo/extrafont
You might need to install the binary first:
library(tinytex)
tlmgr_install("ttfutils")
Update:
- On a second system the afm files from
ttf2afm
differ and pdf export fails (unknown width). - afm files from fontforge are usable, too
On a mac, ttf2pt1
installed with Homebrew (using the bottled version compiled by them) works. It is a drop-in replacement for the one in Rttf2pt1 - as in I copied the homebrew binary to the Rttf2pt1/exec/ R library folder, and then all the TTF files in my system were able to be imported (i.e. no segmentation fault and the Font Name was returned) except for a few. (With Rttf2pt1, only about half worked).