/hg/gfx-test: * src/org/gfxtest/framework/PrintingTest.java:
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Fri Apr 20 06:20:21 PDT 2012
changeset f72558a932b2 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=f72558a932b2
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Fri Apr 20 15:22:51 2012 +0200
* src/org/gfxtest/framework/PrintingTest.java:
Fixed computations of image size based on page properties.
Refactoring, added JavaDoc.
diffstat:
ChangeLog | 6 +
src/org/gfxtest/framework/PrintingTest.java | 98 ++++++++++++++++++++++++----
2 files changed, 90 insertions(+), 14 deletions(-)
diffs (191 lines):
diff -r a630b16209f8 -r f72558a932b2 ChangeLog
--- a/ChangeLog Thu Apr 19 17:39:58 2012 +0200
+++ b/ChangeLog Fri Apr 20 15:22:51 2012 +0200
@@ -1,3 +1,9 @@
+2012-04-20 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/gfxtest/framework/PrintingTest.java:
+ Fixed computations of image size based on page properties.
+ Refactoring, added JavaDoc.
+
2012-04-19 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/gfxtest/testsuites/ClippingPathByRectangleShape.java:
diff -r a630b16209f8 -r f72558a932b2 src/org/gfxtest/framework/PrintingTest.java
--- a/src/org/gfxtest/framework/PrintingTest.java Thu Apr 19 17:39:58 2012 +0200
+++ b/src/org/gfxtest/framework/PrintingTest.java Fri Apr 20 15:22:51 2012 +0200
@@ -48,12 +48,40 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+
+
+/**
+ * Implementation of the framework used to prepare and run printing tests.
+ * Output of such tests are stored in a PostScript file which could be rendered
+ * using GhostScript or other implementation of PostScript language.
+ *
+ * @author Pavel Tisnovsky
+ */
public class PrintingTest implements Printable
{
+ /**
+ * Used to run the selected test
+ */
private GfxTest gfxTest;
+
+ /**
+ * Method of selected test which should be called
+ */
private Method method;
+
+ /**
+ * Test result
+ */
private TestResult result = null;
+ /**
+ * Constructor which configures printing test framework.
+ *
+ * @param gfxTest
+ * used to run the selected test
+ * @param method
+ * method of selected test which should be called
+ */
public PrintingTest(GfxTest gfxTest, Method method)
{
setGfxTest(gfxTest);
@@ -61,6 +89,8 @@
}
/**
+ * Get the current value of attribute method.
+ *
* @return the method
*/
public Method getMethod()
@@ -69,6 +99,8 @@
}
/**
+ * Set a new value of a attribute method.
+ *
* @param method the method to set
*/
public void setMethod(Method method)
@@ -77,6 +109,8 @@
}
/**
+ * Get the current value of attribute result.
+ *
* @return the result
*/
public TestResult getResult()
@@ -85,6 +119,8 @@
}
/**
+ * Set a new value of a attribute method.
+ *
* @param result the result to set
*/
public void setResult(TestResult result)
@@ -93,6 +129,8 @@
}
/**
+ * Get the current value of attribute gfxTest.
+ *
* @return the gfxTest
*/
public GfxTest getGfxTest()
@@ -101,6 +139,8 @@
}
/**
+ * Set a new value of a attribute gfxTest.
+ *
* @param gfxTest the gfxTest to set
*/
public void setGfxTest(GfxTest gfxTest)
@@ -108,19 +148,23 @@
this.gfxTest = gfxTest;
}
+ /**
+ * Prints the page at the specified index into the specified Graphics context in the specified format.
+ */
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
- if (pageIndex > 0) { /* We have only one page, and 'page' is zero-based */
+ /* we have only one page, and 'page' is zero-based */
+ if (pageIndex > 0) {
return NO_SUCH_PAGE;
}
-
- /* Origin (0,0) is typically outside the imageable area, so we must
- * translate by the X and Y values in the PageFormat to avoid clipping
- */
+
Graphics2D gc = (Graphics2D)graphics;
- gc.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
- TestImage image = new TestImage(pageFormat.getWidth(), pageFormat.getHeight());
+ translateCoordinateSystem(pageFormat, gc);
+
+ /* create test image with the width and height based of page format */
+ TestImage image = createTestImage(pageFormat);
+
try
{
setResult((TestResult) this.method.invoke(getGfxTest(), new Object[] { image, gc }));
@@ -141,15 +185,41 @@
setResult(TestResult.ERROR);
}
- /*
- graphics.setColor(Color.RED);
- graphics.drawLine(0, 0, (int)pageFormat.getWidth(), (int)pageFormat.getHeight());
- graphics.drawLine((int)pageFormat.getWidth(), 0, 0, (int)pageFormat.getHeight());
-
- graphics.drawString("Hello world!", 100, 100);
- */
/* tell the caller that this page is part of the printed document */
return PAGE_EXISTS;
}
+ /**
+ * Translate coordinate system used to put graphics object into a page.
+ *
+ * Origin (0,0) is typically outside the imageable area, so we must
+ * translate by the X and Y values in the PageFormat to avoid clipping
+ *
+ * @param pageFormat
+ * object containing the size and orientation of a page to be
+ * printed.
+ * @param gc graphics context
+ */
+ private void translateCoordinateSystem(PageFormat pageFormat, Graphics2D gc)
+ {
+ gc.translate(pageFormat.getImageableX() * 2, pageFormat.getImageableY() * 2);
+ }
+
+ /**
+ * Create test image with the width and height based of page format.
+ *
+ * @param pageFormat
+ * object containing the size and orientation of a page to be
+ * printed.
+ * @return object representing raster image on which shapes are rendered.
+ */
+ private TestImage createTestImage(PageFormat pageFormat)
+ {
+ final double width = pageFormat.getImageableWidth();
+ final double height = pageFormat.getImageableHeight();
+ final double xoffset = pageFormat.getImageableX();
+ final double yoffset = pageFormat.getImageableY();
+ return new TestImage(width - xoffset, height - yoffset);
+ }
+
}
More information about the distro-pkg-dev
mailing list