RotTransText.java revision 284
284N/A/*
284N/A * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
284N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
284N/A *
284N/A * This code is free software; you can redistribute it and/or modify it
284N/A * under the terms of the GNU General Public License version 2 only, as
284N/A * published by the Free Software Foundation.
284N/A *
284N/A * This code is distributed in the hope that it will be useful, but WITHOUT
284N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
284N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
284N/A * version 2 for more details (a copy is included in the LICENSE file that
284N/A * accompanied this code).
284N/A *
284N/A * You should have received a copy of the GNU General Public License version
284N/A * 2 along with this work; if not, write to the Free Software Foundation,
284N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
284N/A *
284N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
284N/A * CA 95054 USA or visit www.sun.com if you need additional information or
284N/A * have any questions.
284N/A */
284N/A
284N/A/**
284N/A * @test
284N/A * @bug 6683472
284N/A * @summary Transformed fonts using drawString and TextLayout should be in
284N/A * the same position.
284N/A */
284N/A
284N/Aimport java.awt.*;
284N/Aimport java.awt.font.*;
284N/Aimport java.awt.geom.*;
284N/Aimport java.awt.image.*;
284N/Aimport java.util.HashMap;
284N/A
284N/Apublic class RotTransText {
284N/A
284N/A public static void main(String[] args) {
284N/A
284N/A int wid=400, hgt=400;
284N/A BufferedImage bi =
284N/A new BufferedImage(wid, hgt, BufferedImage.TYPE_INT_RGB);
284N/A
284N/A Graphics2D g2d = bi.createGraphics();
284N/A
284N/A g2d.setColor(Color.white);
284N/A g2d.fillRect(0, 0, wid, hgt);
284N/A
284N/A int x=130, y=130;
284N/A String s = "Text";
284N/A
284N/A int xt=90, yt=50;
284N/A for (int angle=0;angle<360;angle+=30) {
284N/A AffineTransform aff = AffineTransform.getTranslateInstance(50,90);
284N/A aff.rotate(angle * Math.PI/180.0);
284N/A
284N/A Font fnt = new Font("SansSerif", Font.PLAIN, 60);
284N/A fnt = fnt.deriveFont(Font.PLAIN, aff);
284N/A g2d.setFont(fnt);
284N/A g2d.setColor(Color.blue);
284N/A g2d.drawString(s, x, y);
284N/A
284N/A g2d.setColor(Color.red);
284N/A FontRenderContext frc = g2d.getFontRenderContext();
284N/A HashMap attrMap = new HashMap();
284N/A attrMap.put(TextAttribute.STRIKETHROUGH,
284N/A TextAttribute.STRIKETHROUGH_ON);
284N/A fnt = fnt.deriveFont(attrMap);
284N/A TextLayout tl = new TextLayout(s, fnt, frc);
284N/A tl.draw(g2d, (float)x, (float)y);
284N/A }
284N/A // Test BI: should be no blue: only red and white.
284N/A int red = Color.red.getRGB();
284N/A int blue = Color.blue.getRGB();
284N/A int white = Color.white.getRGB();
284N/A for (int px=0;px<wid;px++) {
284N/A for (int py=0;py<hgt;py++) {
284N/A int rgb = bi.getRGB(px, py);
284N/A if (rgb == blue || ( rgb != red && rgb != white)) {
284N/A throw new RuntimeException
284N/A ("Unexpected color : " + Integer.toHexString(rgb) +
284N/A " at x=" + x + " y="+ y);
284N/A }
284N/A }
284N/A }
284N/A }
284N/A}