[rkward/releases/0.6.4] rkward/rbackend/rpackages/rkward/R: Help webkit understand local file paths to images on Windows.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Fri Feb 19 21:12:17 UTC 2016


Git commit 8b44b7547bb0d26b3d47cf39c12d35c6127b4975 by Thomas Friedrichsmeier.
Committed on 19/02/2016 at 21:10.
Pushed by tfry into branch 'releases/0.6.4'.

Help webkit understand local file paths to images on Windows.

NOTE: Bug ticket will be closed, once updates Windows binaries are available.

CCBUG: 359404

M  +12   -4    rkward/rbackend/rpackages/rkward/R/public_graphics.R

http://commits.kde.org/rkward/8b44b7547bb0d26b3d47cf39c12d35c6127b4975

diff --git a/rkward/rbackend/rpackages/rkward/R/public_graphics.R b/rkward/rbackend/rpackages/rkward/R/public_graphics.R
index e56b08b..4b941ad 100644
--- a/rkward/rbackend/rpackages/rkward/R/public_graphics.R
+++ b/rkward/rbackend/rpackages/rkward/R/public_graphics.R
@@ -45,6 +45,14 @@
 #' @rdname rk.graph.on
 "rk.graph.on" <- function (device.type=getOption ("rk.graphics.type"), width=getOption ("rk.graphics.width"), height=getOption ("rk.graphics.height"), quality, ...) 
 {
+	make.url <- function (filename) {
+		if (substr (filename, 1, 1) != "/") {  # this generally happens on Windows
+			paste ("file:///", filename, sep="")
+		} else {
+			paste ("file://", filename, sep="")
+		}
+	}
+
 	if (!is.numeric (width)) width <- 480
 	if (!is.numeric (height)) height <- 480
 	if (is.null (device.type)) device.type <- "PNG"	# default behavior is PNG for now
@@ -55,7 +63,7 @@
 	if (device.type == "PNG") {
 		filename <- rk.get.tempfile.name(prefix = "graph", extension = ".png")
 		ret <- png(filename = file.path(filename), width = width, height = height, ...)
-		.rk.cat.output(paste("<img src=\"", filename, "\" width=\"", width, 
+		.rk.cat.output(paste("<img src=\"", make.url (filename), "\" width=\"", width,
 			"\" height=\"", height, "\"><br>", sep = ""))
 	} else if (device.type == "JPG") {
 		if (missing (quality)) {
@@ -64,7 +72,7 @@
 		}
 		filename <- rk.get.tempfile.name(prefix = "graph", extension = ".jpg")
 		ret <- jpeg(filename = file.path(filename), width = width, height = height, "quality"=quality, ...)
-		.rk.cat.output(paste("<img src=\"", filename, "\" width=\"", width, 
+		.rk.cat.output(paste("<img src=\"", make.url (filename), "\" width=\"", width,
 			"\" height=\"", height, "\"><br>", sep = ""))
 	} else if (device.type == "SVG") {
 		if (!capabilities ("cairo")) {	# cairo support is not always compiled in
@@ -73,9 +81,9 @@
 		}
 		filename <- rk.get.tempfile.name(prefix = "graph", extension = ".svg")
 		ret <- svg(filename = file.path(filename), ...)
-		.rk.cat.output(paste("<object data=\"", filename, "\" type=\"image/svg+xml\" width=\"", width, 
+		.rk.cat.output(paste("<object data=\"", make.url (filename), "\" type=\"image/svg+xml\" width=\"", width,
 			"\" height=\"", height, "\">\n", sep = ""))
-		.rk.cat.output(paste("<param name=\"src\" value=\"", filename, "\">\n", sep = ""))
+		.rk.cat.output(paste("<param name=\"src\" value=\"", make.url (filename), "\">\n", sep = ""))
 		.rk.cat.output(paste("This browser appears incapable of displaying SVG object. The SVG source is at:", filename))
 		.rk.cat.output("</object>")
 	} else {



More information about the rkward-tracker mailing list