Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seek replacement for ttf2pt1 for extracting font metrics #92

Open
jpgoldberg opened this issue Dec 30, 2021 · 2 comments
Open

Seek replacement for ttf2pt1 for extracting font metrics #92

jpgoldberg opened this issue Dec 30, 2021 · 2 comments

Comments

@jpgoldberg
Copy link

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.

@sjewo
Copy link

sjewo commented Feb 10, 2022

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

@pooranis
Copy link

pooranis commented Mar 7, 2022

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants