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