在Mac OS X的R包Cairo中设置系统字体

时间:2023-01-21 14:28:59

Because of the issue raised in Using Unicode inside R's expression() command, I am switching to R on Mac OS X to create some plots. Using CairoPDF(), however, the commands I use in Windows to select my fonts don't have any effect on Mac OS X, where the output .pdf file always has the Helvetica font.

由于在R的expression()命令中使用Unicode引起的问题,我在Mac OS X上切换到R以创建一些图。然而,使用CairoPDF(),我在Windows中用于选择字体的命令对Mac OS X没有任何影响,在Mac OS X中,输出.pdf文件总是使用Helvetica字体。

library(package = "Cairo")
CairoPDF("test.pdf")
plot.new()
text(x=.5,y=.5,labels="\u0260",family="Times New Roman")
dev.off()

The output in Windows is:

Windows中的输出是:

在Mac OS X的R包Cairo中设置系统字体

The output in Mac OS X is:

Mac OS X的输出为:

在Mac OS X的R包Cairo中设置系统字体

The Times New Roman font is exactly the same on both systems.

Times New Roman字体在两种系统中都是一样的。

1 个解决方案

#1


2  

I did it with CairoFonts rather than the family argument, which seems to be getting ignored.

我用的是CairoFonts而不是家庭争论,这似乎被忽略了。

> CairoPDF("test.pdf")
> plot.new()
> text(x=.5,y=.5,labels="\u0260",family="Times New Roman")
> dev.off()
quartz 
     2 

在Mac OS X的R包Cairo中设置系统字体

> CairoFonts(  # slight mod to example in ?CairoFonts page
+   regular="TimesNewRoman:style=Regular",
+   bold="FreeSans:style=Bold",
+   italic="FreeSans:style=Oblique",
+   bolditalic="FreeSans:style=BoldOblique"
+ )
> 


> CairoPDF("test.pdf")
> plot.new()
> text(x=.5,y=.5, labels="\u0260" )
> dev.off()
quartz 
     2 

在Mac OS X的R包Cairo中设置系统字体

#1


2  

I did it with CairoFonts rather than the family argument, which seems to be getting ignored.

我用的是CairoFonts而不是家庭争论,这似乎被忽略了。

> CairoPDF("test.pdf")
> plot.new()
> text(x=.5,y=.5,labels="\u0260",family="Times New Roman")
> dev.off()
quartz 
     2 

在Mac OS X的R包Cairo中设置系统字体

> CairoFonts(  # slight mod to example in ?CairoFonts page
+   regular="TimesNewRoman:style=Regular",
+   bold="FreeSans:style=Bold",
+   italic="FreeSans:style=Oblique",
+   bolditalic="FreeSans:style=BoldOblique"
+ )
> 


> CairoPDF("test.pdf")
> plot.new()
> text(x=.5,y=.5, labels="\u0260" )
> dev.off()
quartz 
     2 

在Mac OS X的R包Cairo中设置系统字体