jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java
author serb
Fri, 03 Apr 2015 17:17:36 +0300
changeset 29922 7b9c1e1532cf
parent 29730 eab36f5cc7ac
child 31653 d88ff422c7fb
permissions -rw-r--r--
8027771: Enhance thread contexts Reviewed-by: anthony, serb
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
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
     2
 * Copyright (c) 2011, 2014, 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.*;
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
    45
import sun.misc.InnocuousThread;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
26007
dba8f49653ce 8035165: Expose internal representation in sun.awt.X11
serb
parents: 24520
diff changeset
    47
public final class CFontManager extends SunFontManager {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
    private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
    protected FontConfiguration createFontConfiguration() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
        FontConfiguration fc = new CFontConfiguration(this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
        fc.init();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
        return fc;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
    public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
                                                     boolean preferPropFonts)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
        return new CFontConfiguration(this, preferLocaleFonts, preferPropFonts);
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
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
     * Returns an array of two strings. The first element is the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
     * name of the font. The second element is the file name.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
    @Override
26007
dba8f49653ce 8035165: Expose internal representation in sun.awt.X11
serb
parents: 24520
diff changeset
    69
    protected String[] getDefaultPlatformFont() {
dba8f49653ce 8035165: Expose internal representation in sun.awt.X11
serb
parents: 24520
diff changeset
    70
        return new String[]{"Lucida Grande",
dba8f49653ce 8035165: Expose internal representation in sun.awt.X11
serb
parents: 24520
diff changeset
    71
                            "/System/Library/Fonts/LucidaGrande.ttc"};
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
    // 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
    75
    public static Font2D[] getGenericFonts() {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
    76
        return genericFonts.values().toArray(new Font2D[0]);
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
    public Font2D registerGenericFont(Font2D f)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
        return registerGenericFont(f, false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    public Font2D registerGenericFont(Font2D f, boolean logicalFont)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
        int rank = 4;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
        String fontName = f.fullName;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
        String familyName = f.familyName;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
        if (fontName == null || "".equals(fontName)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
            return null;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
        // logical fonts always need to be added to the family
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
        // 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
    96
        // or the fullNameToFont table since they are covers for
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
        // already existing fonts in this list
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
        if (logicalFont || !genericFonts.containsKey(fontName)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
            if (FontUtilities.debugFonts()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
                FontUtilities.getLogger().info("Add to Family "+familyName +
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
                    ", Font " + fontName + " rank="+rank);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
            FontFamily family = FontFamily.getFamily(familyName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
            if (family == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
                family = new FontFamily(familyName, false, rank);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
                family.setFont(f, f.style);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
            } else if (family.getRank() >= rank) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
                family.setFont(f, f.style);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
            if (!logicalFont)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
            {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
                genericFonts.put(fontName, f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
                fullNameToFont.put(fontName.toLowerCase(Locale.ENGLISH), f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
            return f;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
        } else {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   117
            return genericFonts.get(fontName);
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
    public Font2D[] getRegisteredFonts() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
        Font2D[] regFonts = super.getRegisteredFonts();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
        // Add in the Mac OS X native fonts
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
        Font2D[] genericFonts = getGenericFonts();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
        Font2D[] allFonts = new Font2D[regFonts.length+genericFonts.length];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
        System.arraycopy(regFonts, 0, allFonts, 0, regFonts.length);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
        System.arraycopy(genericFonts, 0, allFonts, regFonts.length, genericFonts.length);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
        return allFonts;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
    protected void addNativeFontFamilyNames(TreeMap<String, String> familyNames, Locale requestedLocale) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
        Font2D[] genericfonts = getGenericFonts();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
        for (int i=0; i < genericfonts.length; i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
            if (!(genericfonts[i] instanceof NativeFont)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
                String name = genericfonts[i].getFamilyName(requestedLocale);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
                familyNames.put(name.toLowerCase(requestedLocale), name);
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
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
    public Font2D createFont2D(File fontFile, int fontFormat, boolean isCopy, CreatedFontTracker tracker) throws FontFormatException {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
    String fontFilePath = fontFile.getPath();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
    Font2D font2D = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
    final File fFile = fontFile;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
    final CreatedFontTracker _tracker = tracker;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
    try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
        switch (fontFormat) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
            case Font.TRUETYPE_FONT:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
                        font2D = new TrueTypeFont(fontFilePath, null, 0, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
            case Font.TYPE1_FONT:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
                        font2D = new Type1Font(fontFilePath, null, isCopy);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
            default:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
                throw new FontFormatException("Unrecognised Font Format");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
    } catch (FontFormatException e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
        if (isCopy) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
            java.security.AccessController.doPrivileged(
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
                    new java.security.PrivilegedAction<Object>() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
                        public Object run() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
                            if (_tracker != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
                                _tracker.subBytes((int)fFile.length());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
                            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
                            fFile.delete();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
                            return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
                        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
                    });
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
        throw(e);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
    if (isCopy) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
        FileFont.setFileToRemove(font2D, fontFile, tracker);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
        synchronized (FontManager.class) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
            if (tmpFontFiles == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
                tmpFontFiles = new Vector<File>();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
            tmpFontFiles.add(fontFile);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
            if (fileCloser == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
                final Runnable fileCloserRunnable = new Runnable() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
                    public void run() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
                        java.security.AccessController.doPrivileged(
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
                                new java.security.PrivilegedAction<Object>() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
                                    public Object run() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
                                        for (int i=0;i<CHANNELPOOLSIZE;i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
                                            if (fontFileCache[i] != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
                                                try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
                                                    fontFileCache[i].close();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
                                                } catch (Exception e) {}
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
                                        if (tmpFontFiles != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
                                            File[] files = new File[tmpFontFiles.size()];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
                                            files = tmpFontFiles.toArray(files);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
                                            for (int f=0; f<files.length;f++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
                                                try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
                                                    files[f].delete();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
                                                } catch (Exception e) {}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
                                            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
                                        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
                                        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
                                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
                                });
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
                };
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   215
                AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   216
                            if (System.getSecurityManager() == null) {
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   217
                                /* The thread must be a member of a thread group
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   218
                                 * which will not get GCed before VM exit.
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   219
                                 * Make its parent the top-level thread group.
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   220
                                 */
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   221
                                ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup();
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   222
                                fileCloser = new Thread(rootTG, fileCloserRunnable);
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   223
                            } else {
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   224
                                /* InnocuousThread is a member of a correct TG by default */
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   225
                                fileCloser = new InnocuousThread(fileCloserRunnable);
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 29730
diff changeset
   226
                            }
23900
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 22584
diff changeset
   227
                            fileCloser.setContextClassLoader(null);
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 22584
diff changeset
   228
                            Runtime.getRuntime().addShutdownHook(fileCloser);
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 22584
diff changeset
   229
                            return null;
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 22584
diff changeset
   230
                        }
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 22584
diff changeset
   231
                );
12047
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
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
        return font2D;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
    protected void registerFontsInDir(String dirName, boolean useJavaRasterizer, int fontRank, boolean defer, boolean resolveSymLinks) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
        loadNativeDirFonts(dirName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
        super.registerFontsInDir(dirName, useJavaRasterizer, fontRank, defer, resolveSymLinks);
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
    private native void loadNativeDirFonts(String dirName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
    private native void loadNativeFonts();
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
    void registerFont(String fontName, String fontFamilyName) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
        final CFont font = new CFont(fontName, fontFamilyName);
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
        registerGenericFont(font);
28996
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   250
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
28996
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   252
    void registerItalicDerived() {
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   253
        FontFamily[] famArr = FontFamily.getAllFontFamilies();
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   254
        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
   255
            FontFamily family = famArr[i];
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   256
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   257
            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
   258
            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
   259
            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
   260
            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
   261
            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
   262
            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
   263
            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
   264
            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
   265
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   266
            CFont plain = (CFont)f2dPlain;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   267
            CFont bold = (CFont)f2dBold;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   268
            CFont italic = (CFont)f2dItalic;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   269
            CFont boldItalic = (CFont)f2dBoldItalic;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   270
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   271
            if (bold == null) bold = plain;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   272
            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
   273
            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
   274
            if (plain != null && italic == null) {
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   275
               registerGenericFont(plain.createItalicVariant(), true);
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   276
            }
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   277
            if (bold != null && boldItalic == null) {
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   278
               registerGenericFont(bold.createItalicVariant(), true);
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   279
            }
12047
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
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
    Object waitForFontsToBeLoaded  = new Object();
28996
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   284
    private boolean loadedAllFonts = false;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   285
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
    public void loadFonts()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
        synchronized(waitForFontsToBeLoaded)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
        {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
            super.loadFonts();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
            java.security.AccessController.doPrivileged(
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
                new java.security.PrivilegedAction<Object>() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
                    public Object run() {
28996
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   294
                        if (!loadedAllFonts) {
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   295
                           loadNativeFonts();
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   296
                           registerItalicDerived();
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   297
                           loadedAllFonts = true;
4d9228fac01a 8064833: [macosx] Native font lookup uses family+style, not full name/postscript name
prr
parents: 26037
diff changeset
   298
                        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
                        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
            );
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
            String defaultFont = "Lucida Grande";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
            String defaultFallback = "Lucida Sans";
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
            setupLogicalFonts("Dialog", defaultFont, defaultFallback);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   308
            setupLogicalFonts("Serif", "Times", "Lucida Bright");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
            setupLogicalFonts("SansSerif", defaultFont, defaultFallback);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
            setupLogicalFonts("Monospaced", "Menlo", "Lucida Sans Typewriter");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
            setupLogicalFonts("DialogInput", defaultFont, defaultFallback);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
    protected void setupLogicalFonts(String logicalName, String realName, String fallbackName) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
        FontFamily realFamily = getFontFamilyWithExtraTry(logicalName, realName, fallbackName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
        cloneStyledFont(realFamily, logicalName, Font.PLAIN);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
        cloneStyledFont(realFamily, logicalName, Font.BOLD);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
        cloneStyledFont(realFamily, logicalName, Font.ITALIC);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
        cloneStyledFont(realFamily, logicalName, Font.BOLD | Font.ITALIC);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
    protected FontFamily getFontFamilyWithExtraTry(String logicalName, String realName, String fallbackName){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
        FontFamily family = getFontFamily(realName, fallbackName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
        if (family != null) return family;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
        // 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
   329
        super.loadFonts();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
        family = getFontFamily(realName, fallbackName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
        if (family != null) return family;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
        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
   335
        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   336
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
    protected FontFamily getFontFamily(String realName, String fallbackName){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
        FontFamily family = FontFamily.getFamily(realName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
        if (family != null) return family;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
        family = FontFamily.getFamily(fallbackName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
        if (family != null){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
            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
   345
            return family;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
    protected boolean cloneStyledFont(FontFamily realFamily, String logicalFamilyName, int style) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
        if (realFamily == null) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
        Font2D realFont = realFamily.getFontWithExactStyleMatch(style);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
        if (realFont == null || !(realFont instanceof CFont)) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
        CFont newFont = new CFont((CFont)realFont, logicalFamilyName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
        registerGenericFont(newFont, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
        return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
    public String getFontPath(boolean noType1Fonts) {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 13767
diff changeset
   365
        // 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
   366
        Toolkit tk = Toolkit.getDefaultToolkit();
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
   367
        if (tk instanceof HeadlessToolkit) {
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
   368
            tk = ((HeadlessToolkit)tk).getUnderlyingToolkit();
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
   369
        }
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
   370
        if (tk instanceof LWCToolkit) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
            return "";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
        }
13767
5ea857776c3f 7181199: [macosx] Startup is much slower in headless mode for apps using Fonts
bae
parents: 12047
diff changeset
   373
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
        // X11 case
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
        return "/Library/Fonts";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   378
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   379
    protected FontUIResource getFontConfigFUIR(
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
            String family, int style, int size)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
        String mappedName = FontUtilities.mapFcName(family);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
        if (mappedName == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   384
            mappedName = "sansserif";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   385
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   386
        return new FontUIResource(mappedName, style, size);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   387
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
    // Only implemented on Windows
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   391
    protected void populateFontFileNameMap(HashMap<String, String> fontToFileMap, HashMap<String, String> fontToFamilyNameMap,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   392
            HashMap<String, ArrayList<String>> familyToFontListMap, Locale locale) {}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
}