author | prr |
Thu, 16 Oct 2008 06:28:37 -0700 | |
changeset 1728 | 7c281f43cafa |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
1728
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
1 |
/* |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
2 |
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
4 |
* |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
8 |
* |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
13 |
* accompanied this code). |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
14 |
* |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
18 |
* |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
21 |
* have any questions. |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
22 |
*/ |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
23 |
|
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
24 |
/* @test |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
25 |
* @summary verify outline and stroking of underline match. |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
26 |
* @bug 6751616 |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
27 |
*/ |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
28 |
|
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
29 |
import java.awt.*; |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
30 |
import java.awt.font.*; |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
31 |
import java.awt.geom.*; |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
32 |
import java.awt.image.*; |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
33 |
import java.util.*; |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
34 |
|
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
35 |
public class UnderlinePositionTest { |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
36 |
|
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
37 |
public static void main(String[] args) { |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
38 |
BufferedImage bi = |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
39 |
new BufferedImage(600, 150, BufferedImage.TYPE_INT_RGB); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
40 |
Graphics2D g2d = bi.createGraphics(); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
41 |
g2d.setColor(Color.white); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
42 |
g2d.fillRect(0, 0, 600, 150); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
43 |
|
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
44 |
float x = 10; |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
45 |
float y = 90; |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
46 |
Map map = new HashMap(); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
47 |
map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
48 |
map.put(TextAttribute.SIZE, new Float(80)); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
49 |
|
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
50 |
FontRenderContext frc = g2d.getFontRenderContext(); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
51 |
|
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
52 |
// Use all spaces for the text so we know we are dealing |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
53 |
// only with pixels from the underline. |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
54 |
String text = " "; |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
55 |
TextLayout tl = new TextLayout(text, map, frc); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
56 |
Shape outline = tl.getOutline(null); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
57 |
Rectangle2D bounds = outline.getBounds(); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
58 |
|
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
59 |
g2d.translate(x, y); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
60 |
g2d.setColor(Color.RED); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
61 |
tl.draw(g2d, 0, 0); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
62 |
|
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
63 |
/* By getting the outline, then its bounds, then filling |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
64 |
* according to the same pixelisation rules, this ought to |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
65 |
* match the position of the original underline. If any |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
66 |
* red pixels are left, then the test will fail. |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
67 |
*/ |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
68 |
g2d.setColor(Color.BLUE); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
69 |
g2d.fill(bounds); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
70 |
g2d.dispose(); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
71 |
|
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
72 |
checkBI(bi, Color.RED); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
73 |
} |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
74 |
|
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
75 |
static void checkBI(BufferedImage bi, Color badColor) { |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
76 |
int badrgb = badColor.getRGB(); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
77 |
int w = bi.getWidth(null); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
78 |
int h = bi.getHeight(null); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
79 |
for (int x=0; x<w; x++) { |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
80 |
for (int y=0; y<h; y++) { |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
81 |
int col = bi.getRGB(x, y); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
82 |
if (col == badrgb) { |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
83 |
throw new RuntimeException("Got " + col); |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
84 |
} |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
85 |
} |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
86 |
} |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
87 |
} |
7c281f43cafa
6751616: outline for underline in TextLayout with underline is off rasterized underline
prr
parents:
diff
changeset
|
88 |
} |