6423N/A/*
6423N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
6423N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6423N/A *
6423N/A * This code is free software; you can redistribute it and/or modify it
6423N/A * under the terms of the GNU General Public License version 2 only, as
6423N/A * published by the Free Software Foundation.
6423N/A *
6423N/A * This code is distributed in the hope that it will be useful, but WITHOUT
6423N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6423N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6423N/A * version 2 for more details (a copy is included in the LICENSE file that
6423N/A * accompanied this code).
6423N/A *
6423N/A * You should have received a copy of the GNU General Public License version
6423N/A * 2 along with this work; if not, write to the Free Software Foundation,
6423N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6423N/A *
6423N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6423N/A * or visit www.oracle.com if you need additional information or have any
6423N/A * questions.
6423N/A */
6423N/A
6423N/A/**
6423N/A * @test
6423N/A * @bug 8015334
6423N/A * @summary Memory leak with kerning.
6423N/A */
6423N/A
6423N/Aimport java.awt.Font;
6423N/Aimport java.awt.FontMetrics;
6423N/Aimport java.awt.font.FontRenderContext;
6423N/Aimport java.awt.font.TextAttribute;
6423N/Aimport java.awt.font.TextLayout;
6423N/Aimport java.util.HashMap;
6423N/Aimport java.util.Map;
6423N/A
6423N/Apublic class KerningLeak {
6423N/A
6423N/A public static void main(String[] args) {
6423N/A Map<TextAttribute, Object> textAttributes = new HashMap<>();
6423N/A textAttributes.put(TextAttribute.FAMILY, "Sans Serif");
6423N/A textAttributes.put(TextAttribute.SIZE, 12);
6423N/A textAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
6423N/A Font font = Font.getFont(textAttributes);
6423N/A int totalAdvance = 0;
6423N/A FontRenderContext frc = new FontRenderContext(null, false, false);
6423N/A for (int i = 0; i < 500; i++) {
6423N/A if (i % 10 == 0) System.out.println("Starting iter " + (i+1));
6423N/A for (int j = 0; j <1000; j++) {
6423N/A TextLayout tl = new TextLayout(Integer.toString(j), font, frc);
6423N/A totalAdvance += tl.getAdvance();
6423N/A }
6423N/A }
6423N/A System.out.println("done " + totalAdvance);
6423N/A }
6423N/A}