blob: d5055c660c7fcf07e827683ec7f8ed0b90eb22af [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test TestTransform
26 * @bug 6586545
27 * @summary This test verifies that transforms do not cause crash
28 * @run main TestTransform
29 */
30
31import java.awt.geom.AffineTransform;
32import java.awt.Font;
33import java.awt.Graphics;
34import java.awt.Graphics2D;
35import java.awt.RenderingHints;
36import java.awt.image.BufferedImage;
37
38public class TestTransform {
39 public static void testTransformedFont(AffineTransform a, Object textHint) {
40 BufferedImage bi = new BufferedImage(200, 200,
41 BufferedImage.TYPE_INT_RGB);
42 Graphics2D g2 = (Graphics2D) bi.getGraphics();
43 g2.setFont(g2.getFont().deriveFont(12.0f));
44 g2.setTransform(a);
45 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, textHint);
46 g2.drawString("test", 100, 100);
47 }
48
49 public static void testFontOfSize(float sz, Object textHint) {
50 BufferedImage bi = new BufferedImage(200, 200,
51 BufferedImage.TYPE_INT_RGB);
52 Graphics2D g2 = (Graphics2D) bi.getGraphics();
53 g2.setFont(g2.getFont().deriveFont(sz));
54 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, textHint);
55 g2.drawString("test", 100, 100);
56 }
57
58 public static void main(String[] args) {
59 Object aahints[] = {RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
60 RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
61 RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
62 RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB};
63 int i, j, k;
64 AffineTransform a = new AffineTransform();
65
66 for (i=0; i<aahints.length; i++) {
67 for(j=0; j<8; j++) {
68 System.out.println("Testing hint "+i+" angle="+j);
69 a.setToRotation(j*Math.PI/4);
70 testTransformedFont(a, aahints[i]);
71 }
72 testFontOfSize(0.0f, aahints[i]);
73 testFontOfSize(-10.0f, aahints[i]);
74 }
75 }
76}