Hi there, I am a Chinese R user. I hope to display Chinese character in a plot, and than save it in PostScript format. I have read the article titled "Non-Standard Fonts in PostScript and PDF Graphics", especially the section about CJK fonts. I also tried the code:> pdf("chinese.pdf", width=3, height=1) > grid.text("\u4F60\u597D", y=2/3, gp=gpar(fontfamily="CNS1")) > grid.text("is 'hello' in (Traditional) Chinese", y=1/3) > dev.off()however, it's not valid with postscript(). It seems that postscript() need to set family in postscirpt(..., family = "CNS1"). Then all the characters are in CJK font, and it's not what I hope to get. I hope the Latin character is displayed in Helvetica. Any suggestions? Thanks in advance! Regards, Jinsong -- Jinsong Zhao, Ph.D. College of Resources and Environment Huazhong Agricultural University Wuhan 430070, P.R. China E-mail: jszhao at mail.hzau.edu.cn
Hi On 6/30/2010 2:17 AM, Jinsong Zhao wrote:> Hi there, > > I am a Chinese R user. I hope to display Chinese character in a plot, > and than save it in PostScript format. I have read the article titled > "Non-Standard Fonts in PostScript and PDF Graphics", especially the > section about CJK fonts. I also tried the code: > >> pdf("chinese.pdf", width=3, height=1) >> grid.text("\u4F60\u597D", y=2/3, gp=gpar(fontfamily="CNS1")) >> grid.text("is 'hello' in (Traditional) Chinese", y=1/3) >> dev.off() > > however, it's not valid with postscript(). It seems that postscript() > need to set family in postscirpt(..., family = "CNS1"). Then all the > characters are in CJK font, and it's not what I hope to get. I hope the > Latin character is displayed in Helvetica. > > Any suggestions? Thanks in advance!Try this ... # Use "Helvetica" as default, but include "CNS1" as a font that # will be used somewhere within the file postscript("chinese.pdf", width=3, height=1, fonts="CNS1") grid.text("\u4F60\u597D", y=2/3, gp=gpar(fontfamily="CNS1")) grid.text("is 'hello' in (Traditional) Chinese", y=1/3) dev.off() Paul> Regards, > Jinsong-- 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/
Hi, Another option would be the tikzDevice package, which lets you process all the text of your plot with LaTeX. I think the XeTeX variant might be the most straight-forward to mix different fonts using this approach. HTH, baptiste On 29 June 2010 16:17, Jinsong Zhao <jszhao at mail.hzau.edu.cn> wrote:> Hi there, > > I am a Chinese R user. I hope to display Chinese character in a plot, > and than save it in PostScript format. I have read the article titled > "Non-Standard Fonts in PostScript and PDF Graphics", especially the > section about CJK fonts. I also tried the code: > >> pdf("chinese.pdf", width=3, height=1) >> grid.text("\u4F60\u597D", y=2/3, gp=gpar(fontfamily="CNS1")) >> grid.text("is 'hello' in (Traditional) Chinese", y=1/3) >> dev.off() > > however, it's not valid with postscript(). It seems that postscript() > need to set family in postscirpt(..., family = "CNS1"). Then all the > characters are in CJK font, and it's not what I hope to get. I hope the > Latin character is displayed in Helvetica. > > Any suggestions? Thanks in advance! > > Regards, > Jinsong > -- > Jinsong Zhao, Ph.D. > College of Resources and Environment > Huazhong Agricultural University > Wuhan 430070, P.R. China > E-mail: jszhao at mail.hzau.edu.cn > > ______________________________________________ > R-help at r-project.org mailing list > 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. >
On 2010-6-30 7:06, Paul Murrell wrote:> Hi > > On 6/30/2010 2:17 AM, Jinsong Zhao wrote: >> Hi there, >> >> I am a Chinese R user. I hope to display Chinese character in a plot, >> and than save it in PostScript format. I have read the article titled >> "Non-Standard Fonts in PostScript and PDF Graphics", especially the >> section about CJK fonts. I also tried the code: >> >>> pdf("chinese.pdf", width=3, height=1) >>> grid.text("\u4F60\u597D", y=2/3, gp=gpar(fontfamily="CNS1")) >>> grid.text("is 'hello' in (Traditional) Chinese", y=1/3) >>> dev.off() >> >> however, it's not valid with postscript(). It seems that postscript() >> need to set family in postscirpt(..., family = "CNS1"). Then all the >> characters are in CJK font, and it's not what I hope to get. I hope the >> Latin character is displayed in Helvetica. >> >> Any suggestions? Thanks in advance! > > Try this ... > > # Use "Helvetica" as default, but include "CNS1" as a font that > # will be used somewhere within the file > postscript("chinese.pdf", width=3, height=1, fonts="CNS1") > grid.text("\u4F60\u597D", y=2/3, gp=gpar(fontfamily="CNS1")) > grid.text("is 'hello' in (Traditional) Chinese", y=1/3) > dev.off() > > Paul >Thank you very much, it works very well. Regards, Jinsong -- Jinsong Zhao, Ph.D. College of Resources and Environment Huazhong Agricultural University Wuhan 430070, P.R. China E-mail: jszhao at mail.hzau.edu.cn
On 2010-6-30 16:24, Patrick Connolly wrote:> On Wed, 30-Jun-2010 at 11:06AM +1200, Paul Murrell wrote: > >> Hi >> >> On 6/30/2010 2:17 AM, Jinsong Zhao wrote: >>> Hi there, >>> >>> I am a Chinese R user. I hope to display Chinese character in a plot, >>> and than save it in PostScript format. I have read the article titled >>> "Non-Standard Fonts in PostScript and PDF Graphics", especially the >>> section about CJK fonts. I also tried the code: >>> >>>> pdf("chinese.pdf", width=3, height=1) >>>> grid.text("\u4F60\u597D", y=2/3, gp=gpar(fontfamily="CNS1")) >>>> grid.text("is 'hello' in (Traditional) Chinese", y=1/3) >>>> dev.off() >>> >>> however, it's not valid with postscript(). It seems that postscript() >>> need to set family in postscirpt(..., family = "CNS1"). Then all the >>> characters are in CJK font, and it's not what I hope to get. I hope the >>> Latin character is displayed in Helvetica. >>> >>> Any suggestions? Thanks in advance! >> >> Try this ... >> >> # Use "Helvetica" as default, but include "CNS1" as a font that >> # will be used somewhere within the file >> postscript("chinese.pdf", width=3, height=1, fonts="CNS1") >> grid.text("\u4F60\u597D", y=2/3, gp=gpar(fontfamily="CNS1")) >> grid.text("is 'hello' in (Traditional) Chinese", y=1/3) >> dev.off() >> > > > That doesn't work for me using the ancient version of R (a year old) > on this box. It produces a file that looks like a postscript file, > but which is slightly smaller than the one that a call to pdf() makes > but cannot be displayed by any file viewer I have. >The filename in Paul's code is "chinese.pdf". In fact, it's a postscript file for it was created by postscript(). If your system dose not have the specific font and corresponding cidfmap (from ghostscript distribution), the file cannot be displayed.> However, it kind of works if I convert the pdf file into a postscript > file using pdftops, but I doubt that's what Jinsong wanted. It's > 35Mb! >I try to convert the "chinese.pdf" to postscript file using pdftops, however, I get the following error: Error: May not be a PDF file (continuing anyway) Error (0): PDF file is damaged - attempting to reconstruct xref table... Error: Couldn't find trailer dictionary Error: Couldn't read xref table So would you like to send the file to me?> Perhaps it really does work using a more up to date version. >Regards, Jinsong -- Jinsong Zhao, Ph.D. College of Resources and Environment Huazhong Agricultural University Wuhan 430070, P.R. China E-mail: jszhao at mail.hzau.edu.cn
On 2010-6-30 17:20, baptiste auguie wrote:> Hi, > > Another option would be the tikzDevice package, which lets you process > all the text of your plot with LaTeX. I think the XeTeX variant might > be the most straight-forward to mix different fonts using this > approach. > > HTH, > > baptiste > > >Thank you very much for your suggestion. tikz is a powerful graphic language, however, I am not familiar with it. Before this question, I add Chinese character to postscript file by LaTeX with psfrag. Regards, Jinsong -- Jinsong Zhao, Ph.D. College of Resources and Environment Huazhong Agricultural University Wuhan 430070, P.R. China E-mail: jszhao at mail.hzau.edu.cn
Reasonably Related Threads
- plain text in Chinese can not be set
- Sweave, cairo_pdf, CJK, ghostscript
- similarity between two gene lists with varied length
- Re: VM I/O performance drops dramatically during storage migration with drive-mirror
- PDFfontNumber bugs in devPS.c (Re: plain text in Chinese can not be set)