Why do Greek letters fail to render in R's (v4) PDF output?

好久不见. 提交于 2020-12-12 02:44:51

问题


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

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

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

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.

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

In the R configure command, I see

Capabilities skipped: ICU

where ICU = International Components for Unicode. Also:

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

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

as well as

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

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


回答1:


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

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.

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



来源:https://stackoverflow.com/questions/65150098/why-do-greek-letters-fail-to-render-in-rs-v4-pdf-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!