showtext icon indicating copy to clipboard operation
showtext copied to clipboard

Cannot access bold, italic fonts from .ttc files

Open braunm opened this issue 6 years ago • 4 comments

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

braunm avatar Jan 18 '18 00:01 braunm

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.

yixuan avatar Jan 18 '18 00:01 yixuan

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

braunm avatar Jan 18 '18 01:01 braunm

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() `

TigerZhao007 avatar Feb 18 '22 16:02 TigerZhao007

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

yixuan avatar Feb 20 '22 02:02 yixuan