[rkward-cvs] SF.net SVN: rkward:[2778] trunk/rkward/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Mar 9 11:35:30 UTC 2010


Revision: 2778
          http://rkward.svn.sourceforge.net/rkward/?rev=2778&view=rev
Author:   tfry
Date:     2010-03-09 11:35:30 +0000 (Tue, 09 Mar 2010)

Log Message:
-----------
Add JPG to the available output formats. Safer handling of SVG.

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R
    trunk/rkward/rkward/resource.ver
    trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp
    trunk/rkward/rkward/settings/rksettingsmoduleoutput.h
    trunk/rkward/rkward/version.h

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2010-03-09 11:34:45 UTC (rev 2777)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2010-03-09 11:35:30 UTC (rev 2778)
@@ -136,12 +136,10 @@
 }
 
 # Requests a graph to be written.
-rk.graph.on <- function (width=getOption ("rk.graphics.width"), height=getOption ("rk.graphics.heigth"), ...) 
+rk.graph.on <- function (device.type=getOption ("rk.graphics.type"), width=getOption ("rk.graphics.width"), height=getOption ("rk.graphics.height"), quality, ...) 
 {
 	if (!is.numeric (width)) width <- 480
 	if (!is.numeric (height)) height <- 480
-
-	device.type <- getOption ("rk.graphics.type")
 	if (is.null (device.type)) device.type <- "PNG"	# default behavior is PNG for now
 
 	ret <- NULL
@@ -150,7 +148,17 @@
 		ret <- png(filename = file.path(filename), width = width, height = height, ...)
 		.rk.cat.output(paste("<img src=\"", filename, "\" width=\"", width, 
 			"\" height=\"", height, "\"><br>", sep = ""))
+	} else if (device.type == "JPG") {
+		if (missing (quality)) quality = getOption ("rk.graphics.jpg.quality", 75)
+		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, 
+			"\" height=\"", height, "\"><br>", sep = ""))
 	} else if (device.type == "SVG") {
+		if (!capabilities ("cairo")) {	# cairo support is not always compiled in
+			require (cairoDevice)
+			svg <- Cairo_svg
+		}
 		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, 

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R	2010-03-09 11:34:45 UTC (rev 2777)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R	2010-03-09 11:35:30 UTC (rev 2778)
@@ -1 +1 @@
-".rk.app.version" <- "0.5.3-test1"
+".rk.app.version" <- "0.5.3-test2"

Modified: trunk/rkward/rkward/resource.ver
===================================================================
--- trunk/rkward/rkward/resource.ver	2010-03-09 11:34:45 UTC (rev 2777)
+++ trunk/rkward/rkward/resource.ver	2010-03-09 11:35:30 UTC (rev 2778)
@@ -1 +1 @@
-0.5.3-test1
+0.5.3-test2

Modified: trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp	2010-03-09 11:34:45 UTC (rev 2777)
+++ trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp	2010-03-09 11:35:30 UTC (rev 2778)
@@ -38,6 +38,7 @@
 QString RKSettingsModuleOutput::graphics_type;
 int RKSettingsModuleOutput::graphics_width;
 int RKSettingsModuleOutput::graphics_height;
+int RKSettingsModuleOutput::graphics_jpg_quality;
 
 RKSettingsModuleOutput::RKSettingsModuleOutput (RKSettings *gui, QWidget *parent) : RKSettingsModule(gui, parent) {
 	RK_TRACE (SETTINGS);
@@ -62,17 +63,25 @@
 	group_layout->addLayout (h_layout);
 	h_layout->addWidget (new QLabel (i18n ("File format"), group));
 	h_layout->addWidget (graphics_type_box = new QComboBox (group));
-	h_layout->addStretch ();
 	graphics_type_box->addItem (i18n ("<Default>"), QString ("NULL"));
 	graphics_type_box->addItem (i18n ("PNG"), QString ("\"PNG\""));
 	graphics_type_box->addItem (i18n ("SVG"), QString ("\"SVG\""));
+	graphics_type_box->addItem (i18n ("JPG"), QString ("\"JPG\""));
 	graphics_type_box->setCurrentIndex (graphics_type_box->findData (graphics_type));
 	graphics_type_box->setEditable (false);
 	connect (graphics_type_box, SIGNAL (currentIndexChanged (int)), this, SLOT (boxChanged (int)));
+	h_layout->addSpacing (2*RKGlobals::spacingHint ());
+	h_layout->addWidget (new QLabel (i18n ("JPG quality"), group));
+	h_layout->addWidget (graphics_jpg_quality_box = new KIntSpinBox (1, 100, 1, graphics_jpg_quality, group));
+	graphics_jpg_quality_box->setEnabled (graphics_type == "\"JPG\"");
+	connect (graphics_jpg_quality_box, SIGNAL (valueChanged (int)), this, SLOT (boxChanged (int)));
+	h_layout->addStretch ();
+
 	h_layout = new QHBoxLayout (group);
 	group_layout->addLayout (h_layout);
 	h_layout->addWidget (new QLabel (i18n ("Width:"), group));
 	h_layout->addWidget (graphics_width_box = new KIntSpinBox (1, INT_MAX, 1, graphics_width, group));
+	h_layout->addSpacing (2*RKGlobals::spacingHint ());
 	h_layout->addWidget (new QLabel (i18n ("Height:"), group));
 	h_layout->addWidget (graphics_height_box = new KIntSpinBox (1, INT_MAX, 1, graphics_height, group));
 	h_layout->addStretch ();
@@ -92,6 +101,7 @@
 	RK_TRACE (SETTINGS);
 	change ();
 	auto_raise_box->setEnabled (auto_show_box->isChecked ());
+	graphics_jpg_quality_box->setEnabled (graphics_type_box->itemData (graphics_type_box->currentIndex ()).toString () == "\"JPG\"");
 }
 
 QString RKSettingsModuleOutput::caption () {
@@ -113,6 +123,7 @@
 	graphics_type = graphics_type_box->itemData (graphics_type_box->currentIndex ()).toString ();
 	graphics_width = graphics_width_box->value ();
 	graphics_height = graphics_height_box->value ();
+	graphics_jpg_quality = graphics_jpg_quality_box->value ();
 	QStringList commands = makeRRunTimeOptionCommands ();
 	for (QStringList::const_iterator it = commands.begin (); it != commands.end (); ++it) {
 		RKGlobals::rInterface ()->issueCommand (*it, RCommand::App, QString::null, 0, 0, commandChain ());
@@ -134,6 +145,7 @@
 	cg.writeEntry ("graphics_type", graphics_type);
 	cg.writeEntry ("graphics_width", graphics_width);
 	cg.writeEntry ("graphics_height", graphics_height);
+	cg.writeEntry ("graphics_jpg_quality", graphics_jpg_quality);
 }
 
 void RKSettingsModuleOutput::loadSettings (KConfig *config) {
@@ -145,6 +157,7 @@
 	graphics_type = cg.readEntry ("graphics_type", "NULL");
 	graphics_width = cg.readEntry ("graphics_width", 480);
 	graphics_height = cg.readEntry ("graphics_height", 480);
+	graphics_jpg_quality = cg.readEntry ("graphics_jpg_quality", 75);
 }
 
 //static
@@ -155,6 +168,7 @@
 	QString command = "options (\"rk.graphics.type\"=" + graphics_type;
 	command.append (", \"rk.graphics.width\"=" + QString::number (graphics_width));
 	command.append (", \"rk.graphics.height\"=" + QString::number (graphics_height));
+	if (graphics_type == "\"JPG\"") command.append (", \"rk.graphics.jpg.quality\"=" + QString::number (graphics_jpg_quality));
 	list.append (command + ")\n");
 	
 	return (list);

Modified: trunk/rkward/rkward/settings/rksettingsmoduleoutput.h
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleoutput.h	2010-03-09 11:34:45 UTC (rev 2777)
+++ trunk/rkward/rkward/settings/rksettingsmoduleoutput.h	2010-03-09 11:35:30 UTC (rev 2778)
@@ -56,12 +56,14 @@
 	QComboBox *graphics_type_box;
 	KIntSpinBox *graphics_width_box;
 	KIntSpinBox *graphics_height_box;
+	KIntSpinBox *graphics_jpg_quality_box;
 
 	static bool auto_show;
 	static bool auto_raise;
 	static QString graphics_type;
 	static int graphics_width;
 	static int graphics_height;
+	static int graphics_jpg_quality;
 };
 
 #endif

Modified: trunk/rkward/rkward/version.h
===================================================================
--- trunk/rkward/rkward/version.h	2010-03-09 11:34:45 UTC (rev 2777)
+++ trunk/rkward/rkward/version.h	2010-03-09 11:35:30 UTC (rev 2778)
@@ -1,2 +1,2 @@
 /* Version number of package */
-#define VERSION "0.5.3-test1"
+#define VERSION "0.5.3-test2"


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list