1685N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1685N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1685N/A *
1685N/A * This code is free software; you can redistribute it and/or modify it
1685N/A * under the terms of the GNU General Public License version 2 only, as
1685N/A * published by the Free Software Foundation.
1685N/A *
1685N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1685N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1685N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1685N/A * version 2 for more details (a copy is included in the LICENSE file that
1685N/A * accompanied this code).
1685N/A *
1685N/A * You should have received a copy of the GNU General Public License version
1685N/A * 2 along with this work; if not, write to the Free Software Foundation,
1685N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1685N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1685N/A */
1685N/Aimport java.awt.*;
1685N/Aimport java.awt.geom.Ellipse2D;
1685N/Aimport java.awt.image.BufferedImage;
1685N/Aimport java.io.File;
1685N/Aimport javax.imageio.ImageIO;
1685N/A
1685N/A/**
1685N/A * @author chrisn@google.com (Chris Nokleberg)
1685N/A * @author yamauchi@google.com (Hiroshi Yamauchi)
1685N/A */
1685N/Apublic class ThinLineTest {
1685N/A private static final int PIXEL = 381;
1685N/A
1685N/A public static void main(String[] args) throws Exception {
1685N/A BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
1685N/A Graphics2D g = image.createGraphics();
1685N/A
1685N/A g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
1685N/A g.setPaint(Color.WHITE);
1685N/A g.fill(new Rectangle(image.getWidth(), image.getHeight()));
1685N/A
1685N/A g.scale(0.5 / PIXEL, 0.5 / PIXEL);
1685N/A g.setPaint(Color.BLACK);
1685N/A g.setStroke(new BasicStroke(PIXEL));
1685N/A g.draw(new Ellipse2D.Double(PIXEL * 50, PIXEL * 50, PIXEL * 300, PIXEL * 300));
1685N/A
1685N/A // To visually check it
1685N/A //ImageIO.write(image, "PNG", new File(args[0]));
1685N/A
1685N/A boolean nonWhitePixelFound = false;
1685N/A for (int x = 0; x < 200; ++x) {
1685N/A if (image.getRGB(x, 100) != Color.WHITE.getRGB()) {
1685N/A nonWhitePixelFound = true;
1685N/A break;
1685N/A }
1685N/A }
1685N/A if (!nonWhitePixelFound) {
1685N/A throw new RuntimeException("The thin line disappeared.");
1685N/A }
1685N/A }
1685N/A}