Path: blob/master/test/jdk/java/awt/FontClass/HeadlessFont.java
41152 views
/*1* Copyright (c) 2007, 2015, 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*/2223import java.awt.*;24import java.awt.font.TextAttribute;25import java.awt.geom.AffineTransform;26import java.text.AttributedCharacterIterator;27import java.text.StringCharacterIterator;28import java.util.HashMap;29import java.util.Map;3031/*32* @test33* @summary Check that Font constructors and methods do not throw34* unexpected exceptions in headless mode35* @run main/othervm -Djava.awt.headless=true HeadlessFont36*/3738public class HeadlessFont {3940public static void main(String args[]) {41HashMap attMap = new HashMap();42attMap.put(TextAttribute.FAMILY, "Helvetica Bold");43attMap.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_LIGHT);44attMap.put(TextAttribute.WIDTH, TextAttribute.WIDTH_REGULAR);45attMap.put(TextAttribute.SIZE, new Float(20));46attMap.put(TextAttribute.FOREGROUND, Color.white);47attMap.put(TextAttribute.BACKGROUND, Color.black);4849for (String font : Toolkit.getDefaultToolkit().getFontList()) {50for (int i = 8; i < 17; i++) {51Font f1 = new Font(font, Font.PLAIN, i);52Font f2 = new Font(font, Font.BOLD, i);53Font f3 = new Font(font, Font.ITALIC, i);54Font f4 = new Font(font, Font.BOLD | Font.ITALIC, i);5556FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics(f1);57metrics = Toolkit.getDefaultToolkit().getFontMetrics(f2);58metrics = Toolkit.getDefaultToolkit().getFontMetrics(f3);59metrics = Toolkit.getDefaultToolkit().getFontMetrics(f4);6061AffineTransform trans = f1.getTransform();62trans = f2.getTransform();63trans = f3.getTransform();64trans = f4.getTransform();6566String str;67str = f1.getFamily();68str = f2.getFamily();69str = f3.getFamily();70str = f4.getFamily();7172str = f1.getPSName();73str = f2.getPSName();74str = f3.getPSName();75str = f4.getPSName();7677str = f1.getName();78str = f2.getName();79str = f3.getName();80str = f4.getName();8182str = f1.getFontName();83str = f2.getFontName();84str = f3.getFontName();85str = f4.getFontName();8687str = f1.toString();88str = f2.toString();89str = f3.toString();90str = f4.toString();9192int s;93s = f1.getStyle();94s = f2.getStyle();95s = f3.getStyle();96s = f4.getStyle();9798s = f1.getSize();99s = f2.getSize();100s = f3.getSize();101s = f4.getSize();102103s = f1.hashCode();104s = f2.hashCode();105s = f3.hashCode();106s = f4.hashCode();107108s = f1.getNumGlyphs();109s = f2.getNumGlyphs();110s = f3.getNumGlyphs();111s = f4.getNumGlyphs();112113s = f1.getMissingGlyphCode();114s = f2.getMissingGlyphCode();115s = f3.getMissingGlyphCode();116s = f4.getMissingGlyphCode();117118float f;119f = f1.getSize2D();120f = f2.getSize2D();121f = f3.getSize2D();122f = f4.getSize2D();123124125byte b;126b = f1.getBaselineFor('c');127b = f2.getBaselineFor('c');128b = f3.getBaselineFor('c');129b = f4.getBaselineFor('c');130131Map m = f1.getAttributes();132m = f2.getAttributes();133m = f3.getAttributes();134m = f4.getAttributes();135136AttributedCharacterIterator.Attribute[] a;137a = f1.getAvailableAttributes();138a = f2.getAvailableAttributes();139a = f3.getAvailableAttributes();140a = f4.getAvailableAttributes();141142143Font fnt;144fnt = f1.deriveFont(Font.BOLD | Font.ITALIC, (float) 80);145fnt = f2.deriveFont(Font.BOLD | Font.ITALIC, (float) 80);146fnt = f3.deriveFont(Font.BOLD | Font.ITALIC, (float) 80);147fnt = f4.deriveFont(Font.BOLD | Font.ITALIC, (float) 80);148149fnt = f1.deriveFont(80f);150fnt = f2.deriveFont(80f);151fnt = f3.deriveFont(80f);152fnt = f4.deriveFont(80f);153154fnt = f1.deriveFont(Font.BOLD | Font.ITALIC);155fnt = f2.deriveFont(Font.BOLD | Font.ITALIC);156fnt = f3.deriveFont(Font.BOLD | Font.ITALIC);157fnt = f4.deriveFont(Font.BOLD | Font.ITALIC);158159fnt = f1.deriveFont(attMap);160fnt = f2.deriveFont(attMap);161fnt = f3.deriveFont(attMap);162fnt = f4.deriveFont(attMap);163164165if (!f1.isPlain())166throw new RuntimeException("Plain font " + f1.getName() + " says it's not plain");167if (f2.isPlain())168throw new RuntimeException("Bold font " + f1.getName() + " says it is plain");169if (f3.isPlain())170throw new RuntimeException("Italic font " + f1.getName() + " says it is plain");171if (f4.isPlain())172throw new RuntimeException("Bold|Italic font " + f1.getName() + " says it is plain");173174if (f1.isBold())175throw new RuntimeException("Plain font " + f1.getName() + " says it is bold");176if (!f2.isBold())177throw new RuntimeException("Bold font " + f1.getName() + " says it's not bold");178if (f3.isBold())179throw new RuntimeException("Italic font " + f1.getName() + " says it is bold");180if (!f4.isBold())181throw new RuntimeException("Bold|Italic font " + f1.getName() + " says it's not bold");182183if (f1.isItalic())184throw new RuntimeException("Plain font " + f1.getName() + " says it is italic");185if (f2.isItalic())186throw new RuntimeException("Bold font " + f1.getName() + " says it is italic");187if (!f3.isItalic())188throw new RuntimeException("Italic font " + f1.getName() + " says it's not italic");189if (!f4.isItalic())190throw new RuntimeException("Bold|Italic font " + f1.getName() + " says it's not italic");191192f1.canDisplay('~');193f2.canDisplay('~');194f3.canDisplay('~');195f4.canDisplay('~');196f1.canDisplay('c');197f2.canDisplay('c');198f3.canDisplay('c');199f4.canDisplay('c');200201f1.canDisplayUpTo("canDisplayUpTo");202f2.canDisplayUpTo("canDisplayUpTo");203f3.canDisplayUpTo("canDisplayUpTo");204f4.canDisplayUpTo("canDisplayUpTo");205206str = "canDisplayUpTo";207f1.canDisplayUpTo(str.toCharArray(), 0, str.length());208f2.canDisplayUpTo(str.toCharArray(), 0, str.length());209f3.canDisplayUpTo(str.toCharArray(), 0, str.length());210f4.canDisplayUpTo(str.toCharArray(), 0, str.length());211212f1.canDisplayUpTo(new StringCharacterIterator(str), 0, str.length());213f2.canDisplayUpTo(new StringCharacterIterator(str), 0, str.length());214f3.canDisplayUpTo(new StringCharacterIterator(str), 0, str.length());215f4.canDisplayUpTo(new StringCharacterIterator(str), 0, str.length());216217f1.getItalicAngle();218f2.getItalicAngle();219f3.getItalicAngle();220f4.getItalicAngle();221222f1.hasUniformLineMetrics();223f2.hasUniformLineMetrics();224f3.hasUniformLineMetrics();225f4.hasUniformLineMetrics();226}227}228229Font f = new Font(attMap);230f = Font.getFont(attMap);231f = Font.decode(null);232}233}234235236