为什么希腊字母无法在 R 的 (v4) PDF 输出中呈现?
Why do Greek letters fail to render in R's (v4) PDF output?
我正在尝试将一个简单的绘图从 R 导出为 PDF,带有希腊字母,如下所示:
cairo_pdf("test.pdf")
barplot(1, main = "\u03C1")
dev.off()
我使用的是预装了 R 3.5 的 OpenSUSE LEAP 15.1 系统 - 这工作正常。所以必须安装必要的字体。
然而,在 R 4.0.3(我自己编译的)中,相同的命令产生一个方框而不是希腊字母:
(有趣的是,复制并粘贴此框会插入正确的希腊字母。)
这是 R v3 和 v4 之间的根本区别(如果是,是哪一个?),或者我可以在编译期间影响它吗?我在 Windows 上没有同样的问题,但这是一个我没有自己编译的发行版本,它具有 ICU 功能。
查看PDF文件,v3文件使用Cantarell-Regular和SourceCodePro-Bold。 v4 使用 Cantarell-Regular 和 Cantarell-Bold。所有字体都是子集嵌入的。所以不知何故,R v4 似乎无法切换到 SourceCodePro
字体,尽管它已安装:
> fc-list | grep SourceCodePro
/usr/share/fonts/truetype/SourceCodePro-Medium.otf: Source Code Pro,Source Code Pro Medium:style=Medium,Regular
/usr/share/fonts/truetype/SourceCodePro-Regular.otf: Source Code Pro:style=Regular
/usr/share/fonts/truetype/SourceCodePro-Bold.otf: Source Code Pro:style=Bold
/usr/share/fonts/truetype/SourceCodePro-Black.otf: Source Code Pro,Source Code Pro Black:style=Black,Regular
/usr/share/fonts/truetype/SourceCodePro-BoldIt.otf: Source Code Pro:style=Bold Italic
/usr/share/fonts/truetype/SourceCodePro-Semibold.otf: Source Code Pro,Source Code Pro Semibold:style=Semibold,Regular
/usr/share/fonts/truetype/SourceCodePro-ExtraLightIt.otf: Source Code Pro,Source Code Pro ExtraLight:style=ExtraLight Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-BlackIt.otf: Source Code Pro,Source Code Pro Black:style=Black Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-LightIt.otf: Source Code Pro,Source Code Pro Light:style=Light Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-MediumIt.otf: Source Code Pro,Source Code Pro Medium:style=Medium Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-It.otf: Source Code Pro:style=Italic
/usr/share/fonts/truetype/SourceCodePro-SemiboldIt.otf: Source Code Pro,Source Code Pro Semibold:style=Semibold Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-Light.otf: Source Code Pro,Source Code Pro Light:style=Light,Regular
/usr/share/fonts/truetype/SourceCodePro-ExtraLight.otf: Source Code Pro,Source Code Pro ExtraLight:style=ExtraLight,Regular
在R configure
命令中,我看到
Capabilities skipped: ICU
其中 ICU = Unicode 的国际组件。还有:
checking whether pkg-config knows about cairo and pango... no
checking whether pkg-config knows about cairo... yes
这两者有关联吗?
编辑:我已经找到并阅读了Changes to Symbol Fonts for Cairo Graphics Devices,但是
cairo_pdf("test.pdf", symbolfamily = cairoSymbolFont("Courier", usePUA = FALSE))
barplot(1, main = "\u03C1")
dev.off()
以及
cairo_pdf("test.pdf", symbolfamily = cairoSymbolFont("Courier", usePUA = TRUE))
barplot(1, main = "\u03C1")
dev.off()
产生与上面相同的输出,虽然
cairo_pdf("test.pdf", family = "Courier")
barplot(1, main = "\u03C1")
dev.off()
成功更改标准字体,说明Courier已安装并可用
使用 ICU 支持重新编译没有解决这个问题 - 使用 cairo 和 pango 重新编译可以解决这个问题。
为了实现这两个目标,安装包时进行了大量的反复试验。总之,我做了
zypper in libicu-devel freetype-devel freetype pango-devel pango-tools libpango-1_0-0 harfbuzz-devel fribidi-devel fribidi
。其中大部分可能已经安装,但在此过程中,我注意到 libharfbuzz0
和 libharfbuzz-icu0
was broken and fixed that.
的安装
然后重新配置并重新编译R,问题没有了。
我正在尝试将一个简单的绘图从 R 导出为 PDF,带有希腊字母,如下所示:
cairo_pdf("test.pdf")
barplot(1, main = "\u03C1")
dev.off()
我使用的是预装了 R 3.5 的 OpenSUSE LEAP 15.1 系统 - 这工作正常。所以必须安装必要的字体。
然而,在 R 4.0.3(我自己编译的)中,相同的命令产生一个方框而不是希腊字母:
这是 R v3 和 v4 之间的根本区别(如果是,是哪一个?),或者我可以在编译期间影响它吗?我在 Windows 上没有同样的问题,但这是一个我没有自己编译的发行版本,它具有 ICU 功能。
查看PDF文件,v3文件使用Cantarell-Regular和SourceCodePro-Bold。 v4 使用 Cantarell-Regular 和 Cantarell-Bold。所有字体都是子集嵌入的。所以不知何故,R v4 似乎无法切换到 SourceCodePro
字体,尽管它已安装:
> fc-list | grep SourceCodePro
/usr/share/fonts/truetype/SourceCodePro-Medium.otf: Source Code Pro,Source Code Pro Medium:style=Medium,Regular
/usr/share/fonts/truetype/SourceCodePro-Regular.otf: Source Code Pro:style=Regular
/usr/share/fonts/truetype/SourceCodePro-Bold.otf: Source Code Pro:style=Bold
/usr/share/fonts/truetype/SourceCodePro-Black.otf: Source Code Pro,Source Code Pro Black:style=Black,Regular
/usr/share/fonts/truetype/SourceCodePro-BoldIt.otf: Source Code Pro:style=Bold Italic
/usr/share/fonts/truetype/SourceCodePro-Semibold.otf: Source Code Pro,Source Code Pro Semibold:style=Semibold,Regular
/usr/share/fonts/truetype/SourceCodePro-ExtraLightIt.otf: Source Code Pro,Source Code Pro ExtraLight:style=ExtraLight Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-BlackIt.otf: Source Code Pro,Source Code Pro Black:style=Black Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-LightIt.otf: Source Code Pro,Source Code Pro Light:style=Light Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-MediumIt.otf: Source Code Pro,Source Code Pro Medium:style=Medium Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-It.otf: Source Code Pro:style=Italic
/usr/share/fonts/truetype/SourceCodePro-SemiboldIt.otf: Source Code Pro,Source Code Pro Semibold:style=Semibold Italic,Italic
/usr/share/fonts/truetype/SourceCodePro-Light.otf: Source Code Pro,Source Code Pro Light:style=Light,Regular
/usr/share/fonts/truetype/SourceCodePro-ExtraLight.otf: Source Code Pro,Source Code Pro ExtraLight:style=ExtraLight,Regular
在R configure
命令中,我看到
Capabilities skipped: ICU
其中 ICU = Unicode 的国际组件。还有:
checking whether pkg-config knows about cairo and pango... no
checking whether pkg-config knows about cairo... yes
这两者有关联吗?
编辑:我已经找到并阅读了Changes to Symbol Fonts for Cairo Graphics Devices,但是
cairo_pdf("test.pdf", symbolfamily = cairoSymbolFont("Courier", usePUA = FALSE))
barplot(1, main = "\u03C1")
dev.off()
以及
cairo_pdf("test.pdf", symbolfamily = cairoSymbolFont("Courier", usePUA = TRUE))
barplot(1, main = "\u03C1")
dev.off()
产生与上面相同的输出,虽然
cairo_pdf("test.pdf", family = "Courier")
barplot(1, main = "\u03C1")
dev.off()
成功更改标准字体,说明Courier已安装并可用
使用 ICU 支持重新编译没有解决这个问题 - 使用 cairo 和 pango 重新编译可以解决这个问题。
为了实现这两个目标,安装包时进行了大量的反复试验。总之,我做了
zypper in libicu-devel freetype-devel freetype pango-devel pango-tools libpango-1_0-0 harfbuzz-devel fribidi-devel fribidi
。其中大部分可能已经安装,但在此过程中,我注意到 libharfbuzz0
和 libharfbuzz-icu0
was broken and fixed that.
然后重新配置并重新编译R,问题没有了。