在R图形中使用Unicode'dingbat-like'字形,跨设备&平台,特别是PDF [英] using Unicode 'dingbat-like' glyphs in R graphics, across devices & platforms, especially PDF
问题描述
有些人可能看过我的,在那里我想写一段代码,希望帮助一个朋友在图形上制作半满的圈子:
TestUnicode < - 函数(start =25a0,end =25ff,...)
{
nstart< - as.hexmode )
nend < - as.hexmode(end)
r < - nstart:nend
s < - ceiling(sqrt(length(r)))
par(pty = s)
plot(c(-1,(s)),c(-1,(s)),type =n,xlab =,ylab =,
grid(s + 1,s + 1,lty = 1)
for(i seq(r)){
try(xaxs =i,yaxs =i点(i %% s,i%/%s,pch = -1 * r [i],...))
}
}
TestUnicode(9500, 9900)
这个工作原理(即产生一个几乎完整的酷酷的小丁点符号):
- 在Ubuntu 10.04上,位于X11或PNG设备中
- 在Mandriva Linux发行版中,相同的设备,使用本地构建的R,一旦安装了pango-devel
(即产生一个部分或全部用点或空矩形填充的网格),无论是静默还是警告:在PDF中相同的Ubuntu 10.04机器上,
- 或PostScript(尝试设置font =NimbusSan以使用URW字体,并没有帮助) 在MacOS X.6(石英,X11,开罗,PDF)上
-
例如,尝试使用所有可用的PDF字体系列:
flist <-c(AvantGarde,Bookman,Courier,Helvetica,Helvetica-Narrow,
NewCenturySchoolbook,Palatino,Times,URWGothic ,
URWBookman,NimbusMon,NimbusSan,NimbusSanCond,
CenturySch,URWPalladio,NimbusRom)
){
fn < - paste(utest _,f,。pdf,sep =)
pdf(fn,family = f)
TestUnicode()
title(main = f)
dev.off()
embedFonts(fn)
}
在Ubuntu上,这些文件都不包含这些符号。
It wo我们很高兴能让它在尽可能多的组合上工作,但特别是在某些矢量格式和双精度上 - 尤其是在PDF中。
关于字体/图形设备的任何建议配置,这将使这项工作将受到欢迎。
解决方案我认为你是出于运气本,因为,根据一些笔记通过Paul Murrell,
pdf()
只能处理单字节编码。多字节编码需要转换为单字节等价物,其中存在摩擦;根据定义,单字节编码不能包含像UTF-8这样的多字节编码中表示的所有字形。
Paul的笔记可以找到<在这里他建议使用开罗 - 在适当的Linux和Mac OS系统上使用
cairo_pdf()
,或通过Cairo
软件包MS Windows。Some of you may have seen my blog post on this topic, where I wrote the following code after wanting to help a friend produce half-filled circles as points on a graph:
TestUnicode <- function(start="25a0", end="25ff", ...) { nstart <- as.hexmode(start) nend <- as.hexmode(end) r <- nstart:nend s <- ceiling(sqrt(length(r))) par(pty="s") plot(c(-1,(s)), c(-1,(s)), type="n", xlab="", ylab="", xaxs="i", yaxs="i") grid(s+1, s+1, lty=1) for(i in seq(r)) { try(points(i%%s, i%/%s, pch=-1*r[i],...)) } } TestUnicode(9500,9900)
This works (i.e. produces a nearly-full grid of cool dingbatty symbols):
- on Ubuntu 10.04, in an X11 or PNG device
- on Mandriva Linux distribution, same devices, with locally built R, once pango-devel was installed
It fails to varying degrees (i.e. produces a grid partly or entirely filled with dots or empty rectangles), either silently or with warnings:
- on the same Ubuntu 10.04 machine in PDF or PostScript (tried setting font="NimbusSan" to use URW fonts, doesn't help)
- on MacOS X.6 (quartz, X11, Cairo, PDF)
For example, trying all the available PDF font families:
flist <- c("AvantGarde", "Bookman","Courier", "Helvetica", "Helvetica-Narrow", "NewCenturySchoolbook", "Palatino", "Times","URWGothic", "URWBookman", "NimbusMon", "NimbusSan", "NimbusSanCond", "CenturySch", "URWPalladio","NimbusRom") for (f in flist) { fn <- paste("utest_",f,".pdf",sep="") pdf(fn,family=f) TestUnicode() title(main=f) dev.off() embedFonts(fn) }
on Ubuntu, none of these files contains the symbols.
It would be nice to get it to work on as many combinations as possible, but especially in some vector format and double-especially in PDF.
Any suggestions about font/graphics device configurations that would make this work would be welcomed.
解决方案I think you are out of luck Ben, as, according to some notes by Paul Murrell,
pdf()
can only handle single-byte encodings. Multi-byte encodings need to be converted to a the single-byte equivalent, and therein lies the rub; by definition, single-byte encodings cannot contain all the glyphs that can be represented in a multi-byte encoding like UTF-8, say.Paul's notes can be found here wherein he suggests a couple of solutions using Cairo-based PDF devices, using
cairo_pdf()
on suitably-endowed Linux and Mac OS systems, or via theCairo
package under MS Windows.这篇关于在R图形中使用Unicode'dingbat-like'字形,跨设备&平台,特别是PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!