1 /* 2 * Copyright (c) 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 7019861 27 * 28 * @summary Verifies that the last scanline isn't skipped when doing 29 * antialiased rendering. 30 * 31 * @run main Test7019861 32 */ 33 34 import java.awt.BasicStroke; 35 import java.awt.Color; 36 import java.awt.Graphics2D; 37 import java.awt.geom.Path2D; 38 import java.awt.image.BufferedImage; 39 import java.util.Arrays; 40 41 import static java.awt.RenderingHints.*; 42 43 public class Test7019861 { 44 45 public static void main(String[] argv) throws Exception { 46 BufferedImage im = getWhiteImage(30, 30); 47 Graphics2D g2 = (Graphics2D)im.getGraphics(); 48 g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); 49 g2.setRenderingHint(KEY_STROKE_CONTROL, VALUE_STROKE_PURE); 50 g2.setStroke(new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); 51 g2.setBackground(Color.white); 52 g2.setColor(Color.black); 53 54 Path2D p = getPath(0, 0, 20); 55 g2.draw(p); 56 57 if (!(new Color(im.getRGB(20, 19))).equals(Color.black)) { 58 throw new Exception("This pixel should be black"); 59 } 60 } 61 62 private static Path2D getPath(int x, int y, int len) { 63 Path2D p = new Path2D.Double(); 64 p.moveTo(x, y); 65 p.quadTo(x + len, y, x + len, y + len); 66 return p; 67 } 68 69 private static BufferedImage getWhiteImage(int w, int h) { 70 BufferedImage ret = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); 71 final int[] white = new int[w * h]; 72 Arrays.fill(white, 0xffffff); 73 ret.setRGB(0, 0, w, h, white, 0, w); 74 return ret; 75 } 76 }