为什么希腊字母无法在R(v4)PDF输出中呈现? [英] Why do Greek letters fail to render in R's (v4) PDF output?

查看:102
本文介绍了为什么希腊字母无法在R(v4)PDF输出中呈现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个简单的绘图从R导出为带有希腊字母的PDF,如下所示:

I am trying to export a simple plot to PDF from R, with a Greek letter, like this:

cairo_pdf("test.pdf")
barplot(1, main = "\u03C1")
dev.off()

我在预先安装了R 3.5的OpenSUSE LEAP 15.1系统上-可以正常工作.因此,必须安装必要的字体.

I am on an OpenSUSE LEAP 15.1 system with R 3.5 preinstalled - this works fine. So the necessary fonts must be installed.

但是,在R 4.0.3(我自己编写)中,相同的命令产生一个框而不是希腊字母:(有趣的是,复制并粘贴此框会插入正确的希腊字母.)

However, in R 4.0.3 (which I compiled myself), the same command yields a box instead of the Greek letter: (Interestingly, copy-and-pasting this box inserts the correct Greek letter.)

这是R v3和v4之间的根本区别吗(如果是,是哪个?),或者在编译过程中可以影响吗?我在Windows上没有相同的问题,但这是我自己未编译且具有ICU功能的发行版.

Is this a fundamental difference between R v3 and v4 (if so, which one?), or can I influence this during compilation? I do not have the same problem on Windows, but this is a release version which I did not compile myself and which has ICU capabilities.

查看PDF文件,v3文件使用Cantarell-Regular和SourceCodePro-Bold.v4使用Cantarell-Regular和Cantarell-Bold.所有字体都是子集嵌入的.因此,尽管安装了R v4,它仍无法切换到该 SourceCodePro 字体:

Looking at the PDF files, the v3 file uses Cantarell-Regular and SourceCodePro-Bold. The v4 one uses Cantarell-Regular and Cantarell-Bold. All fonts are subset-embedded. So somehow, R v4 seems to fail switching to that SourceCodePro font, although it is installed:

> 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 命令中,我看到了

In the R configure command, I see

跳过的功能:ICU

Capabilities skipped: ICU

其中ICU = Unicode的国际组件.另外:

where ICU = International Components for Unicode. Also:

检查pkg-config是否了解cairo和pango ...否

checking whether pkg-config knows about cairo and pango... no

检查pkg-config是否了解cairo ...是

checking whether pkg-config knows about cairo... yes

这两个之一可以联系吗?

Could one of these two be related?

编辑:我已经找到并阅读了

Edit: I have found and read Changes to Symbol Fonts for Cairo Graphics Devices, yet

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

产生与上述相同的输出,尽管

produce the same output as above, although

cairo_pdf("test.pdf", family = "Courier")
barplot(1, main = "\u03C1")
dev.off()

成功更改了标准字体,表明Courier已安装并且可以使用.

successfully changes the standard font, indicating that Courier is installed and usable.

推荐答案

使用ICU支持进行重新编译不能解决此问题-使用cairo和pango进行重新编译可以解决.

Recompiling with ICU support did not fix this - recompiling with cairo and pango did.

要实现这两个目标,有很多反复试验的安装软件包.总而言之,我做到了 libicu-devel freetype-devel freetype pango-devel pango-tools libpango-1_0-0 harfbuzz-devel fribidi-devel fribidi中的zypper .其中大部分可能已经安装了,但是在此过程中,我注意到安装了 libharfbuzz0 libharfbuzz-icu0

To achieve both, there was lot of trial-and-error installing packages. In summary, I did zypper in libicu-devel freetype-devel freetype pango-devel pango-tools libpango-1_0-0 harfbuzz-devel fribidi-devel fribidi. Much of that may already have been installed, but in the process, I noticed that the installation of libharfbuzz0 and libharfbuzz-icu0 was broken and fixed that.

然后重新配置并重新编译R,问题消失了.

Then reconfigured and recompiled R, and the problem was gone.

这篇关于为什么希腊字母无法在R(v4)PDF输出中呈现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆