|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, 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 8242004 |
| 27 | + * @summary Font/Text APIs should handle a non-invertible transform. |
| 28 | + */ |
| 29 | + |
| 30 | +import java.awt.Color; |
| 31 | +import java.awt.Font; |
| 32 | +import java.awt.Graphics2D; |
| 33 | +import java.awt.font.FontRenderContext; |
| 34 | +import java.awt.font.GlyphVector; |
| 35 | +import java.awt.font.TextLayout; |
| 36 | +import java.awt.geom.AffineTransform; |
| 37 | +import java.awt.image.BufferedImage; |
| 38 | + |
| 39 | +public class NonInvertibleTransformTextTest { |
| 40 | + |
| 41 | + public static void main(String[] args) { |
| 42 | + |
| 43 | + // Create a non-invertible transform |
| 44 | + AffineTransform at = new AffineTransform(1f, 0.0f, -15, 0.0, -1, -30); |
| 45 | + |
| 46 | + // Test creating a text layout |
| 47 | + FontRenderContext frc = new FontRenderContext(at, false, false); |
| 48 | + Font font = new Font(Font.DIALOG, Font.PLAIN, 12); |
| 49 | + TextLayout tl = new TextLayout("ABC", font, frc); |
| 50 | + tl.getOutline(new AffineTransform()); |
| 51 | + |
| 52 | + // Test rendering text |
| 53 | + BufferedImage bi = new BufferedImage(100, 100, |
| 54 | + BufferedImage.TYPE_INT_RGB); |
| 55 | + Graphics2D g2d = bi.createGraphics(); |
| 56 | + g2d.setColor(Color.white); |
| 57 | + g2d.fillRect(0,0,100,100); |
| 58 | + g2d.setColor(Color.red); |
| 59 | + tl.draw(g2d, 50, 50); // first the TextLayout created above |
| 60 | + |
| 61 | + // Now a laid out GlyphVector |
| 62 | + Font f = g2d.getFont(); |
| 63 | + char[] chs = { 'A', 'B', 'C' }; |
| 64 | + GlyphVector gv = f.layoutGlyphVector(frc, chs, 0, chs.length, 0); |
| 65 | + g2d.drawGlyphVector(gv, 20, 20); |
| 66 | + |
| 67 | + // Now under the transform, the basic text drawing calls. |
| 68 | + g2d.setTransform(at); |
| 69 | + g2d.drawString("ABC", 20, 20); |
| 70 | + g2d.drawChars(chs, 0, chs.length, 20, 20); |
| 71 | + // And TextLayout again. |
| 72 | + tl.draw(g2d, 50, 50); |
| 73 | + } |
| 74 | +} |
0 commit comments