1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 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 * 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. 22 */ 23 import java.awt.Font; 24 import java.awt.font.FontRenderContext; 25 import java.awt.font.GlyphVector; 26 import java.awt.geom.AffineTransform; 27 import java.awt.geom.Point2D; 28 29 /** 30 * @test 31 * @bug 7160052 32 * @run main TestStandardGlyphVectorBug 33 * @summary GlyphVector.setGlyphPosition should not throw an exception on valid input 34 */ 35 public class TestStandardGlyphVectorBug 36 { 37 public static void main(String[] args) 38 { 39 Font defaultFont = new Font(null); 40 FontRenderContext defaultFrc = new FontRenderContext(new AffineTransform(), 41 true, true); 42 GlyphVector gv = defaultFont.createGlyphVector(defaultFrc, "test"); 43 44 //this causes the bounds to be cached 45 //which is necessary to trigger the bug 46 gv.getGlyphLogicalBounds(0); 47 48 //this correctly gets the position of the overall advance 49 Point2D glyphPosition = gv.getGlyphPosition(gv.getNumGlyphs()); 50 51 // this sets the position of the overall advance, 52 // but also incorrectly tries to clear the bounds cache 53 // of a specific glyph indexed by the glyphIndex parameter 54 // even if the glyphIndex represents the overall advance 55 // (i.e. if glyphIndex == getNumGlyphs()) 56 gv.setGlyphPosition(gv.getNumGlyphs(), glyphPosition); 57 } 58 }