jdk/test/java/awt/Graphics2D/DrawString/RotTransText.java
author prr
Fri, 25 Apr 2008 10:37:07 -0700
changeset 545 6c61d3e63342
parent 533 482a0821a9d5
child 554 88eb2812c2a4
permissions -rw-r--r--
6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows Reviewed-by: igor, tdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
533
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
     1
/*
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
     4
 *
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
     8
 *
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    13
 * accompanied this code).
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    14
 *
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    18
 *
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    21
 * have any questions.
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    22
 */
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    23
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    24
/**
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    25
 * @test
545
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    26
 * @bug 6683472 6687298
533
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    27
 * @summary Transformed fonts using drawString and TextLayout should be in
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    28
 *          the same position.
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    29
 */
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    30
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    31
import java.awt.*;
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    32
import java.awt.font.*;
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    33
import java.awt.geom.*;
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    34
import java.awt.image.*;
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    35
import java.util.HashMap;
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    36
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    37
public class RotTransText  {
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    38
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    39
    public static void main(String[] args) {
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    40
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    41
        int wid=400, hgt=400;
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    42
        BufferedImage bi =
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    43
            new BufferedImage(wid, hgt, BufferedImage.TYPE_INT_RGB);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    44
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    45
        Graphics2D g2d = bi.createGraphics();
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    46
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    47
        int x=130, y=130;
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    48
        String s = "Text";
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    49
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    50
        int xt=90, yt=50;
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    51
        for (int angle=0;angle<360;angle+=30) {
545
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    52
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    53
            g2d.setColor(Color.white);
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    54
            g2d.fillRect(0, 0, wid, hgt);
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    55
533
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    56
            AffineTransform aff = AffineTransform.getTranslateInstance(50,90);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    57
            aff.rotate(angle * Math.PI/180.0);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    58
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    59
            Font fnt = new Font("SansSerif", Font.PLAIN, 60);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    60
            fnt = fnt.deriveFont(Font.PLAIN, aff);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    61
            g2d.setFont(fnt);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    62
            g2d.setColor(Color.blue);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    63
            g2d.drawString(s, x, y);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    64
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    65
            g2d.setColor(Color.red);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    66
            FontRenderContext frc = g2d.getFontRenderContext();
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    67
            HashMap attrMap = new HashMap();
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    68
            attrMap.put(TextAttribute.STRIKETHROUGH,
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    69
                    TextAttribute.STRIKETHROUGH_ON);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    70
            fnt = fnt.deriveFont(attrMap);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    71
            TextLayout tl = new TextLayout(s, fnt, frc);
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    72
            tl.draw(g2d, (float)x, (float)y);
545
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    73
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    74
            // Test BI: should be minimal blue relative to red.
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    75
            int redCount = 0;
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    76
            int blueCount = 0;
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    77
            int red = Color.red.getRGB();
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    78
            int blue = Color.blue.getRGB();
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    79
            for (int px=0;px<wid;px++) {
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    80
                for (int py=0;py<hgt;py++) {
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    81
                    int rgb = bi.getRGB(px, py);
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    82
                    if (rgb == red) {
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    83
                        redCount++;
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    84
                    } else if (rgb == blue) {
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    85
                        blueCount++;
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    86
                    }
533
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    87
                }
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    88
            }
545
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    89
            if (redCount == 0 || (blueCount/(double)redCount) > 0.1) {
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    90
                throw new
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    91
                    RuntimeException("Ratio of blue to red is too great: " +
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    92
                                     (blueCount/(double)redCount));
6c61d3e63342 6687298: Reg testcase java/awt/Graphics2D/DrawString/RotTransText.java fails on windows
prr
parents: 533
diff changeset
    93
            }
533
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    94
        }
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    95
    }
482a0821a9d5 6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff changeset
    96
}