1/* 2 * Copyright (c) 2007, 2012, 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 24/* 25 * @test 26 * @bug 7183458 27 * @summary Verify advance of space is not overly widened by bold styling. 28 * @run main StyledSpaceAdvance 29 */ 30import java.awt.Font; 31import java.awt.font.FontRenderContext; 32import java.awt.geom.Rectangle2D; 33import java.util.Locale; 34 35public class StyledSpaceAdvance { 36 37 static String name = "Gulim"; 38 39 public static void main(String args[]) { 40 for (int sz=9;sz<18;sz++) { 41 test(sz); 42 } 43 } 44 45 static void test(int sz) { 46 Font reg = new Font(name, Font.PLAIN, sz); 47 Font bold = new Font(name, Font.BOLD, sz); 48 //System.out.println("reg="+reg); 49 //System.out.println("bold="+bold); 50 FontRenderContext frc = new FontRenderContext(null, false, false); 51 if (reg.getFontName(Locale.ENGLISH).equals(name) && 52 bold.getFontName(Locale.ENGLISH).equals(name)) { 53 Rectangle2D rb = reg.getStringBounds(" ", frc); 54 Rectangle2D bb = bold.getStringBounds(" ", frc); 55 if (bb.getWidth() > rb.getWidth() + 1.01f) { 56 System.err.println("reg="+reg+" bds = " + rb); 57 System.err.println("bold="+bold+" bds = " + bb); 58 throw new RuntimeException("Advance difference too great."); 59 } 60 } else { 61 System.out.println("Skipping test because fonts aren't as expected"); 62 } 63 } 64} 65