author | ohair |
Tue, 22 Jun 2010 17:26:32 -0700 | |
changeset 5967 | 26b773bf22ea |
parent 5551 | 327690766109 |
permissions | -rw-r--r-- |
2393 | 1 |
/* |
5551
327690766109
6956202: Fix a few missed rebranding issues, please contact lines etc.
ohair
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. |
2393 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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. |
|
2393 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6448405 6519513 6745225 |
|
27 |
* @summary static HashMap cache in LineBreakMeasurer can grow wihout bounds |
|
28 |
* @run main/othervm/timeout=600 -client -Xms16m -Xmx16m FRCTest |
|
29 |
*/ |
|
30 |
import java.awt.*; |
|
31 |
import java.awt.image.*; |
|
32 |
import java.awt.font.*; |
|
33 |
import java.awt.geom.*; |
|
34 |
import java.text.*; |
|
35 |
import java.util.Hashtable; |
|
36 |
||
37 |
public class FRCTest { |
|
38 |
||
39 |
static AttributedString vanGogh = new AttributedString( |
|
40 |
"Many people believe that Vincent van Gogh painted his best works " + |
|
41 |
"during the two-year period he spent in Provence. Here is where he " + |
|
42 |
"painted The Starry Night--which some consider to be his greatest " + |
|
43 |
"work of all. However, as his artistic brilliance reached new " + |
|
44 |
"heights in Provence, his physical and mental health plummeted. ", |
|
45 |
new Hashtable()); |
|
46 |
||
47 |
public static void main(String[] args) { |
|
48 |
||
49 |
// First test the behaviour of Graphics2D.getFontRenderContext(); |
|
50 |
BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); |
|
51 |
Graphics2D g2d = bi.createGraphics(); |
|
52 |
AffineTransform g2dTx = new AffineTransform(2,0,2,0,1,1); |
|
53 |
g2d.setTransform(g2dTx); |
|
54 |
AffineTransform frcTx = g2d.getFontRenderContext().getTransform(); |
|
55 |
AffineTransform frcExpected = new AffineTransform(2,0,2,0,0,0); |
|
56 |
if (!frcTx.equals(frcExpected)) { |
|
57 |
throw new RuntimeException("FRC Tx may have translate?"); |
|
58 |
} |
|
59 |
||
60 |
// Now test that using different translates with LBM is OK |
|
61 |
// This test doesn't prove a lot since showing a leak really |
|
62 |
// requires a basher test that can run for a long time. |
|
63 |
for (int x=0;x<100;x++) { |
|
64 |
for (int y=0;y<100;y++) { |
|
65 |
AttributedCharacterIterator aci = vanGogh.getIterator(); |
|
66 |
AffineTransform tx = AffineTransform.getTranslateInstance(x, y); |
|
67 |
FontRenderContext frc = new FontRenderContext(tx, false, false); |
|
68 |
LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc); |
|
69 |
lbm.setPosition(aci.getBeginIndex()); |
|
70 |
while (lbm.getPosition() < aci.getEndIndex()) { |
|
71 |
lbm.nextLayout(100f); |
|
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
||
76 |
for (int x=0;x<25;x++) { |
|
77 |
for (int y=0;y<25;y++) { |
|
78 |
AttributedCharacterIterator aci = vanGogh.getIterator(); |
|
79 |
double rot = Math.random()*.4*Math.PI - .2*Math.PI; |
|
80 |
AffineTransform tx = AffineTransform.getRotateInstance(rot); |
|
81 |
FontRenderContext frc = new FontRenderContext(tx, false, false); |
|
82 |
LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc); |
|
83 |
lbm.setPosition(aci.getBeginIndex()); |
|
84 |
while (lbm.getPosition() < aci.getEndIndex()) { |
|
85 |
lbm.nextLayout(100f); |
|
86 |
} |
|
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
} |