Path: blob/master/test/jdk/java/awt/FontClass/NonInvertibleTransformTextTest.java
41152 views
/*1* Copyright (c) 2020, 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*/2223/*24* @test25* @bug 824200426* @summary Font/Text APIs should handle a non-invertible transform.27*/2829import java.awt.Color;30import java.awt.Font;31import java.awt.Graphics2D;32import java.awt.font.FontRenderContext;33import java.awt.font.GlyphVector;34import java.awt.font.TextLayout;35import java.awt.geom.AffineTransform;36import java.awt.image.BufferedImage;3738public class NonInvertibleTransformTextTest {3940public static void main(String[] args) {4142// Create a non-invertible transform43AffineTransform at = new AffineTransform(1f, 0.0f, -15, 0.0, -1, -30);4445// Test creating a text layout46FontRenderContext frc = new FontRenderContext(at, false, false);47Font font = new Font(Font.DIALOG, Font.PLAIN, 12);48TextLayout tl = new TextLayout("ABC", font, frc);49tl.getOutline(new AffineTransform());5051// Test rendering text52BufferedImage bi = new BufferedImage(100, 100,53BufferedImage.TYPE_INT_RGB);54Graphics2D g2d = bi.createGraphics();55g2d.setColor(Color.white);56g2d.fillRect(0,0,100,100);57g2d.setColor(Color.red);58tl.draw(g2d, 50, 50); // first the TextLayout created above5960// Now a laid out GlyphVector61Font f = g2d.getFont();62char[] chs = { 'A', 'B', 'C' };63GlyphVector gv = f.layoutGlyphVector(frc, chs, 0, chs.length, 0);64g2d.drawGlyphVector(gv, 20, 20);6566// Now under the transform, the basic text drawing calls.67g2d.setTransform(at);68g2d.drawString("ABC", 20, 20);69g2d.drawChars(chs, 0, chs.length, 20, 20);70// And TextLayout again.71tl.draw(g2d, 50, 50);72}73}747576