284N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. 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 *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
284N/A */
284N/A
284N/A/**
284N/A * @test
296N/A * @bug 6683472 6687298
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
305N/A testIt(false);
305N/A testIt(true);
305N/A
305N/A }
305N/A
305N/A public static void testIt(boolean fmOn) {
305N/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
305N/A if (fmOn) {
305N/A g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
305N/A RenderingHints.VALUE_FRACTIONALMETRICS_ON);
305N/A }
305N/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) {
296N/A
296N/A g2d.setColor(Color.white);
296N/A g2d.fillRect(0, 0, wid, hgt);
296N/A
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);
296N/A
296N/A // Test BI: should be minimal blue relative to red.
296N/A int redCount = 0;
296N/A int blueCount = 0;
296N/A int red = Color.red.getRGB();
296N/A int blue = Color.blue.getRGB();
296N/A for (int px=0;px<wid;px++) {
296N/A for (int py=0;py<hgt;py++) {
296N/A int rgb = bi.getRGB(px, py);
296N/A if (rgb == red) {
296N/A redCount++;
296N/A } else if (rgb == blue) {
296N/A blueCount++;
296N/A }
284N/A }
284N/A }
296N/A if (redCount == 0 || (blueCount/(double)redCount) > 0.1) {
296N/A throw new
296N/A RuntimeException("Ratio of blue to red is too great: " +
296N/A (blueCount/(double)redCount));
296N/A }
284N/A }
284N/A }
284N/A}