0N/A/*
328N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
180N/A * published by the Free Software Foundation.
0N/A *
180N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
180N/A * questions.
180N/A */
180N/A
0N/A/*
0N/A * @test
0N/A * @bug 6448405 6519513 6745225
0N/A * @summary static HashMap cache in LineBreakMeasurer can grow wihout bounds
0N/A * @run main/othervm/timeout=600 -client -Xms16m -Xmx16m FRCTest
0N/A */
0N/Aimport java.awt.*;
0N/Aimport java.awt.image.*;
0N/Aimport java.awt.font.*;
0N/Aimport java.awt.geom.*;
0N/Aimport java.text.*;
0N/Aimport java.util.Hashtable;
0N/A
0N/Apublic class FRCTest {
0N/A
0N/A static AttributedString vanGogh = new AttributedString(
0N/A "Many people believe that Vincent van Gogh painted his best works " +
0N/A "during the two-year period he spent in Provence. Here is where he " +
0N/A "painted The Starry Night--which some consider to be his greatest " +
311N/A "work of all. However, as his artistic brilliance reached new " +
0N/A "heights in Provence, his physical and mental health plummeted. ",
0N/A new Hashtable());
311N/A
0N/A public static void main(String[] args) {
0N/A
0N/A // First test the behaviour of Graphics2D.getFontRenderContext();
311N/A BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
0N/A Graphics2D g2d = bi.createGraphics();
0N/A AffineTransform g2dTx = new AffineTransform(2,0,2,0,1,1);
311N/A g2d.setTransform(g2dTx);
0N/A AffineTransform frcTx = g2d.getFontRenderContext().getTransform();
0N/A AffineTransform frcExpected = new AffineTransform(2,0,2,0,0,0);
0N/A if (!frcTx.equals(frcExpected)) {
throw new RuntimeException("FRC Tx may have translate?");
}
// Now test that using different translates with LBM is OK
// This test doesn't prove a lot since showing a leak really
// requires a basher test that can run for a long time.
for (int x=0;x<100;x++) {
for (int y=0;y<100;y++) {
AttributedCharacterIterator aci = vanGogh.getIterator();
AffineTransform tx = AffineTransform.getTranslateInstance(x, y);
FontRenderContext frc = new FontRenderContext(tx, false, false);
LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
lbm.setPosition(aci.getBeginIndex());
while (lbm.getPosition() < aci.getEndIndex()) {
lbm.nextLayout(100f);
}
}
}
for (int x=0;x<25;x++) {
for (int y=0;y<25;y++) {
AttributedCharacterIterator aci = vanGogh.getIterator();
double rot = Math.random()*.4*Math.PI - .2*Math.PI;
AffineTransform tx = AffineTransform.getRotateInstance(rot);
FontRenderContext frc = new FontRenderContext(tx, false, false);
LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
lbm.setPosition(aci.getBeginIndex());
while (lbm.getPosition() < aci.getEndIndex()) {
lbm.nextLayout(100f);
}
}
}
}
}