Path: blob/master/test/jdk/java/awt/Graphics2D/DrawString/DrawRotatedString.java
41153 views
/*1* Copyright (c) 2013, 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.Color;24import java.awt.Graphics2D;25import java.awt.RenderingHints;26import java.awt.image.BufferedImage;27import java.io.File;28import java.io.IOException;2930import javax.imageio.ImageIO;3132/**33* @test34* @bug 719034935* @summary Verifies that we get correct direction, when draw rotated string.36* @author Sergey Bylokhov37* @run main/othervm DrawRotatedString38*/39public final class DrawRotatedString {4041private static final int SIZE = 500;4243public static void main(final String[] args) throws IOException {44BufferedImage bi = createBufferedImage(true);45verify(bi);46bi = createBufferedImage(false);47verify(bi);48System.out.println("Passed");49}5051private static void verify(BufferedImage bi) throws IOException {52for (int i = 0; i < SIZE; ++i) {53for (int j = 0; j < 99; ++j) {54//Text should not appear before 10055if (bi.getRGB(i, j) != Color.RED.getRGB()) {56ImageIO.write(bi, "png", new File("image.png"));57throw new RuntimeException("Failed: wrong text location");58}59}60}61}6263private static BufferedImage createBufferedImage(final boolean aa) {64final BufferedImage bi = new BufferedImage(SIZE, SIZE,65BufferedImage.TYPE_INT_RGB);66final Graphics2D bg = bi.createGraphics();67bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,68aa ? RenderingHints.VALUE_ANTIALIAS_ON69: RenderingHints.VALUE_ANTIALIAS_OFF);70bg.setColor(Color.RED);71bg.fillRect(0, 0, SIZE, SIZE);72bg.translate(100, 100);73bg.rotate(Math.toRadians(90));74bg.setColor(Color.BLACK);75bg.setFont(bg.getFont().deriveFont(20.0f));76bg.drawString("MMMMMMMMMMMMMMMM", 0, 0);77bg.dispose();78return bi;79}80}818283