jdk/test/java/awt/FontClass/AppleFontNameTest.java
author hannesw
Wed, 08 Feb 2017 11:57:41 +0100 (2017-02-08)
changeset 46001 f7865942462f
parent 43310 0746906c86f6
permissions -rw-r--r--
8171539: Better script accessibility for JavaScript Reviewed-by: jlaskey, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43310
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
     1
/*
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
     4
 *
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
     8
 *
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    13
 * accompanied this code).
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    14
 *
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    18
 *
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    21
 * questions.
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    22
 */
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    23
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    24
/*
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    25
 * @test
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    26
 * @bug 6232267
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    27
 * @requires (os.family == "mac")
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    28
 * @summary Test reading a font with only Apple names.
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    29
 * @run main AppleFontNameTest
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    30
 */
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    31
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    32
import java.awt.Font;
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    33
import java.io.File;
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    34
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    35
/*
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    36
 * This test picks on a font that is known to have only Apple names.
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    37
 * So it runs only on MacOS and works only if the font is where it
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    38
 * has historically been. Anything else is a silent pass.`
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    39
 */
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    40
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    41
public class AppleFontNameTest {
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    42
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    43
    static String file = "/System/Library/Fonts/Menlo.ttc";
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    44
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    46
        String os = System.getProperty("os.name");
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    47
        if (!(os.startsWith("Mac"))) {
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    48
            return;
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    49
        }
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    50
        File fontFile = new File(file);
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    51
        if (!fontFile.exists()) {
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    52
            return;
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    53
        }
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    54
        Font[] fonts = Font.createFonts(new File(file));
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    55
        System.out.println("createFont from file returned " + fonts);
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    56
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    57
        if (fonts == null || fonts.length == 0) {
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    58
            throw new RuntimeException("No fonts");
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    59
        }
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    60
        for (Font f : fonts) {
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    61
            System.out.println(f);
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    62
            if (!f.getFamily().equals("Menlo"))
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    63
               throw new RuntimeException("Expected Menlo, got " + f.getFamily());
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    64
        }
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    65
    }
0746906c86f6 6232267: TrueType Fonts which have only Apple platform names cannot be loaded
prr
parents:
diff changeset
    66
}