Hi there, I am a Chinese R user. I hope to plot the following code with Chinese in one font family, such as SimHei, but English in another font family, such as Times New Roman. plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "serif") In my case, the system default font is "SimSun", so the above code fallback "\u4F60\u597D", which is not in the font Times, to SimSun. If I use: plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "SimHei") Then The "Hello" will in "SimHei" family, it's not as beautiful as Times. Is it possible to specify the fallback font family in R? Any hints or suggestions? Thanks in advance. Best, Jinsong > version _ platform x86_64-w64-mingw32 arch x86_64 os mingw32 system x86_64, mingw32 status major 3 minor 3.3 year 2017 month 03 day 06 svn rev 72310 language R version.string R version 3.3.3 (2017-03-06) nickname Another Canoe > Sys.getlocale() [1] "LC_COLLATE=Chinese (Simplified)_China.936;LC_CTYPE=Chinese (Simplified)_China.936;LC_MONETARY=Chinese (Simplified)_China.936;LC_NUMERIC=C;LC_TIME=Chinese (Simplified)_China.936"
Hi there, I have searched the google, however, I don't find anything that related with fallback font in R. I also try to read the source code of R, however, I am not familiar with C and the algorithm about font specific in text/plot. Thus, I try to specify different fonts for Latin and non-latin characters. I try to use expression(): plot(1:10, xlab = "") mtext(expression(phantom(Hello)*\u4F60\u597D), side = 1, family = "SimSun") mtext(expression(Hello*phantom(\u4F60\u597D), side = 1, family = "serif") However, "Hello" in Simsun has a different strwidth with that in serif. Thus, there are more space between Hello and \u4F60\u597D than it should be. The other way is to merge a Latin font, such as Times New Roman with a non Latin font, such as SimSun. There are several fontforge scripts for the purpose. However, there will cause fontforge core dump. I don't have chance to test it. Will the R core team or someone response to it, if I filed a wishlist in R bugzilla? Best, Jinsong On 2017/3/23 22:24, Jinsong Zhao wrote:> Hi there, > > I am a Chinese R user. I hope to plot the following code with Chinese in > one font family, such as SimHei, but English in another font family, > such as Times New Roman. > > plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "serif") > > In my case, the system default font is "SimSun", so the above code > fallback "\u4F60\u597D", which is not in the font Times, to SimSun. > > If I use: > > plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "SimHei") > > Then The "Hello" will in "SimHei" family, it's not as beautiful as Times. > > Is it possible to specify the fallback font family in R? Any hints or > suggestions? > > Thanks in advance. > > Best, > Jinsong > >> version > _ > platform x86_64-w64-mingw32 > arch x86_64 > os mingw32 > system x86_64, mingw32 > status > major 3 > minor 3.3 > year 2017 > month 03 > day 06 > svn rev 72310 > language R > version.string R version 3.3.3 (2017-03-06) > nickname Another Canoe > >> Sys.getlocale() > [1] "LC_COLLATE=Chinese (Simplified)_China.936;LC_CTYPE=Chinese > (Simplified)_China.936;LC_MONETARY=Chinese > (Simplified)_China.936;LC_NUMERIC=C;LC_TIME=Chinese (Simplified)_China.936
Hi The following code uses 'gridSVG' to export the plot to SVG (after using 'gridGraphics' to convert the plot to using 'grid'), which allows you to specify a "font stack" for the exported SVG. In this example, I am adding "SimHei" to the "serif" font stack. I attach a screen shot of what the result looks like for me in Firefox on Windows (because I am not sure what it should look like). The idea here is really just to pass the effort of deciding which font to use on to a web browser. library(gridSVG) library(gridGraphics) fonts <- getSVGFonts() fonts$serif <- c(fonts$serif, "SimHei") setSVGFonts(fonts) plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family="serif") grid.echo() grid.export("test-1.svg", xmldecl='') Does that help at all? Paul On 24/03/2017 3:24 a.m., Jinsong Zhao wrote:> Hi there, > > I am a Chinese R user. I hope to plot the following code with Chinese in > one font family, such as SimHei, but English in another font family, > such as Times New Roman. > > plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "serif") > > In my case, the system default font is "SimSun", so the above code > fallback "\u4F60\u597D", which is not in the font Times, to SimSun. > > If I use: > > plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "SimHei") > > Then The "Hello" will in "SimHei" family, it's not as beautiful as Times. > > Is it possible to specify the fallback font family in R? Any hints or > suggestions? > > Thanks in advance. > > Best, > Jinsong > >> version > _ > platform x86_64-w64-mingw32 > arch x86_64 > os mingw32 > system x86_64, mingw32 > status > major 3 > minor 3.3 > year 2017 > month 03 > day 06 > svn rev 72310 > language R > version.string R version 3.3.3 (2017-03-06) > nickname Another Canoe > >> Sys.getlocale() > [1] "LC_COLLATE=Chinese (Simplified)_China.936;LC_CTYPE=Chinese > (Simplified)_China.936;LC_MONETARY=Chinese > (Simplified)_China.936;LC_NUMERIC=C;LC_TIME=Chinese (Simplified)_China.936" > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ -------------- next part -------------- A non-text attachment was scrubbed... Name: screen.png Type: image/png Size: 14565 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20170327/dddfc2f4/attachment.png>
On 2017/3/27 6:46, Paul Murrell wrote:> Hi > > The following code uses 'gridSVG' to export the plot to SVG (after using > 'gridGraphics' to convert the plot to using 'grid'), which allows you to > specify a "font stack" for the exported SVG. In this example, I am > adding "SimHei" to the "serif" font stack. I attach a screen shot of > what the result looks like for me in Firefox on Windows (because I am > not sure what it should look like). The idea here is really just to > pass the effort of deciding which font to use on to a web browser. > > library(gridSVG) > library(gridGraphics) > > fonts <- getSVGFonts() > fonts$serif <- c(fonts$serif, "SimHei") > setSVGFonts(fonts) > > plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family="serif") > > grid.echo() > grid.export("test-1.svg", xmldecl='') > > Does that help at all? > > PaulThank you very much. The code solve my concerns about fonts. gridGraphics make me to draw my plot in base graphics that I used to. I can convert SVG to any other format using Inkscape. Best, Jinsong> > On 24/03/2017 3:24 a.m., Jinsong Zhao wrote: >> Hi there, >> >> I am a Chinese R user. I hope to plot the following code with Chinese in >> one font family, such as SimHei, but English in another font family, >> such as Times New Roman. >> >> plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "serif") >> >> In my case, the system default font is "SimSun", so the above code >> fallback "\u4F60\u597D", which is not in the font Times, to SimSun. >> >> If I use: >> >> plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "SimHei") >> >> Then The "Hello" will in "SimHei" family, it's not as beautiful as Times. >> >> Is it possible to specify the fallback font family in R? Any hints or >> suggestions? >> >> Thanks in advance. >> >> Best, >> Jinsong >>