/hg/gfx-test: * src/org/gfxtest/testsuites/GradientPaint.java:
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Thu Aug 18 03:33:36 PDT 2011
changeset 086679317267 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=086679317267
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Thu Aug 18 12:35:19 2011 +0200
* src/org/gfxtest/testsuites/GradientPaint.java: Created new test
suite containing 16 new gfx.tests.
* src/org/gfxtest/common/CommonShapesRenderer.java: Make static method
calculateRadius() public.
* src/org/gfxtest/common/CommonRenderingStyles.java: Added methods
supporting rendering shapes filled by gradient paint.
diffstat:
ChangeLog | 8 +
src/org/gfxtest/framework/CommonRenderingStyles.java | 244 ++++++++++
src/org/gfxtest/framework/CommonShapesRenderer.java | 2 +-
src/org/gfxtest/testsuites/GradientPaint.java | 422 +++++++++++++++++++
4 files changed, 675 insertions(+), 1 deletions(-)
diffs (truncated from 721 to 500 lines):
diff -r db95c4ecbdfc -r 086679317267 ChangeLog
--- a/ChangeLog Wed Aug 17 13:01:08 2011 +0200
+++ b/ChangeLog Thu Aug 18 12:35:19 2011 +0200
@@ -1,3 +1,11 @@
+2011-08-18 Pavel Tisnovsky <ptisnovs at redhat.com>
+ * src/org/gfxtest/testsuites/GradientPaint.java:
+ Created new test suite containing 16 new gfx.tests.
+ * src/org/gfxtest/common/CommonShapesRenderer.java:
+ Make static method calculateRadius() public.
+ * src/org/gfxtest/common/CommonRenderingStyles.java:
+ Added methods supporting rendering shapes filled by gradient paint.
+
2011-08-17 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/gfxtest/common/Configuration.java:
Added JavaDoc.
diff -r db95c4ecbdfc -r 086679317267 src/org/gfxtest/framework/CommonRenderingStyles.java
--- a/src/org/gfxtest/framework/CommonRenderingStyles.java Wed Aug 17 13:01:08 2011 +0200
+++ b/src/org/gfxtest/framework/CommonRenderingStyles.java Thu Aug 18 12:35:19 2011 +0200
@@ -42,6 +42,7 @@
import java.awt.BasicStroke;
import java.awt.Color;
+import java.awt.GradientPaint;
import java.awt.Graphics2D;
@@ -75,6 +76,16 @@
private static final Color DEFAULT_FILL_COLOR = Color.GREEN.darker();
/**
+ * Default gradient paint first color.
+ */
+ private static final Color DEFAULT_GRADIENT_PAINT_FIRST_COLOR = Color.RED;
+
+ /**
+ * Default gradient paint second color.
+ */
+ private static final Color DEFAULT_GRADIENT_PAINT_SECOND_COLOR = Color.YELLOW;
+
+ /**
* Set default stroke color.
*
* @param graphics
@@ -168,6 +179,239 @@
}
/**
+ * Set horizontal gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ */
+ public static void setHorizontalGradientFill(TestImage image, Graphics2D graphics)
+ {
+ setHorizontalGradientFill(image, graphics, DEFAULT_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_GRADIENT_PAINT_SECOND_COLOR);
+ }
+
+ /**
+ * Set horizontal gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @param offset
+ * offset between shape border and edge of horizontal gradient,
+ * positive offset: gradient is narrower, negative offset:
+ * gradient is broader
+ */
+ public static void setHorizontalGradientFill(TestImage image, Graphics2D graphics, int offset)
+ {
+ setHorizontalGradientFill(image, graphics, DEFAULT_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_GRADIENT_PAINT_SECOND_COLOR, offset);
+ }
+
+ /**
+ * Set horizontal gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @param color1
+ * color set for the first edge of gradient fill
+ * @param color2
+ * color set for the second edge of gradient fill
+ */
+ public static void setHorizontalGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2)
+ {
+ setHorizontalGradientFill(image, graphics, color1, color2, 0);
+ }
+
+ /**
+ * Set horizontal gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @param color1
+ * color set for the first edge of gradient fill
+ * @param color2
+ * color set for the second edge of gradient fill
+ * @param offset
+ * offset between shape border and edge of horizontal gradient
+ */
+ public static void setHorizontalGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2, int offset)
+ {
+ // calculate center of the image
+ int xc = image.getCenterX();
+ int yc = image.getCenterY();
+
+ // calculate radius of circle
+ int radius = CommonShapesRenderer.calculateRadius(image);
+
+ GradientPaint gradientPaint = new GradientPaint(xc - radius + offset, yc, color1, xc + radius - offset, yc, color2);
+ graphics.setPaint(gradientPaint);
+ }
+
+ /**
+ * Set vertical gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ */
+ public static void setVerticalGradientFill(TestImage image, Graphics2D graphics)
+ {
+ setVerticalGradientFill(image, graphics, DEFAULT_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_GRADIENT_PAINT_SECOND_COLOR);
+ }
+
+ /**
+ * Set vertical gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @param offset
+ * offset between shape border and edge of horizontal gradient,
+ * positive offset: gradient is narrower, negative offset:
+ * gradient is broader
+ */
+ public static void setVerticalGradientFill(TestImage image, Graphics2D graphics, int offset)
+ {
+ setVerticalGradientFill(image, graphics, DEFAULT_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_GRADIENT_PAINT_SECOND_COLOR, offset);
+ }
+
+ /**
+ * Set vertical gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @param color1
+ * color set for the first edge of gradient fill
+ * @param color2
+ * color set for the second edge of gradient fill
+ */
+ public static void setVerticalGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2)
+ {
+ setVerticalGradientFill(image, graphics, color1, color2, 0);
+ }
+
+ /**
+ * Set vertical gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @param color1
+ * color set for the first edge of gradient fill
+ * @param color2
+ * color set for the second edge of gradient fill
+ * @param offset
+ * offset between shape border and edge of horizontal gradient
+ */
+ public static void setVerticalGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2, int offset)
+ {
+ // calculate center of the image
+ int xc = image.getCenterX();
+ int yc = image.getCenterY();
+
+ // calculate radius of circle
+ int radius = CommonShapesRenderer.calculateRadius(image);
+
+ GradientPaint gradientPaint = new GradientPaint(xc, yc - radius + offset, color1, xc, yc + radius - offset, color2);
+ graphics.setPaint(gradientPaint);
+ }
+
+ /**
+ * Set diagonal gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ */
+ public static void setDiagonalGradientFill(TestImage image, Graphics2D graphics)
+ {
+ setDiagonalGradientFill(image, graphics, DEFAULT_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_GRADIENT_PAINT_SECOND_COLOR);
+ }
+
+ /**
+ * Set diagonal gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @param offset
+ * offset between shape border and edge of horizontal gradient,
+ * positive offset: gradient is narrower, negative offset:
+ * gradient is broader
+ */
+ public static void setDiagonalGradientFill(TestImage image, Graphics2D graphics, int offset)
+ {
+ setDiagonalGradientFill(image, graphics, DEFAULT_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_GRADIENT_PAINT_SECOND_COLOR, offset);
+ }
+
+ /**
+ * Set diagonal gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @param color1
+ * color set for the first edge of gradient fill
+ * @param color2
+ * color set for the second edge of gradient fill
+ */
+ public static void setDiagonalGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2)
+ {
+ setDiagonalGradientFill(image, graphics, color1, color2, 0);
+ }
+
+ /**
+ * Set diagonal gradient fill for given graphics context.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @param color1
+ * color set for the first edge of gradient fill
+ * @param color2
+ * color set for the second edge of gradient fill
+ * @param offset
+ * offset between shape border and edge of horizontal gradient
+ */
+ public static void setDiagonalGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2, int offset)
+ {
+ // sin 45 = cos 45 = 0.707f
+ final double SIN_COS_45 = Math.cos(Math.PI / 4);
+
+ // calculate center of the image
+ int xc = image.getCenterX();
+ int yc = image.getCenterY();
+
+ // calculate radius of circle
+ int radius = CommonShapesRenderer.calculateRadius(image);
+ int r2 = (int)(radius * SIN_COS_45 );
+ int delta = (int) (offset * SIN_COS_45);
+
+ // compute end points used for diagonal fill
+ int x1 = xc - r2 + delta;
+ int y1 = yc - r2 + delta;
+ int x2 = xc + r2 - delta;
+ int y2 = yc + r2 - delta;
+
+ GradientPaint gradientPaint = new GradientPaint(x1, y1, color1, x2, y2, color2);
+ graphics.setPaint(gradientPaint);
+ }
+
+ /**
* Set zero pixels wide stroke and default cap and join style.
*
* @param graphics
diff -r db95c4ecbdfc -r 086679317267 src/org/gfxtest/framework/CommonShapesRenderer.java
--- a/src/org/gfxtest/framework/CommonShapesRenderer.java Wed Aug 17 13:01:08 2011 +0200
+++ b/src/org/gfxtest/framework/CommonShapesRenderer.java Thu Aug 18 12:35:19 2011 +0200
@@ -66,7 +66,7 @@
* image to which two dimensional shape is to be rendered
* @return radius
*/
- private static int calculateRadius(TestImage image)
+ public static int calculateRadius(TestImage image)
{
return Math.min(image.getWidth(), image.getHeight()) / 3;
}
diff -r db95c4ecbdfc -r 086679317267 src/org/gfxtest/testsuites/GradientPaint.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/gfxtest/testsuites/GradientPaint.java Thu Aug 18 12:35:19 2011 +0200
@@ -0,0 +1,422 @@
+/*
+ Java gfx-test framework
+
+ Copyright (C) 2010, 2011 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.testsuites;
+
+
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+
+
+
+import org.gfxtest.framework.*;
+import org.gfxtest.framework.annotations.*;
+
+/**
+ * This test renders filled shapes using simple ColorPaint.
+ *
+ * @author Pavel Tisnovsky
+ */
+ at TestType(TestTypes.RENDER_TEST)
+ at RenderStyle(RenderStyles.FILL)
+ at Transformation(Transformations.NONE)
+ at Zoom(1)
+public class GradientPaint extends GfxTest
+{
+ /**
+ * Test if circle drawn by graphics.drawOval() is rendered correctly.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @return test result status - PASSED, FAILED or ERROR
+ */
+ public TestResult testCircleEmptyFill(TestImage image, Graphics2D graphics)
+ {
+ // set stroke color
+ CommonRenderingStyles.setStrokeColor(graphics);
+ // draw the circle
+ CommonShapesRenderer.drawCircle(image, graphics);
+ // test return value
+ return TestResult.PASSED;
+ }
+
+ /**
+ * Test if filled circle drawn by graphics.fillOval() is rendered correctly.
+ * Horizontal gradient paint is used for filling this circle.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @return test result status - PASSED, FAILED or ERROR
+ */
+ public TestResult testCircleHorizontalGradientFill(TestImage image, Graphics2D graphics)
+ {
+ // set stroke color
+ CommonRenderingStyles.setStrokeColor(graphics);
+ // set fill color
+ CommonRenderingStyles.setHorizontalGradientFill(image, graphics);
+ // draw the circle
+ CommonShapesRenderer.drawFilledCircle(image, graphics);
+ // test return value
+ return TestResult.PASSED;
+ }
+
+ /**
+ * Test if filled circle drawn by graphics.fillOval() is rendered correctly.
+ * Horizontal gradient paint is used for filling this circle.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @return test result status - PASSED, FAILED or ERROR
+ */
+ public TestResult testCircleHorizontalGradientFillPositiveOffset1(TestImage image, Graphics2D graphics)
+ {
+ // set stroke color
+ CommonRenderingStyles.setStrokeColor(graphics);
+ // set fill color
+ CommonRenderingStyles.setHorizontalGradientFill(image, graphics, image.getWidth() / 16);
+ // draw the circle
+ CommonShapesRenderer.drawFilledCircle(image, graphics);
+ // test return value
+ return TestResult.PASSED;
+ }
+
+ /**
+ * Test if filled circle drawn by graphics.fillOval() is rendered correctly.
+ * Horizontal gradient paint is used for filling this circle.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @return test result status - PASSED, FAILED or ERROR
+ */
+ public TestResult testCircleHorizontalGradientFillPositiveOffset2(TestImage image, Graphics2D graphics)
+ {
+ // set stroke color
+ CommonRenderingStyles.setStrokeColor(graphics);
+ // set fill color
+ CommonRenderingStyles.setHorizontalGradientFill(image, graphics, image.getWidth() / 6);
+ // draw the circle
+ CommonShapesRenderer.drawFilledCircle(image, graphics);
+ // test return value
+ return TestResult.PASSED;
+ }
+
+ /**
+ * Test if filled circle drawn by graphics.fillOval() is rendered correctly.
+ * Horizontal gradient paint is used for filling this circle.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @return test result status - PASSED, FAILED or ERROR
+ */
+ public TestResult testCircleHorizontalGradientFillNegativeOffset1(TestImage image, Graphics2D graphics)
+ {
+ // set stroke color
+ CommonRenderingStyles.setStrokeColor(graphics);
+ // set fill color
+ CommonRenderingStyles.setHorizontalGradientFill(image, graphics, - image.getWidth() / 16);
+ // draw the circle
+ CommonShapesRenderer.drawFilledCircle(image, graphics);
+ // test return value
+ return TestResult.PASSED;
+ }
+
+ /**
+ * Test if filled circle drawn by graphics.fillOval() is rendered correctly.
+ * Horizontal gradient paint is used for filling this circle.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @return test result status - PASSED, FAILED or ERROR
+ */
+ public TestResult testCircleHorizontalGradientFillNegativeOffset2(TestImage image, Graphics2D graphics)
+ {
+ // set stroke color
+ CommonRenderingStyles.setStrokeColor(graphics);
+ // set fill color
+ CommonRenderingStyles.setHorizontalGradientFill(image, graphics, - image.getWidth() / 6);
+ // draw the circle
+ CommonShapesRenderer.drawFilledCircle(image, graphics);
+ // test return value
+ return TestResult.PASSED;
+ }
+
+ /**
+ * Test if filled circle drawn by graphics.fillOval() is rendered correctly.
+ * Vertical gradient paint is used for filling this circle.
+ *
+ * @param image
+ * image to which two dimensional shape is to be rendered
+ * @param graphics
+ * graphics context for image
+ * @return test result status - PASSED, FAILED or ERROR
More information about the distro-pkg-dev
mailing list