author | prr |
Wed, 09 Apr 2008 13:11:46 -0700 | |
changeset 533 | 482a0821a9d5 |
child 545 | 6c61d3e63342 |
permissions | -rw-r--r-- |
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 |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
26 |
* @bug 6683472 |
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 |
g2d.setColor(Color.white); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
48 |
g2d.fillRect(0, 0, wid, hgt); |
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 x=130, y=130; |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
51 |
String s = "Text"; |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
52 |
|
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
53 |
int xt=90, yt=50; |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
54 |
for (int angle=0;angle<360;angle+=30) { |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
55 |
AffineTransform aff = AffineTransform.getTranslateInstance(50,90); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
56 |
aff.rotate(angle * Math.PI/180.0); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
57 |
|
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
58 |
Font fnt = new Font("SansSerif", Font.PLAIN, 60); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
59 |
fnt = fnt.deriveFont(Font.PLAIN, aff); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
60 |
g2d.setFont(fnt); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
61 |
g2d.setColor(Color.blue); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
62 |
g2d.drawString(s, x, y); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
63 |
|
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
64 |
g2d.setColor(Color.red); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
65 |
FontRenderContext frc = g2d.getFontRenderContext(); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
66 |
HashMap attrMap = new HashMap(); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
67 |
attrMap.put(TextAttribute.STRIKETHROUGH, |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
68 |
TextAttribute.STRIKETHROUGH_ON); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
69 |
fnt = fnt.deriveFont(attrMap); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
70 |
TextLayout tl = new TextLayout(s, fnt, frc); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
71 |
tl.draw(g2d, (float)x, (float)y); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
72 |
} |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
73 |
// Test BI: should be no blue: only red and white. |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
74 |
int red = Color.red.getRGB(); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
75 |
int blue = Color.blue.getRGB(); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
76 |
int white = Color.white.getRGB(); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
77 |
for (int px=0;px<wid;px++) { |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
78 |
for (int py=0;py<hgt;py++) { |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
79 |
int rgb = bi.getRGB(px, py); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
80 |
if (rgb == blue || ( rgb != red && rgb != white)) { |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
81 |
throw new RuntimeException |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
82 |
("Unexpected color : " + Integer.toHexString(rgb) + |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
83 |
" at x=" + x + " y="+ y); |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
84 |
} |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
85 |
} |
482a0821a9d5
6683472: Incorrect handling of translation component of font transform.
prr
parents:
diff
changeset
|
86 |
} |
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 |
} |