J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /** |
| 25 | * @test |
| 26 | * @bug 6599363 |
| 27 | * @summary Verifies correct handling of unclosed segments |
| 28 | * @run main FillPPathTest |
| 29 | */ |
| 30 | |
| 31 | |
| 32 | import java.awt.*; |
| 33 | import java.awt.image.*; |
| 34 | import java.awt.geom.*; |
| 35 | import java.awt.color.*; |
| 36 | |
| 37 | public class FillPPathTest { |
| 38 | static final int IMG_WIDTH = 100; |
| 39 | static final int IMG_HEIGHT = 100; |
| 40 | |
| 41 | private static BufferedImage createCustomImage() { |
| 42 | ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); |
| 43 | ComponentColorModel cm = |
| 44 | new ComponentColorModel(cs, false, false, Transparency.OPAQUE, |
| 45 | DataBuffer.TYPE_FLOAT); |
| 46 | WritableRaster raster = |
| 47 | cm.createCompatibleWritableRaster(IMG_WIDTH, IMG_HEIGHT); |
| 48 | return new BufferedImage(cm, raster, false, null); |
| 49 | } |
| 50 | |
| 51 | public static void main(String[] args) throws Exception { |
| 52 | |
| 53 | Path2D oddShape = new Path2D.Double(); |
| 54 | oddShape.moveTo(50,10); |
| 55 | oddShape.curveTo(50,10,10,20,50,30); |
| 56 | oddShape.moveTo(50,30); |
| 57 | |
| 58 | BufferedImage img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, |
| 59 | BufferedImage.TYPE_INT_RGB); |
| 60 | Graphics2D g2d = img.createGraphics(); |
| 61 | g2d.setColor(Color.BLACK); |
| 62 | g2d.fillRect(0,0,IMG_WIDTH,IMG_HEIGHT); |
| 63 | g2d.setColor(Color.WHITE); |
| 64 | g2d.fill(oddShape); |
| 65 | |
| 66 | if (img.getRGB(60, 20) != Color.BLACK.getRGB()) { |
| 67 | throw new RuntimeException("Error. Invalid pixel at (60,20)"); |
| 68 | } |
| 69 | |
| 70 | img = createCustomImage(); |
| 71 | |
| 72 | g2d = img.createGraphics(); |
| 73 | g2d.setColor(Color.BLACK); |
| 74 | g2d.fillRect(0,0,IMG_WIDTH,IMG_HEIGHT); |
| 75 | g2d.setColor(Color.WHITE); |
| 76 | g2d.fill(oddShape); |
| 77 | |
| 78 | if (img.getRGB(60, 20) != Color.BLACK.getRGB()) { |
| 79 | throw new RuntimeException("Error. Invalid pixel at (60,20)"); |
| 80 | } |
| 81 | } |
| 82 | } |