daqana / tikzDevice

A R package for producing graphics output as PGF/TikZ code for use in TeX documents.
https://daqana.github.io/tikzDevice
132 stars 26 forks source link

text() with non-Latin1 character causes infinite loop #160

Closed jszhao closed 6 years ago

jszhao commented 7 years ago

After set DEBUG to TRUE, the following code demonstrated the bug.

library(tikzDevice)
options(tikzDefaultEngine = "xetex")
options(tikzXelatexPackages = c(getOption("tikzXelatexPackages"),
                                "\\setmainfont{Times New Roman}\n",
                                "\\usepackage[math-style=TeX]{unicode-math}\n",
                                "\\setmathfont{Times New Roman}\n",
                                "\\usepackage{xeCJK}\n", 
                                "\\setCJKmainfont{SimHei}\n\n"
                                ))
tikz(console=TRUE, standAlone = TRUE, width=4, height=4)
plot(1:10, type = "n", xlab = "", ylab = "模式")
text(5,2, "江")
dev.off()

it will print endlessly: % Calculated character metrics. ascent: 7.851560, descent: 0.976530, width: 10.000000

If I replaced text(5,2, "江") to text(5,2, "a"), It will end normally.

However, I don't know how to debug C code.

This issue is the root of https://github.com/yihui/tikzDevice/issues/155.

By the way, it may not be the bug of tikzDevice, maybe the bug of R itself. I don't know.

krlmlr commented 6 years ago

Thanks for your analysis. This is likely a bug in base R.

krlmlr commented 6 years ago

This now works for me in the development version of tikzDevice with R 3.4.3 on Linux. Please file a new issue if the problem persists.