/hg/gfx-test: * postscript_renderer.properties:
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Fri May 4 05:37:43 PDT 2012
changeset e1207eaf717b in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=e1207eaf717b
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Fri May 04 14:40:21 2012 +0200
* postscript_renderer.properties:
Added property file containing configuration for a software PostScript
renderer.
* src/org/gfxtest/common/PostScriptRendererConfiguration.java:
* src/org/gfxtest/framework/PostScriptToPngConverter.java:
* src/org/gfxtest/framework/PrintingTest.java:
Classes which support rasterization from a PostScript file to a PNG
image.
* Makefile: Updated
diffstat:
ChangeLog | 12 +
Makefile | 3 +
postscript_renderer.properties | 7 +
src/org/gfxtest/common/PostScriptRendererConfiguration.java | 198 ++++++++++++
src/org/gfxtest/framework/PostScriptToPngConverter.java | 118 +++++++
src/org/gfxtest/framework/PrintingTest.java | 4 +
6 files changed, 342 insertions(+), 0 deletions(-)
diffs (397 lines):
diff -r 1e9fa50239df -r e1207eaf717b ChangeLog
--- a/ChangeLog Thu May 03 14:34:35 2012 +0200
+++ b/ChangeLog Fri May 04 14:40:21 2012 +0200
@@ -1,3 +1,15 @@
+2012-05-04 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * postscript_renderer.properties:
+ Added property file containing configuration for a software PostScript
+ renderer.
+ * src/org/gfxtest/common/PostScriptRendererConfiguration.java:
+ * src/org/gfxtest/framework/PostScriptToPngConverter.java:
+ * src/org/gfxtest/framework/PrintingTest.java:
+ Classes which support rasterization from a PostScript file to a PNG
+ image.
+ * Makefile: Updated
+
2012-05-03 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/gfxtest/testsuites/PrintTestLines.java:
diff -r 1e9fa50239df -r e1207eaf717b Makefile
--- a/Makefile Thu May 03 14:34:35 2012 +0200
+++ b/Makefile Fri May 04 14:40:21 2012 +0200
@@ -63,6 +63,7 @@
$(CLASSES)/$(COMMON_DIR)/InvalidParameterValueException.class \
$(CLASSES)/$(COMMON_DIR)/ConfigurationException.class \
$(CLASSES)/$(COMMON_DIR)/Configuration.class \
+ $(CLASSES)/$(COMMON_DIR)/PostScriptRendererConfiguration.class \
$(CLASSES)/$(REPORTER_DIR)/TestResult.class \
$(CLASSES)/$(REPORTER_DIR)/ReporterConfiguration.class \
$(CLASSES)/$(REPORTER_DIR)/Reporter.class \
@@ -92,6 +93,8 @@
$(CLASSES)/$(FRAMEWORK_DIR)/Log.class \
$(CLASSES)/$(FRAMEWORK_DIR)/ProceduralTextureFactory.class \
$(CLASSES)/$(FRAMEWORK_DIR)/ImageFactory.class \
+ $(CLASSES)/$(FRAMEWORK_DIR)/PostScriptToPngConverter.class \
+ $(CLASSES)/$(FRAMEWORK_DIR)/PrintingTest.class \
$(CLASSES)/$(IMAGE_DIFFER_DIR)/ComparisonResult.class \
$(CLASSES)/$(IMAGE_DIFFER_DIR)/Configuration.class \
$(CLASSES)/$(IMAGE_DIFFER_DIR)/ImageComparator.class \
diff -r 1e9fa50239df -r e1207eaf717b postscript_renderer.properties
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/postscript_renderer.properties Fri May 04 14:40:21 2012 +0200
@@ -0,0 +1,7 @@
+# This file is used to configure PostScript renderer (RIP)
+# which can render/rasterize PostScript files to a raster
+# images
+renderer_name = gs
+renderer_options = -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m
+dpi = 150
+
diff -r 1e9fa50239df -r e1207eaf717b src/org/gfxtest/common/PostScriptRendererConfiguration.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/gfxtest/common/PostScriptRendererConfiguration.java Fri May 04 14:40:21 2012 +0200
@@ -0,0 +1,198 @@
+/*
+ Java gfx-test framework
+
+ Copyright (C) 2012 Red Hat
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version.
+*/
+
+package org.gfxtest.common;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+
+
+/**
+ * Class representing configuration of PostScript renderer (RIP). This
+ * configuration is usually stored in a file named
+ * "postscript_renderer.properties".
+ *
+ * @author Pavel Tisnovsky
+ */
+public class PostScriptRendererConfiguration
+{
+ /**
+ * Property file containing configuration of PostScript renderer.
+ */
+ private static final String PROPERTIES_FILE_NAME = "postscript_renderer.properties";
+
+ /**
+ * Name of program used as software RIP.
+ */
+ private String rendererName = "gs";
+
+ /**
+ * Renderer options passed via command line.
+ */
+ private String rendererOptions = "";
+
+ /**
+ * Resolution of the image (not its width and height!).
+ */
+ private int dpi = 150;
+
+ /**
+ * Constructor which read renderer configuration from property file.
+ */
+ public PostScriptRendererConfiguration()
+ {
+ readConfiguration();
+ }
+
+ /**
+ * Read renderer configuration from property file.
+ */
+ private void readConfiguration()
+ {
+ // Read properties file.
+ FileInputStream fileInputStream = null;
+ try
+ {
+ fileInputStream = new FileInputStream(PROPERTIES_FILE_NAME);
+ readAllProperties(fileInputStream);
+ }
+ catch (FileNotFoundException e)
+ {
+ e.printStackTrace();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ // try to close input stream containing property information
+ if (fileInputStream != null)
+ {
+ try
+ {
+ fileInputStream.close();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /**
+ * Read renderer configuration from property file and set all attributes.
+ *
+ * @param fileInputStream
+ * @throws IOException
+ */
+ private void readAllProperties(FileInputStream fileInputStream) throws IOException
+ {
+ Properties properties = new Properties();
+ properties.load(fileInputStream);
+ this.setRendererName(properties.getProperty("renderer_name"));
+ this.setRendererOptions(properties.getProperty("renderer_options"));
+ this.setDpi(Integer.parseInt(properties.getProperty("dpi")));
+ }
+
+ /**
+ * Getter for an attribute rendererName.
+ *
+ * @return the rendererName
+ */
+ public String getRendererName()
+ {
+ return this.rendererName;
+ }
+
+ /**
+ * Setter for an attribute rendererName.
+ *
+ * @param rendererName the rendererName to set
+ */
+ public void setRendererName(String rendererName)
+ {
+ this.rendererName = rendererName;
+ }
+
+ /**
+ * Getter for an attribute rendererOptions.
+ *
+ * @return the rendererOptions
+ */
+ public String getRendererOptions()
+ {
+ return this.rendererOptions;
+ }
+
+ /**
+ * Setter for an attribute rendererOptions.
+ *
+ * @param rendererOptions the rendererOptions to set
+ */
+ public void setRendererOptions(String rendererOptions)
+ {
+ this.rendererOptions = rendererOptions;
+ }
+
+ /**
+ * Getter for an attribute dpi.
+ *
+ * @return the dpi
+ */
+ public int getDpi()
+ {
+ return this.dpi;
+ }
+
+ /**
+ * Setter for an attribute dpi.
+ *
+ * @param dpi the dpi to set
+ */
+ public void setDpi(int dpi)
+ {
+ this.dpi = dpi;
+ }
+}
diff -r 1e9fa50239df -r e1207eaf717b src/org/gfxtest/framework/PostScriptToPngConverter.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/gfxtest/framework/PostScriptToPngConverter.java Fri May 04 14:40:21 2012 +0200
@@ -0,0 +1,118 @@
+/*
+ Java gfx-test framework
+
+ Copyright (C) 2012 Red Hat
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version.
+*/
+
+package org.gfxtest.framework;
+
+import java.io.File;
+import java.io.IOException;
+
+
+
+import org.gfxtest.common.PostScriptRendererConfiguration;
+
+
+
+/**
+ * This class performs conversion from a PostScript file to a PNG file.
+ *
+ * @author Pavel Tisnovsky
+ */
+public class PostScriptToPngConverter
+{
+ /**
+ * Configuration of a PostScript software RIP
+ */
+ static PostScriptRendererConfiguration configuration = null;
+
+ /**
+ * Do the conversion from PostScript file to a PNG image.
+ *
+ * @param printOutputFile
+ * @param pngOutputFile
+ */
+ public static void convert(File printOutputFile, File pngOutputFile)
+ {
+ // load configuration and put it to a "cache"
+ if (configuration == null)
+ {
+ configuration = new PostScriptRendererConfiguration();
+ }
+
+ // prepare command for PostScript RIP
+ String command = prepareCommand(printOutputFile, pngOutputFile);
+ Runtime rt = Runtime.getRuntime();
+ try
+ {
+ // run PostScript RIP and wait for its finish
+ Process proc =rt.exec(command);
+ proc.waitFor();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Construct a command for a PostScript software RIP
+ *
+ * @param printOutputFile
+ * @param pngOutputFile
+ * @return command to be called via @see Runtime#exec
+ */
+ private static String prepareCommand(File printOutputFile, File pngOutputFile)
+ {
+ // renderer name and its basic parameters
+ String cmd = configuration.getRendererName() + " " + configuration.getRendererOptions() + " ";
+ // DPI specifier
+ String res = "-r" + configuration.getDpi() + " ";
+ // output file name
+ String output = "-o " + pngOutputFile.getPath() + " ";
+ // input file name
+ String input = " " + printOutputFile.getPath();
+ // put it all together
+ return cmd + res + output + input + " >> out 2>> err";
+ }
+
+}
diff -r 1e9fa50239df -r e1207eaf717b src/org/gfxtest/framework/PrintingTest.java
--- a/src/org/gfxtest/framework/PrintingTest.java Thu May 03 14:34:35 2012 +0200
+++ b/src/org/gfxtest/framework/PrintingTest.java Fri May 04 14:40:21 2012 +0200
@@ -154,8 +154,10 @@
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
+ this.gfxTest.log.log(this.getClass().getName(), "printBegin " + pageIndex);
/* we have only one page, and 'page' is zero-based */
if (pageIndex > 0) {
+ this.gfxTest.log.log(this.getClass().getName(), "printEnd no such page " + pageIndex);
return NO_SUCH_PAGE;
}
@@ -184,6 +186,8 @@
e.printStackTrace();
setResult(TestResult.ERROR);
}
+ graphics.dispose();
+ this.gfxTest.log.log(this.getClass().getName(), "printEnd");
/* tell the caller that this page is part of the printed document */
return PAGE_EXISTS;
More information about the distro-pkg-dev
mailing list