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