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

Cannot access bold, italic fonts from .ttc files #17

Open
braunm opened this issue Jan 18, 2018 · 4 comments
Open

Cannot access bold, italic fonts from .ttc files #17

braunm opened this issue Jan 18, 2018 · 4 comments

Comments

@braunm
Copy link

braunm commented Jan 18, 2018

I have not been able to use the bold or italic font faces included in .ttc files, where all faces are in the same file. There is no problem with using .ttf font files, where each face has a different file. I can also use the plain font face from the .ttc file. This problem occurs with pdf() and quartz() devices. I am on a Mac, with R 3.4.3 and showtext 0.5.1.

Below is an MWE, although I understand paths to fonts may be different on different systems. Just pick your favorite .ttc and .ttf fonts.

Any help would be greatly appreciated. Thanks for contributing showtext to the world.

library(showtext)
font_add("Palatino",
         regular="/System/Library/Fonts/Palatino.ttc",
         bold="/System/Library/Fonts/Palatino.ttc",
         italic="/System/Library/Fonts/Palatino.ttc")
font_add("Verdana",
         regular="/Library/Fonts/Microsoft/Verdana.ttf",
         bold="/Library/Fonts/Microsoft/Verdana Bold.ttf",
         italic="/Library/Fonts/Microsoft/Verdana Italic.ttf")
fam1 <- "Palatino"
fam2 <- "Verdana"
showtext_auto()

pdf()
plot(1:10,family=fam1,font=1,main=fam1)  ## for all Palatino, titles should be bold, but they are not
plot(1:10,family=fam1,font=2,main=fam1) ## axes should be bold, but they are not
plot(1:10,family=fam1,font=3,main=fam1) ## axes should be italic, but they are not
plot(1:10,family=fam2,font=1,main=fam2)  ## for all Verdana, titles are bold (correct)
plot(1:10,family=fam2,font=2,main=fam2)  ## axes are bold (correct)
plot(1:10,family=fam2,font=3,main=fam2)  ## axes are italic (correct)
dev.off()
@yixuan
Copy link
Owner

yixuan commented Jan 18, 2018

Thanks for the report. There seems to be some difficulty recognizing different font faces in a ttc file, so I would suggest using some conversion tools to unpack the ttc file first, for example https://transfonter.org/ttc-unpack.

@braunm
Copy link
Author

braunm commented Jan 18, 2018

Thanks for pointing me to transfonter. That does solve the problem as a workaround.

@TigerZhao007
Copy link

TigerZhao007 commented Feb 18, 2022

I have the same problem. How to access italic Chinese fonts.
For example, I want italic Fangsong fonts. What should I do.

`
library(showtext)

font_add("fangsong", "simfang.ttf")

showtext_auto()

pdf(file = "R001.pdf")

plot(1:10,1:10,type="n")

text(5,5, labels = "这应该是仿宋斜体",cex = 2, family="songti",font=3); # hould be italic, but they are not

dev.off()
`

@yixuan
Copy link
Owner

yixuan commented Feb 20, 2022

@TigerZhao007 As far as I know, the Fangsong font does not contain an italic font face.

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