1 
   2 /*
   3  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * @test
  27  * @bug 8043509
  28  * @summary Test locale famlly falls back to same language before English
  29  * @run main/othervm TrueTypeFontLocaleNameTest
  30  */
  31 
  32 import java.awt.Font;
  33 import java.util.Locale;
  34 
  35 public class TrueTypeFontLocaleNameTest {
  36 
  37     public static void main(String[] args) {
  38 
  39         String os = System.getProperty("os.name", "");
  40         if (!os.toLowerCase().startsWith("win")) {
  41             return;
  42         }
  43         System.setProperty("user.language", "de");
  44         System.setProperty("user.country", "AT");
  45         Locale de_atLocale = new Locale("de", "AT");
  46         Locale.setDefault(de_atLocale);
  47 
  48         String family = "Verdana";
  49         Font font = new Font(family, Font.BOLD, 12);
  50         if (!font.getFamily(Locale.ENGLISH).equals(family)) {
  51             System.out.println(family + " not found - skipping test.");
  52             return;
  53         }
  54 
  55         String atFontName = font.getFontName();
  56         Locale deGELocale = new Locale("de", "GE");
  57         String deFontName = font.getFontName(deGELocale);
  58         System.out.println("Austrian font name: " + atFontName);
  59         System.out.println("German font name: " + deFontName);
  60 
  61         String deLangFullName = "Verdana Fett";
  62         // We expect "Fett" for "Bold" when the language is German.
  63         // This font does have that so these should both be equal and
  64         // say "Verdana Fett"
  65         if (!deFontName.equals(atFontName)) {
  66             throw new RuntimeException("Font names differ " +
  67                                        deFontName + " " + atFontName);
  68         }
  69         if (!deLangFullName.equals(deFontName)) {
  70             throw new RuntimeException("Font name is not " + deLangFullName +
  71                                        " instead got " + deFontName);
  72         }
  73     }
  74 }