/hg/gfx-test: * Makefile: added new classes to compile

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Mon Sep 5 02:26:33 PDT 2011


changeset 49478d158096 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=49478d158096
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Mon Sep 05 11:28:26 2011 +0200

	* Makefile: added new classes to compile
	* src/org/gfxtest/framework/CommonRenderingStyles.java: Added
	methods supporting rendering shapes filled by linear gradient
	paint.
	* src/org/gfxtest/testsuites/LinearGradientPaint.java: Added new
	test suite containing 16 new gfx.tests.


diffstat:

 ChangeLog                                            |    8 +
 Makefile                                             |   10 +-
 src/org/gfxtest/framework/CommonRenderingStyles.java |  270 ++++++++++++
 src/org/gfxtest/testsuites/LinearGradientPaint.java  |  419 +++++++++++++++++++
 4 files changed, 705 insertions(+), 2 deletions(-)

diffs (truncated from 759 to 500 lines):

diff -r 6c985b5ee97e -r 49478d158096 ChangeLog
--- a/ChangeLog	Fri Sep 02 10:39:52 2011 +0200
+++ b/ChangeLog	Mon Sep 05 11:28:26 2011 +0200
@@ -1,3 +1,11 @@
+2011-09-05  Pavel Tisnovsky  <ptisnovs at redhat.com>
+	* Makefile: added new classes to compile
+	* src/org/gfxtest/framework/CommonRenderingStyles.java:
+	Added methods supporting rendering shapes filled by linear gradient
+	paint.
+	* src/org/gfxtest/testsuites/LinearGradientPaint.java:
+	Added new test suite containing 16 new gfx.tests.
+
 2011-09-02  Pavel Tisnovsky  <ptisnovs at redhat.com>
 	* src/org/gfxtest/testsuites/SpecialCases.java:
 	Added 6 new test cases, added JavaDoc to existing test cases.
diff -r 6c985b5ee97e -r 49478d158096 Makefile
--- a/Makefile	Fri Sep 02 10:39:52 2011 +0200
+++ b/Makefile	Mon Sep 05 11:28:26 2011 +0200
@@ -130,7 +130,10 @@
 	$(CLASSES)/$(TESTSUITE_DIR)/DashedRectangles.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/DashedRoundRectangles.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PathsFromLines.class \
-	$(CLASSES)/$(TESTSUITE_DIR)/SpecialCases.class
+	$(CLASSES)/$(TESTSUITE_DIR)/SpecialCases.class \
+	$(CLASSES)/$(TESTSUITE_DIR)/GradientPaint.class \
+	$(CLASSES)/$(TESTSUITE_DIR)/LinearGradientPaint.class \
+	$(CLASSES)/$(TESTSUITE_DIR)/RadialGradientPaint.class
 
 COMPARE_RESULTS = \
 	$(RESULTS)/AALines \
@@ -167,7 +170,10 @@
 	$(RESULTS)/DashedRectangles \
 	$(RESULTS)/DashedRoundRectangles \
 	$(RESULTS)/PathsFromLines \
-	$(RESULTS)/SpecialCases
+	$(RESULTS)/SpecialCases \
+	$(RESULTS)/GradientPaint \
+	$(RESULTS)/LinearGradientPaint \
+	$(RESULTS)/RadialGradientPaint
 
 # targets for all test suites
 TESTSUITES = $(shell ls -1 src/org/gfxtest/testsuites | sed -n -e 's/\([A-Za-z0-9]*\)\.java/\1/p')
diff -r 6c985b5ee97e -r 49478d158096 src/org/gfxtest/framework/CommonRenderingStyles.java
--- a/src/org/gfxtest/framework/CommonRenderingStyles.java	Fri Sep 02 10:39:52 2011 +0200
+++ b/src/org/gfxtest/framework/CommonRenderingStyles.java	Mon Sep 05 11:28:26 2011 +0200
@@ -44,6 +44,7 @@
 import java.awt.Color;
 import java.awt.GradientPaint;
 import java.awt.Graphics2D;
+import java.awt.LinearGradientPaint;
 import java.awt.RadialGradientPaint;
 import java.awt.MultipleGradientPaint.CycleMethod;
 
@@ -88,6 +89,21 @@
     private static final Color DEFAULT_GRADIENT_PAINT_SECOND_COLOR = Color.YELLOW;
 
     /**
+     * Default linear gradient paint first color.
+     */
+    private static final Color DEFAULT_LINEAR_GRADIENT_PAINT_FIRST_COLOR = Color.RED;
+
+    /**
+     * Default linear gradient paint second color.
+     */
+    private static final Color DEFAULT_LINEAR_GRADIENT_PAINT_SECOND_COLOR = Color.WHITE;
+
+    /**
+     * Default linear gradient paint third color.
+     */
+    private static final Color DEFAULT_LINEAR_GRADIENT_PAINT_THIRD_COLOR = Color.BLUE;
+
+    /**
      * Default radial gradient paint first color.
      */
     private static final Color DEFAULT_RADIAL_GRADIENT_PAINT_FIRST_COLOR = Color.RED;
@@ -429,6 +445,260 @@
     }
 
     /**
+     * Set horizontal linear 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 setHorizontalLinearGradientFill(TestImage image, Graphics2D graphics)
+    {
+        setHorizontalLinearGradientFill(image, graphics, DEFAULT_LINEAR_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_SECOND_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_THIRD_COLOR);
+    }
+
+    /**
+     * Set horizontal linear 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 setHorizontalLinearGradientFill(TestImage image, Graphics2D graphics, int offset)
+    {
+        setHorizontalLinearGradientFill(image, graphics, DEFAULT_LINEAR_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_SECOND_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_THIRD_COLOR, offset);
+    }
+
+    /**
+     * Set horizontal linear 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 color3
+     *            color set for the third edge of gradient fill
+     */
+    public static void setHorizontalLinearGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2, Color color3)
+    {
+        setHorizontalLinearGradientFill(image, graphics, color1, color2, color3, 0);
+    }
+
+    /**
+     * Set horizontal linear 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 color3
+     *            color set for the third edge of gradient fill
+     * @param offset
+     *            offset between shape border and edge of horizontal gradient
+     */
+    public static void setHorizontalLinearGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2, Color color3, int offset)
+    {
+        // calculate center of the image
+        int xc = image.getCenterX();
+        int yc = image.getCenterY();
+
+        // calculate radius of circle
+        int radius = CommonShapesRenderer.calculateRadius(image);
+
+        float[] fractions = { 0.0f, 0.5f, 1.0f };
+        Color[] colors = { color1, color2, color3 };
+
+        LinearGradientPaint linearGradientPaint = new LinearGradientPaint(xc - radius + offset, yc, xc + radius - offset, yc, fractions, colors);
+        graphics.setPaint(linearGradientPaint);
+    }
+
+    /**
+     * Set vertical linear 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 setVerticalLinearGradientFill(TestImage image, Graphics2D graphics)
+    {
+        setVerticalLinearGradientFill(image, graphics, DEFAULT_LINEAR_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_SECOND_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_THIRD_COLOR);
+    }
+
+    /**
+     * Set vertical linear 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 setVerticalLinearGradientFill(TestImage image, Graphics2D graphics, int offset)
+    {
+        setVerticalLinearGradientFill(image, graphics, DEFAULT_LINEAR_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_SECOND_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_THIRD_COLOR, offset);
+    }
+
+    /**
+     * Set vertical linear 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 color3
+     *            color set for the third edge of gradient fill
+     */
+    public static void setVerticalLinearGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2, Color color3)
+    {
+        setVerticalLinearGradientFill(image, graphics, color1, color2, color3, 0);
+    }
+
+    /**
+     * Set vertical linear 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 color3
+     *            color set for the third edge of gradient fill
+     * @param offset
+     *            offset between shape border and edge of horizontal gradient
+     */
+    public static void setVerticalLinearGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2, Color color3, int offset)
+    {
+        // calculate center of the image
+        int xc = image.getCenterX();
+        int yc = image.getCenterY();
+
+        // calculate radius of circle
+        int radius = CommonShapesRenderer.calculateRadius(image);
+
+        float[] fractions = { 0.0f, 0.5f, 1.0f };
+        Color[] colors = { color1, color2, color3 };
+
+        LinearGradientPaint linearGradientPaint = new LinearGradientPaint(xc, yc - radius + offset, xc, yc + radius - offset, fractions, colors);
+        graphics.setPaint(linearGradientPaint);
+    }
+
+    /**
+     * Set diagonal linear 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 setDiagonalLinearGradientFill(TestImage image, Graphics2D graphics)
+    {
+        setDiagonalLinearGradientFill(image, graphics, DEFAULT_LINEAR_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_SECOND_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_THIRD_COLOR);
+    }
+
+    /**
+     * Set diagonal linear 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 setDiagonalLinearGradientFill(TestImage image, Graphics2D graphics, int offset)
+    {
+        setDiagonalLinearGradientFill(image, graphics, DEFAULT_LINEAR_GRADIENT_PAINT_FIRST_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_SECOND_COLOR, DEFAULT_LINEAR_GRADIENT_PAINT_THIRD_COLOR, offset);
+    }
+
+    /**
+     * Set diagonal linear 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 color3
+     *            color set for the third edge of gradient fill
+     */
+    public static void setDiagonalLinearGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2, Color color3)
+    {
+        setDiagonalLinearGradientFill(image, graphics, color1, color2, color3, 0);
+    }
+
+    /**
+     * Set diagonal linear 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 color3
+     *            color set for the third edge of gradient fill
+     * @param offset
+     *            offset between shape border and edge of horizontal gradient
+     */
+    public static void setDiagonalLinearGradientFill(TestImage image, Graphics2D graphics, Color color1, Color color2, Color color3, 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;
+
+        float[] fractions = { 0.0f, 0.5f, 1.0f };
+        Color[] colors = { color1, color2, color3 };
+
+        LinearGradientPaint linearGradientPaint = new LinearGradientPaint(x1, y1, x2, y2, fractions, colors);
+        graphics.setPaint(linearGradientPaint);
+    }
+
+    /**
      * Set radial gradient fill for given graphics context.
      *
      * @param image
diff -r 6c985b5ee97e -r 49478d158096 src/org/gfxtest/testsuites/LinearGradientPaint.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/gfxtest/testsuites/LinearGradientPaint.java	Mon Sep 05 11:28:26 2011 +0200
@@ -0,0 +1,419 @@
+/*
+  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.Graphics2D;
+
+
+
+import org.gfxtest.framework.*;
+import org.gfxtest.framework.annotations.*;
+
+/**
+ * This test renders filled shapes using linear gradient paint.
+ * 
+ * @author Pavel Tisnovsky
+ */
+ at TestType(TestTypes.RENDER_TEST)
+ at RenderStyle(RenderStyles.FILL)
+ at Transformation(Transformations.NONE)
+ at Zoom(1)
+public class LinearGradientPaint 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 testCircleLinearGradientEmptyFill(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 testCircleHorizontalLinearGradientFill(TestImage image, Graphics2D graphics)
+    {
+        // set stroke color
+        CommonRenderingStyles.setStrokeColor(graphics);
+        // set fill color
+        CommonRenderingStyles.setHorizontalLinearGradientFill(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 testCircleHorizontalLinearGradientFillPositiveOffset1(TestImage image, Graphics2D graphics)
+    {
+        // set stroke color
+        CommonRenderingStyles.setStrokeColor(graphics);
+        // set fill color
+        CommonRenderingStyles.setHorizontalLinearGradientFill(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 testCircleHorizontalLinearGradientFillPositiveOffset2(TestImage image, Graphics2D graphics)
+    {
+        // set stroke color
+        CommonRenderingStyles.setStrokeColor(graphics);
+        // set fill color
+        CommonRenderingStyles.setHorizontalLinearGradientFill(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 testCircleHorizontalLinearGradientFillNegativeOffset1(TestImage image, Graphics2D graphics)
+    {
+        // set stroke color
+        CommonRenderingStyles.setStrokeColor(graphics);
+        // set fill color



More information about the distro-pkg-dev mailing list