Jinsong Zhao
2017-Apr-07 08:05 UTC
[R] difference metric info of same font on different device
Hi there, I try to plot with custom fonts, which have good shape Latin and CJK characters. I set up all the fonts correctly. However, when I plot the same code on png() and postscript(), I get different result. The main problem is the space between characters is narrower in postscript() than that in png(), and some character also overlap in postscript(). You can see the differences from the attached png files. Is there any way to get the same plot using postscript() and png()? Thanks in advance. Best, Jinsong The code I used is here: windowsFonts(song = windowsFont("SourceHanSerifSC-Regular"), hei = windowsFont("SourceHanSansSC-Regular"), hwhei = windowsFont("SourceHanSansHWSC-Regular"), fzsong = windowsFont("FZShuSong-Z01"), fzhei = windowsFont("FZHei-B01")) postscriptFonts(song = CIDFont("SourceHanSerifSC-Regular", "UniSourceHanSerifCN-UTF8-H", "UTF-8", ""), hei = CIDFont("SourceHanSansSC-Regular", "UniSourceHanSansCN-UTF8-H", "UTF-8", ""), hwhei = CIDFont("SourceHanSansHWSC-Regular", "UniSourceHanSansHWCN-UTF8-H", "UTF-8", ""), fzsong = CIDFont("FZShuSong-Z01", "GBK-EUC-H", "GBK", ""), fzhei = CIDFont("FZHei-B01", "GBK-EUC-H", "GBK", "")) fa <- c("sans", "serif", "song", "hei", "hwhei", "fzsong", "fzhei") postscript("font.eps", fonts = fa, onefile = FALSE, width = 4, height = 4, horizontal = FALSE) #png("font.png", width=4*300, height=4*300, res =300) plot(0,xlab="",ylab="",type="n") text(1, -0.75, expression(CO[2]-Hei), family = "hei") text(1, -0.5, expression(CO[2]-HWHei), family = "hwhei") text(1, -0.25, expression(CO[2]-FZHei), family = "fzhei") text(1, 0.0, expression(CO[2]-Sans), family = "sans") text(1, 0.25, expression(CO[2]-FZSong), family = "fzsong") text(1, 0.5, expression(CO[2]-Song), family = "song") text(1, 0.75, expression(CO[2]-Serif), family = "serif") dev.off() -------------- next part -------------- A non-text attachment was scrubbed... Name: postscript.png Type: image/png Size: 6388 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20170407/af6f7b62/attachment.png> -------------- next part -------------- A non-text attachment was scrubbed... Name: png.png Type: image/png Size: 21368 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20170407/af6f7b62/attachment-0001.png>
Jeff Newmiller
2017-Apr-07 15:13 UTC
[R] difference metric info of same font on different device
I think it is a fundamental characteristic of graphics drivers that output will look different in the details... you are on a wild goose chase. Postscript in particular has a huge advantage in font presentation over other graphics output mechanisms. -- Sent from my phone. Please excuse my brevity. On April 7, 2017 1:05:45 AM PDT, Jinsong Zhao <jszhao at yeah.net> wrote:>Hi there, > >I try to plot with custom fonts, which have good shape Latin and CJK >characters. I set up all the fonts correctly. However, when I plot the >same code on png() and postscript(), I get different result. The main >problem is the space between characters is narrower in postscript() >than >that in png(), and some character also overlap in postscript(). You >can >see the differences from the attached png files. > >Is there any way to get the same plot using postscript() and png()? >Thanks in advance. > >Best, >Jinsong > >The code I used is here: > >windowsFonts(song = windowsFont("SourceHanSerifSC-Regular"), > hei = windowsFont("SourceHanSansSC-Regular"), > hwhei = windowsFont("SourceHanSansHWSC-Regular"), > fzsong = windowsFont("FZShuSong-Z01"), > fzhei = windowsFont("FZHei-B01")) > >postscriptFonts(song = CIDFont("SourceHanSerifSC-Regular", >"UniSourceHanSerifCN-UTF8-H", "UTF-8", ""), > hei = CIDFont("SourceHanSansSC-Regular", >"UniSourceHanSansCN-UTF8-H", "UTF-8", ""), > hwhei = CIDFont("SourceHanSansHWSC-Regular", >"UniSourceHanSansHWCN-UTF8-H", "UTF-8", ""), > fzsong = CIDFont("FZShuSong-Z01", "GBK-EUC-H", >"GBK", ""), > fzhei = CIDFont("FZHei-B01", "GBK-EUC-H", "GBK", "")) > >fa <- c("sans", "serif", "song", "hei", "hwhei", "fzsong", "fzhei") > >postscript("font.eps", fonts = fa, onefile = FALSE, width = 4, height > >4, horizontal = FALSE) > >#png("font.png", width=4*300, height=4*300, res =300) > >plot(0,xlab="",ylab="",type="n") >text(1, -0.75, expression(CO[2]-Hei), family = "hei") >text(1, -0.5, expression(CO[2]-HWHei), family = "hwhei") >text(1, -0.25, expression(CO[2]-FZHei), family = "fzhei") >text(1, 0.0, expression(CO[2]-Sans), family = "sans") >text(1, 0.25, expression(CO[2]-FZSong), family = "fzsong") >text(1, 0.5, expression(CO[2]-Song), family = "song") >text(1, 0.75, expression(CO[2]-Serif), family = "serif") > >dev.off()
Jinsong Zhao
2017-Apr-08 07:19 UTC
[R] difference metric info of same font on different device
On 2017/4/7 23:13, Jeff Newmiller wrote:> I think it is a fundamental characteristic of graphics drivers that output will look different in the details... you are on a wild goose chase. Postscript in particular has a huge advantage in font presentation over other graphics output mechanisms. >Well, the problem stems from the MetricInfo of CID-keyed fonts, which are intended only for use for the glyphs of East Asian languages, which are all monospaced and are all treated as filling the same bounding box. (from the help page of CIDFont) However, is it possible to use the same MetricInfo of CID-keyed fonts as that for png() or windows()? Best, Jinsong
Jinsong Zhao
2017-Apr-08 16:18 UTC
[R] difference metric info of same font on different device
On 2017/4/7 23:13, Jeff Newmiller wrote:> I think it is a fundamental characteristic of graphics drivers that output will look different in the details... you are on a wild goose chase. Postscript in particular has a huge advantage in font presentation over other graphics output mechanisms. >I agreed with your opinion on Postscript. However, as shown in the attached plots in previous post, the glyph metric info for any CID-keyed font is based on assumption in R. In fact, it's not possible to get the metric info of a CID-keyed font without accessing the actual font which may be in truetype or opentype/CFF format. And, I don't think R could find the actual font. Best, Jinsong
Paul Murrell
2017-Apr-10 02:06 UTC
[R] [FORGED] difference metric info of same font on different device
Hi I think you are hitting the limit of what R's PostScript device can do with CID fonts (particularly with Latin characters). Have you tried the cairo_ps() device ? Paul On 7/04/2017 8:05 p.m., Jinsong Zhao wrote:> Hi there, > > I try to plot with custom fonts, which have good shape Latin and CJK > characters. I set up all the fonts correctly. However, when I plot the > same code on png() and postscript(), I get different result. The main > problem is the space between characters is narrower in postscript() than > that in png(), and some character also overlap in postscript(). You can > see the differences from the attached png files. > > Is there any way to get the same plot using postscript() and png()? > Thanks in advance. > > Best, > Jinsong > > The code I used is here: > > windowsFonts(song = windowsFont("SourceHanSerifSC-Regular"), > hei = windowsFont("SourceHanSansSC-Regular"), > hwhei = windowsFont("SourceHanSansHWSC-Regular"), > fzsong = windowsFont("FZShuSong-Z01"), > fzhei = windowsFont("FZHei-B01")) > > postscriptFonts(song = CIDFont("SourceHanSerifSC-Regular", > "UniSourceHanSerifCN-UTF8-H", "UTF-8", ""), > hei = CIDFont("SourceHanSansSC-Regular", > "UniSourceHanSansCN-UTF8-H", "UTF-8", ""), > hwhei = CIDFont("SourceHanSansHWSC-Regular", > "UniSourceHanSansHWCN-UTF8-H", "UTF-8", ""), > fzsong = CIDFont("FZShuSong-Z01", "GBK-EUC-H", > "GBK", ""), > fzhei = CIDFont("FZHei-B01", "GBK-EUC-H", "GBK", "")) > > fa <- c("sans", "serif", "song", "hei", "hwhei", "fzsong", "fzhei") > > postscript("font.eps", fonts = fa, onefile = FALSE, width = 4, height > 4, horizontal = FALSE) > > #png("font.png", width=4*300, height=4*300, res =300) > > plot(0,xlab="",ylab="",type="n") > text(1, -0.75, expression(CO[2]-Hei), family = "hei") > text(1, -0.5, expression(CO[2]-HWHei), family = "hwhei") > text(1, -0.25, expression(CO[2]-FZHei), family = "fzhei") > text(1, 0.0, expression(CO[2]-Sans), family = "sans") > text(1, 0.25, expression(CO[2]-FZSong), family = "fzsong") > text(1, 0.5, expression(CO[2]-Song), family = "song") > text(1, 0.75, expression(CO[2]-Serif), family = "serif") > > dev.off() > > > ______________________________________________ > 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/
Jinsong Zhao
2017-Apr-10 05:26 UTC
[R] [FORGED] difference metric info of same font on different device
On 2017/4/10 10:06, Paul Murrell wrote:> Hi > > I think you are hitting the limit of what R's PostScript device can do > with CID fonts (particularly with Latin characters). > > Have you tried the cairo_ps() device ? > > PaulThank you very much. It works very well. It's more simple than postscript() with CIDFont setting. Best, Jinsong> > On 7/04/2017 8:05 p.m., Jinsong Zhao wrote: >> Hi there, >> >> I try to plot with custom fonts, which have good shape Latin and CJK >> characters. I set up all the fonts correctly. However, when I plot the >> same code on png() and postscript(), I get different result. The main >> problem is the space between characters is narrower in postscript() than >> that in png(), and some character also overlap in postscript(). You can >> see the differences from the attached png files. >> >> Is there any way to get the same plot using postscript() and png()? >> Thanks in advance. >> >> Best, >> Jinsong >> >> The code I used is here: >> >> windowsFonts(song = windowsFont("SourceHanSerifSC-Regular"), >> hei = windowsFont("SourceHanSansSC-Regular"), >> hwhei = windowsFont("SourceHanSansHWSC-Regular"), >> fzsong = windowsFont("FZShuSong-Z01"), >> fzhei = windowsFont("FZHei-B01")) >> >> postscriptFonts(song = CIDFont("SourceHanSerifSC-Regular", >> "UniSourceHanSerifCN-UTF8-H", "UTF-8", ""), >> hei = CIDFont("SourceHanSansSC-Regular", >> "UniSourceHanSansCN-UTF8-H", "UTF-8", ""), >> hwhei = CIDFont("SourceHanSansHWSC-Regular", >> "UniSourceHanSansHWCN-UTF8-H", "UTF-8", ""), >> fzsong = CIDFont("FZShuSong-Z01", "GBK-EUC-H", >> "GBK", ""), >> fzhei = CIDFont("FZHei-B01", "GBK-EUC-H", "GBK", "")) >> >> fa <- c("sans", "serif", "song", "hei", "hwhei", "fzsong", "fzhei") >> >> postscript("font.eps", fonts = fa, onefile = FALSE, width = 4, height >> 4, horizontal = FALSE) >> >> #png("font.png", width=4*300, height=4*300, res =300) >> >> plot(0,xlab="",ylab="",type="n") >> text(1, -0.75, expression(CO[2]-Hei), family = "hei") >> text(1, -0.5, expression(CO[2]-HWHei), family = "hwhei") >> text(1, -0.25, expression(CO[2]-FZHei), family = "fzhei") >> text(1, 0.0, expression(CO[2]-Sans), family = "sans") >> text(1, 0.25, expression(CO[2]-FZSong), family = "fzsong") >> text(1, 0.5, expression(CO[2]-Song), family = "song") >> text(1, 0.75, expression(CO[2]-Serif), family = "serif") >> >> dev.off() >>