It was as easy as I thought it was half a day ago - here is a patch against R trunk to add cairo support to the Sweave driver, an example Sweave input, and the resulting output. A few more notes:
- obviously the documentation needs to be updated... a bit more work to do. - some check to make sure "cairo" and "pdf" are not both set would be nice, as well as checking capabilities() for cairo support, etc. - pdflatex from texlive2007 (fedora 15) emits a couple of warnings - but seems harmless enough: ================= pdfTeX warning: pdflatex (file ./CairoTest-another1.pdf): PDF inclusion: found PDF version <1.5>, but at most version <1.4> allowed pdfTeX warning: pdflatex (file ./CairoTest-another1.pdf): PDF inclusion: Page Group detected which pdfTeX can't handle. Ignoring it. ================== I am fairly sure that this is too late to be included in R 2.14 (already in code freeze and due in less than 10 days..), but harmless enough to go into trunk and 2.14.1? --- On Sat, 22/10/11, Hin-Tak Leung <ht...@users.sourceforge.net> wrote: > I have had some fun in the last few > days trying to put together an annotated map of China with R > and some public GIS data: > > http://sourceforge.net/projects/outmodedbonsai/files/snpMatrix%20next/1.17.7.11/China_Choropleth_Maps.pdf/download > > It is done, and rather nice... there are a few issues: > > - the default pdf() device cannot do CJK with embedded > fonts - and cairo_pdf() is not hooked up to Sweave yet. I > have had a quick look, and it does not look too complicated, > other than the fact that cairo_pdf() is mutually exclusive > with pdf(); and the jpeg/png are new to 2.13 so it is > probably just nobody has gotten round to it. (and > cairo_pdf() also behaves differently with the onefile > option). I guess I am almost saying I might get my hand > dirty or help somebody else who wants to. So it is probably > best to start some discussion. > > - Some of the ghostscript/CID font instructions in pdf() > are a bit bizarre... > > - An earlier version of the above map does not work well > with part of ghostscript > (http://bugs.ghostscript.com/show_bug.cgi?id=692620). So > that limits to some extent post-processing of cairo_pdf() > output. > > >
diff --git a/src/library/utils/R/SweaveDrivers.R b/src/library/utils/R/SweaveDrivers.R index 7336e7d..ca4b557 100644 --- a/src/library/utils/R/SweaveDrivers.R +++ b/src/library/utils/R/SweaveDrivers.R @@ -60,7 +60,7 @@ RweaveLatexSetup <- options <- list(prefix = TRUE, prefix.string = prefix.string, engine = "R", print = FALSE, eval = TRUE, fig = FALSE, - pdf = TRUE, eps = FALSE, png = FALSE, jpeg = FALSE, + pdf = TRUE, cairo=FALSE, eps = FALSE, png = FALSE, jpeg = FALSE, grdevice = "", width = 6, height = 6, resolution = 300, term = TRUE, echo = TRUE, keep.source = TRUE, results = "verbatim", @@ -98,6 +98,9 @@ makeRweaveLatexCodeRunner <- function(evalFunc = RweaveEvalWithOpt) version = options$pdf.version, encoding = options$pdf.encoding, compress = options$pdf.compress) + cairo.Swd <- function(name, width, height, ...) + grDevices::cairo_pdf(file = paste(chunkprefix, "pdf", sep = "."), + width = width, height = height) eps.Swd <- function(name, width, height, ...) grDevices::postscript(file = paste(name, "eps", sep = "."), width = width, height = height, @@ -119,6 +122,10 @@ makeRweaveLatexCodeRunner <- function(evalFunc = RweaveEvalWithOpt) devs <- c(devs, list(pdf.Swd)) devoffs <- c(devoffs, list(grDevices::dev.off)) } + if (options$cairo) { + devs <- c(devs, list(cairo.Swd)) + devoffs <- c(devoffs, list(grDevices::dev.off)) + } if (options$eps) { devs <- c(devs, list(eps.Swd)) devoffs <- c(devoffs, list(grDevices::dev.off)) @@ -151,6 +158,7 @@ makeRweaveLatexCodeRunner <- function(evalFunc = RweaveEvalWithOpt) if (options$fig) { if (options$eps) cat(" eps") if (options$pdf) cat(" pdf") + if (options$cairo) cat(" cairo") if (options$png) cat(" png") if (options$jpeg) cat(" jpeg") if (!is.null(options$grdevice)) cat("", options$grdevice)
CairoTest.pdf
Description: Adobe PDF document
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel