src/java.desktop/macosx/classes/sun/font/CFontManager.java
author prr
Fri, 25 May 2018 16:23:17 -0700
changeset 50348 008f416a79cb
parent 47216 71c04702a3d5
child 54871 c2e4aef5edf2
permissions -rw-r--r--
8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources Reviewed-by: serb, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
31653
d88ff422c7fb 8080405: Exception in thread "AWT-EventQueue-1" java.security.AccessControlException
serb
parents: 29922
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
package sun.font;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
import java.awt.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
import java.io.File;
23900
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 22584
diff changeset
    30
import java.security.AccessController;
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 22584
diff changeset
    31
import java.security.PrivilegedAction;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
import java.util.ArrayList;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
import java.util.HashMap;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
import java.util.Hashtable;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
import java.util.Locale;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
import java.util.TreeMap;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
import java.util.Vector;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
import javax.swing.plaf.FontUIResource;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
import sun.awt.FontConfiguration;
13767
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
    42
import sun.awt.HeadlessToolkit;
24520
e8afd90fcb69 8035169: Move ThreadGroupUtils from the sun.misc package
pchelko
parents: 23900
diff changeset
    43
import sun.awt.util.ThreadGroupUtils;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
import sun.lwawt.macosx.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
26007
dba8f49653ce 8035165: Expose internal representation in sun.awt.X11
serb
parents: 24520
diff changeset
    46
public final class CFontManager extends SunFontManager {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
    private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
    protected FontConfiguration createFontConfiguration() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
        FontConfiguration fc = new CFontConfiguration(this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
        fc.init();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
        return fc;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
    public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
                                                     boolean preferPropFonts)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
        return new CFontConfiguration(this, preferLocaleFonts, preferPropFonts);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
     * Returns an array of two strings. The first element is the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
     * name of the font. The second element is the file name.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
    @Override
26007
dba8f49653ce 8035165: Expose internal representation in sun.awt.X11
serb
parents: 24520
diff changeset
    68
    protected String[] getDefaultPlatformFont() {
dba8f49653ce 8035165: Expose internal representation in sun.awt.X11
serb
parents: 24520
diff changeset
    69
        return new String[]{"Lucida Grande",
dba8f49653ce 8035165: Expose internal representation in sun.awt.X11
serb
parents: 24520
diff changeset
    70
                            "/System/Library/Fonts/LucidaGrande.ttc"};
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
    // This is a way to register any kind of Font2D, not just files and composites.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
    public static Font2D[] getGenericFonts() {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
    75
        return genericFonts.values().toArray(new Font2D[0]);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
    public Font2D registerGenericFont(Font2D f)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
        return registerGenericFont(f, false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    public Font2D registerGenericFont(Font2D f, boolean logicalFont)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
        int rank = 4;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
        String fontName = f.fullName;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
        String familyName = f.familyName;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
        if (fontName == null || "".equals(fontName)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
            return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
        // logical fonts always need to be added to the family
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
        // plus they never need to be added to the generic font list
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
        // or the fullNameToFont table since they are covers for
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
        // already existing fonts in this list
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
        if (logicalFont || !genericFonts.containsKey(fontName)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
            if (FontUtilities.debugFonts()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
                FontUtilities.getLogger().info("Add to Family "+familyName +
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
                    ", Font " + fontName + " rank="+rank);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
            FontFamily family = FontFamily.getFamily(familyName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
            if (family == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
                family = new FontFamily(familyName, false, rank);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
                family.setFont(f, f.style);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
            } else if (family.getRank() >= rank) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
                family.setFont(f, f.style);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
            if (!logicalFont)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
            {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
                genericFonts.put(fontName, f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
                fullNameToFont.put(fontName.toLowerCase(Locale.ENGLISH), f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
            return f;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
        } else {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   116
            return genericFonts.get(fontName);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
    public Font2D[] getRegisteredFonts() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
        Font2D[] regFonts = super.getRegisteredFonts();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
        // Add in the Mac OS X native fonts
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
        Font2D[] genericFonts = getGenericFonts();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
        Font2D[] allFonts = new Font2D[regFonts.length+genericFonts.length];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
        System.arraycopy(regFonts, 0, allFonts, 0, regFonts.length);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
        System.arraycopy(genericFonts, 0, allFonts, regFonts.length, genericFonts.length);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
        return allFonts;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
    protected void addNativeFontFamilyNames(TreeMap<String, String> familyNames, Locale requestedLocale) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
        Font2D[] genericfonts = getGenericFonts();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
        for (int i=0; i < genericfonts.length; i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
            if (!(genericfonts[i] instanceof NativeFont)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
                String name = genericfonts[i].getFamilyName(requestedLocale);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
                familyNames.put(name.toLowerCase(requestedLocale), name);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
42726
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   144
    protected void registerFontsInDir(final String dirName, boolean useJavaRasterizer,
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   145
                                      int fontRank, boolean defer, boolean resolveSymLinks) {
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   146
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   147
        String[] files = AccessController.doPrivileged((PrivilegedAction<String[]>) () -> {
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   148
            return new File(dirName).list(getTrueTypeFilter());
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   149
        });
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   150
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   151
        if (files == null) {
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   152
           return;
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   153
        } else {
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   154
            for (String f : files) {
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   155
                loadNativeDirFonts(dirName+File.separator+f);
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   156
            }
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   157
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
        super.registerFontsInDir(dirName, useJavaRasterizer, fontRank, defer, resolveSymLinks);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
42726
ffe8f242155d 8167103: Intermittent font loading failure on macOS with JFXPanel application
prr
parents: 37550
diff changeset
   161
    private native void loadNativeDirFonts(String fontPath);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
    private native void loadNativeFonts();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
    void registerFont(String fontName, String fontFamilyName) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
        final CFont font = new CFont(fontName, fontFamilyName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
        registerGenericFont(font);
28996
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   168
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
28996
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   170
    void registerItalicDerived() {
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   171
        FontFamily[] famArr = FontFamily.getAllFontFamilies();
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   172
        for (int i=0; i<famArr.length; i++) {
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   173
            FontFamily family = famArr[i];
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   174
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   175
            Font2D f2dPlain = family.getFont(Font.PLAIN);
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   176
            if (f2dPlain != null && !(f2dPlain instanceof CFont)) continue;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   177
            Font2D f2dBold = family.getFont(Font.BOLD);
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   178
            if (f2dBold != null && !(f2dBold instanceof CFont)) continue;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   179
            Font2D f2dItalic = family.getFont(Font.ITALIC);
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   180
            if (f2dItalic != null && !(f2dItalic instanceof CFont)) continue;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   181
            Font2D f2dBoldItalic = family.getFont(Font.BOLD|Font.ITALIC);
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   182
            if (f2dBoldItalic != null && !(f2dBoldItalic instanceof CFont)) continue;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   183
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   184
            CFont plain = (CFont)f2dPlain;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   185
            CFont bold = (CFont)f2dBold;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   186
            CFont italic = (CFont)f2dItalic;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   187
            CFont boldItalic = (CFont)f2dBoldItalic;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   188
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   189
            if (bold == null) bold = plain;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   190
            if (plain == null && bold == null) continue;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   191
            if (italic != null && boldItalic != null) continue;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   192
            if (plain != null && italic == null) {
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   193
               registerGenericFont(plain.createItalicVariant(), true);
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   194
            }
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   195
            if (bold != null && boldItalic == null) {
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   196
               registerGenericFont(bold.createItalicVariant(), true);
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   197
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
    Object waitForFontsToBeLoaded  = new Object();
28996
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   202
    private boolean loadedAllFonts = false;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   203
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
    public void loadFonts()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
        synchronized(waitForFontsToBeLoaded)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
        {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
            super.loadFonts();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
            java.security.AccessController.doPrivileged(
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
                new java.security.PrivilegedAction<Object>() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
                    public Object run() {
28996
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   212
                        if (!loadedAllFonts) {
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   213
                           loadNativeFonts();
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   214
                           registerItalicDerived();
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   215
                           loadedAllFonts = true;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   216
                        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
                        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
            );
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
            String defaultFont = "Lucida Grande";
50348
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
   223
            String defaultFallback = "Lucida Grande";
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
            setupLogicalFonts("Dialog", defaultFont, defaultFallback);
50348
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
   226
            setupLogicalFonts("Serif", "Times", "Times");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
            setupLogicalFonts("SansSerif", defaultFont, defaultFallback);
50348
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
   228
            setupLogicalFonts("Monospaced", "Menlo", "Courier");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
            setupLogicalFonts("DialogInput", defaultFont, defaultFallback);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
    protected void setupLogicalFonts(String logicalName, String realName, String fallbackName) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
        FontFamily realFamily = getFontFamilyWithExtraTry(logicalName, realName, fallbackName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
        cloneStyledFont(realFamily, logicalName, Font.PLAIN);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
        cloneStyledFont(realFamily, logicalName, Font.BOLD);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
        cloneStyledFont(realFamily, logicalName, Font.ITALIC);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
        cloneStyledFont(realFamily, logicalName, Font.BOLD | Font.ITALIC);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
    protected FontFamily getFontFamilyWithExtraTry(String logicalName, String realName, String fallbackName){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
        FontFamily family = getFontFamily(realName, fallbackName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
        if (family != null) return family;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
        // at this point, we recognize that we probably needed a fallback font
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
        super.loadFonts();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
        family = getFontFamily(realName, fallbackName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
        if (family != null) return family;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
        System.err.println("Warning: the fonts \"" + realName + "\" and \"" + fallbackName + "\" are not available for the Java logical font \"" + logicalName + "\", which may have unexpected appearance or behavior. Re-enable the \""+ realName +"\" font to remove this warning.");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
    protected FontFamily getFontFamily(String realName, String fallbackName){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
        FontFamily family = FontFamily.getFamily(realName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
        if (family != null) return family;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
        family = FontFamily.getFamily(fallbackName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
        if (family != null){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
            System.err.println("Warning: the font \"" + realName + "\" is not available, so \"" + fallbackName + "\" has been substituted, but may have unexpected appearance or behavor. Re-enable the \""+ realName +"\" font to remove this warning.");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
            return family;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
    protected boolean cloneStyledFont(FontFamily realFamily, String logicalFamilyName, int style) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
        if (realFamily == null) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
        Font2D realFont = realFamily.getFontWithExactStyleMatch(style);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
        if (realFont == null || !(realFont instanceof CFont)) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
        CFont newFont = new CFont((CFont)realFont, logicalFamilyName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
        registerGenericFont(newFont, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
        return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
    public String getFontPath(boolean noType1Fonts) {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 13767
diff changeset
   283
        // In the case of the Cocoa toolkit, since we go through NSFont, we don't need to register /Library/Fonts
13767
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
   284
        Toolkit tk = Toolkit.getDefaultToolkit();
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
   285
        if (tk instanceof HeadlessToolkit) {
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
   286
            tk = ((HeadlessToolkit)tk).getUnderlyingToolkit();
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
   287
        }
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
   288
        if (tk instanceof LWCToolkit) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
            return "";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
        }
13767
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
   291
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
        // X11 case
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
        return "/Library/Fonts";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
    protected FontUIResource getFontConfigFUIR(
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
            String family, int style, int size)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
        String mappedName = FontUtilities.mapFcName(family);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
        if (mappedName == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
            mappedName = "sansserif";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
        return new FontUIResource(mappedName, style, size);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
    // Only implemented on Windows
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   308
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
    protected void populateFontFileNameMap(HashMap<String, String> fontToFileMap, HashMap<String, String> fontToFamilyNameMap,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
            HashMap<String, ArrayList<String>> familyToFontListMap, Locale locale) {}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
}