src/java.desktop/unix/classes/sun/awt/FcFontManager.java
author prr
Fri, 25 May 2018 16:23:17 -0700
changeset 50348 008f416a79cb
parent 47216 71c04702a3d5
child 55192 26dd6fdc4165
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:
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
     1
/*
30938
35ae5c70d60e 8030087: Avoid public native methods in sun.awt packages
serb
parents: 29513
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
     4
 *
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    10
 *
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    15
 * accompanied this code).
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    16
 *
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    20
 *
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    23
 * questions.
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    24
 */
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    25
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    26
package sun.awt;
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    27
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    28
import sun.font.FcFontConfiguration;
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    29
import sun.font.FontConfigManager;
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    30
import sun.font.SunFontManager;
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    31
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    32
/**
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    33
 * A {@link sun.font.FontManager} that uses fontconfig to find system fonts.
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    34
 */
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    35
public class FcFontManager extends SunFontManager {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    36
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    37
    private FontConfigManager fcManager = null;
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    38
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    39
    public synchronized FontConfigManager getFontConfigManager() {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    40
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    41
        if (fcManager == null) {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    42
            fcManager = new FontConfigManager();
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    43
        }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    44
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    45
        return fcManager;
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    46
    }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    47
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    48
    @Override
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    49
    protected FontConfiguration createFontConfiguration() {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    50
        FcFontConfiguration fcFontConfig = new FcFontConfiguration(this);
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    51
        if (fcFontConfig.init()) {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    52
            return fcFontConfig;
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    53
        } else {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    54
            throw new InternalError("failed to initialize fontconfig");
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    55
        }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    56
    }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    57
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    58
    @Override
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    59
    public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    60
                                                     boolean preferPropFonts) {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    61
        FcFontConfiguration fcFontConfig =
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    62
            new FcFontConfiguration(this, preferLocaleFonts, preferPropFonts);
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    63
        if (fcFontConfig.init()) {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    64
            return fcFontConfig;
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    65
        } else {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    66
            throw new InternalError("failed to initialize fontconfig");
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    67
        }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    68
    }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    69
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    70
    @Override
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    71
    protected String[] getDefaultPlatformFont() {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    72
        final String[] info = new String[2];
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    73
        getFontConfigManager().initFontConfigFonts(false);
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    74
        FontConfigManager.FcCompFont[] fontConfigFonts =
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    75
            getFontConfigManager().getFontConfigFonts();
50348
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
    76
        if (fontConfigFonts != null) {
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
    77
            for (int i=0; i<fontConfigFonts.length; i++) {
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
    78
                if ("sans".equals(fontConfigFonts[i].fcFamily) &&
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
    79
                    0 == fontConfigFonts[i].style) {
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
    80
                    info[0] = fontConfigFonts[i].firstFont.familyName;
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
    81
                    info[1] = fontConfigFonts[i].firstFont.fontFile;
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
    82
                    break;
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
    83
                }
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    84
            }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    85
        }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    86
        /* Absolute last ditch attempt in the face of fontconfig problems.
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    87
         * If we didn't match, pick the first, or just make something
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    88
         * up so we don't NPE.
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    89
         */
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    90
        if (info[0] == null) {
50348
008f416a79cb 8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents: 47216
diff changeset
    91
            if (fontConfigFonts != null && fontConfigFonts.length > 0 &&
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    92
                fontConfigFonts[0].firstFont.fontFile != null) {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    93
                info[0] = fontConfigFonts[0].firstFont.familyName;
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    94
                info[1] = fontConfigFonts[0].firstFont.fontFile;
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    95
            } else {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    96
                info[0] = "Dialog";
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    97
                info[1] = "/dialog.ttf";
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    98
            }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
    99
        }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
   100
        return info;
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
   101
    }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
   102
30938
35ae5c70d60e 8030087: Avoid public native methods in sun.awt packages
serb
parents: 29513
diff changeset
   103
    native String getFontPathNative(boolean noType1Fonts, boolean isX11GE);
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
   104
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
   105
    protected synchronized String getFontPath(boolean noType1Fonts) {
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
   106
        return getFontPathNative(noType1Fonts, false);
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
   107
    }
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
   108
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents:
diff changeset
   109
}