Path: blob/master/test/jdk/java/awt/BasicStroke/DashScaleMinWidth.java
41149 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.BasicStroke;24import java.awt.Color;25import java.awt.Graphics2D;26import java.awt.GraphicsConfiguration;27import java.awt.GraphicsEnvironment;28import java.awt.Image;29import java.awt.geom.Line2D;30import java.awt.image.BufferedImage;31import java.awt.image.IndexColorModel;32import java.awt.image.VolatileImage;3334import static java.awt.image.BufferedImage.TYPE_INT_ARGB;3536/**37* @test38* @bug 4917097 8019816 819841139* @key headful40* @summary 1.4.1 REGRESSION: BasicStroke Dashes don't show when scale * line width = 1.041* @run main/othervm -Dsun.java2d.uiScale=1 DashScaleMinWidth42*/43public final class DashScaleMinWidth {4445public static void main(final String[] args) {46BufferedImage img = new BufferedImage(200, 40, TYPE_INT_ARGB);47draw(img);48validate(img);4950GraphicsConfiguration gc =51GraphicsEnvironment.getLocalGraphicsEnvironment()52.getDefaultScreenDevice().getDefaultConfiguration();53if (gc.getColorModel() instanceof IndexColorModel) {54System.err.println("Skipping VolatileImage because of IndexColorModel");55return;56}5758VolatileImage vi = gc.createCompatibleVolatileImage(200, 40);59BufferedImage snapshot;60int attempt = 0;61while (true) {62if (++attempt > 10) {63throw new RuntimeException("Too many attempts: " + attempt);64}65vi.validate(gc);66draw(vi);67snapshot = vi.getSnapshot();68if (!vi.contentsLost()) {69break;70}71}72validate(snapshot);73}7475private static void draw(final Image img) {76float[] dashes = {200.0f, 200.0f};77BasicStroke bs = new BasicStroke(20.0f,78BasicStroke.CAP_BUTT,79BasicStroke.JOIN_MITER,801.0f,81dashes,820.0f);83Graphics2D g = (Graphics2D) img.getGraphics();84g.setColor(Color.WHITE);85g.fillRect(0, 0, 200, 40);86Line2D line = new Line2D.Double(400, 400, 3600, 400);87g.setColor(Color.BLACK);88g.scale(0.05, 0.05);89g.setStroke(bs);90g.draw(line);91g.dispose();92}9394private static void validate(final BufferedImage img) {95int white = Color.white.getRGB();96int point = img.getRGB(35, 20); // point in the gap97if (point != white) {98throw new RuntimeException("Line should be dashed");99}100}101}102103104