Path: blob/master/test/jdk/java/awt/FontMetrics/StyledSpaceAdvance.java
41152 views
/*1* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 718345826* @summary Verify advance of space is not overly widened by bold styling.27* @run main StyledSpaceAdvance28*/29import java.awt.Font;30import java.awt.font.FontRenderContext;31import java.awt.geom.Rectangle2D;32import java.util.Locale;3334public class StyledSpaceAdvance {3536static String name = "Gulim";3738public static void main(String args[]) {39for (int sz=9;sz<18;sz++) {40test(sz);41}42}4344static void test(int sz) {45Font reg = new Font(name, Font.PLAIN, sz);46Font bold = new Font(name, Font.BOLD, sz);47//System.out.println("reg="+reg);48//System.out.println("bold="+bold);49FontRenderContext frc = new FontRenderContext(null, false, false);50if (reg.getFontName(Locale.ENGLISH).equals(name) &&51bold.getFontName(Locale.ENGLISH).equals(name)) {52Rectangle2D rb = reg.getStringBounds(" ", frc);53Rectangle2D bb = bold.getStringBounds(" ", frc);54if (bb.getWidth() > rb.getWidth() + 1.01f) {55System.err.println("reg="+reg+" bds = " + rb);56System.err.println("bold="+bold+" bds = " + bb);57throw new RuntimeException("Advance difference too great.");58}59} else {60System.out.println("Skipping test because fonts aren't as expected");61}62}63}646566