author | prr |
Fri, 21 Jan 2011 08:04:04 -0800 | |
changeset 7950 | dc8f97e15f9b |
parent 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
1725
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
1725
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
4 |
* |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
8 |
* |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
13 |
* accompanied this code). |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
14 |
* |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
18 |
* |
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
1725
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
22 |
*/ |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
23 |
|
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
24 |
/* @test |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
25 |
* @summary verify bounds enclose rendering of decorations. |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
26 |
* @bug 6751621 |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
27 |
*/ |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
28 |
|
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
29 |
import java.awt.*; |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
30 |
import java.awt.font.*; |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
31 |
import java.awt.geom.*; |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
32 |
import java.awt.image.*; |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
33 |
import java.util.*; |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
34 |
|
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
35 |
public class DecorationBoundsTest { |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
36 |
|
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
37 |
public static void main(String[] args) { |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
38 |
BufferedImage bi = |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
39 |
new BufferedImage(600, 300, BufferedImage.TYPE_INT_RGB); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
40 |
Graphics2D g2d = bi.createGraphics(); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
41 |
g2d.setColor(Color.white); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
42 |
g2d.fillRect(0, 0, 600, 300); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
43 |
|
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
44 |
float x = 10; |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
45 |
float y = 90; |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
46 |
Map map = new HashMap(); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
47 |
map.put(TextAttribute.STRIKETHROUGH, |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
48 |
TextAttribute.STRIKETHROUGH_ON); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
49 |
map.put(TextAttribute.SIZE, new Float(80)); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
50 |
|
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
51 |
FontRenderContext frc = g2d.getFontRenderContext(); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
52 |
|
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
53 |
String text = "Welcome to "; |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
54 |
TextLayout tl = new TextLayout(text, map, frc); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
55 |
g2d.translate(x, y); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
56 |
g2d.setColor(Color.RED); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
57 |
tl.draw(g2d, 0, 0); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
58 |
g2d.setColor(Color.GREEN); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
59 |
Rectangle2D bds = tl.getBounds(); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
60 |
/* Since due to pixelisation the glyphs may touch above |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
61 |
* or below the theoretical outline bounds, pad in the |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
62 |
* y direction to avoid spurious failures. |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
63 |
*/ |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
64 |
bds.setRect(bds.getX(), bds.getY()-1, |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
65 |
bds.getWidth(), bds.getHeight()+2); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
66 |
g2d.fill(bds); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
67 |
|
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
68 |
map = new HashMap(); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
69 |
map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
70 |
map.put(TextAttribute.SIZE, new Float(80)); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
71 |
tl = new TextLayout(text, map, frc); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
72 |
g2d.translate(0, 100); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
73 |
g2d.setColor(Color.RED); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
74 |
tl.draw(g2d, 0, 0); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
75 |
|
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
76 |
g2d.setColor(Color.GREEN); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
77 |
bds = tl.getBounds(); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
78 |
bds.setRect(bds.getX(), bds.getY()-1, |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
79 |
bds.getWidth(), bds.getHeight()+2); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
80 |
g2d.fill(bds); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
81 |
|
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
82 |
checkBI(bi, Color.RED); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
83 |
} |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
84 |
|
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
85 |
static void checkBI(BufferedImage bi, Color badColor) { |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
86 |
int badrgb = badColor.getRGB(); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
87 |
int w = bi.getWidth(null); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
88 |
int h = bi.getHeight(null); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
89 |
for (int x=0; x<w; x++) { |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
90 |
for (int y=0; y<h; y++) { |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
91 |
int col = bi.getRGB(x, y); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
92 |
if (col == badrgb) { |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
93 |
throw new RuntimeException("Got " + col); |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
94 |
} |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
95 |
} |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
96 |
} |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
97 |
} |
3be564c67d63
6751621: TextLayout.getBounds() doesn't account for strike through
prr
parents:
diff
changeset
|
98 |
} |