src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58592 fd7e7bb190aa
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
     1
/*
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
     2
 * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
     4
 *
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    10
 *
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    15
 * accompanied this code).
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    16
 *
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
2372
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 883
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    24
 */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    25
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    26
package sun.font;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    27
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    28
import java.io.File;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    29
import java.io.FileInputStream;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    30
import java.io.FileOutputStream;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    31
import java.io.IOException;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    32
import java.net.InetAddress;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    33
import java.net.UnknownHostException;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    34
import java.nio.charset.Charset;
23282
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
    35
import java.nio.charset.StandardCharsets;
13041
8477cb6992be 7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents: 9461
diff changeset
    36
import java.nio.file.Files;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    37
import java.util.HashMap;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    38
import java.util.HashSet;
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
    39
import java.util.Locale;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    40
import java.util.Properties;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    41
import java.util.Scanner;
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents: 28983
diff changeset
    42
import sun.awt.FcFontManager;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    43
import sun.awt.FontConfiguration;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    44
import sun.awt.FontDescriptor;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    45
import sun.awt.SunToolkit;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    46
import sun.font.CompositeFontDescriptor;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    47
import sun.font.FontConfigManager.FontConfigInfo;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    48
import sun.font.FontConfigManager.FcCompFont;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    49
import sun.font.FontConfigManager.FontConfigFont;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
    50
import sun.util.logging.PlatformLogger;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    51
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    52
public class FcFontConfiguration extends FontConfiguration {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    53
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    54
    /** Version of the cache file format understood by this code.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    55
     * Its part of the file name so that we can rev this at
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    56
     * any time, even in a minor JDK update.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    57
     * It is stored as the value of the "version" property.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    58
     * This is distinct from the version of "libfontconfig" that generated
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    59
     * the cached results, and which is the "fcversion" property in the file.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    60
     * {@code FontConfiguration.getVersion()} also returns a version string,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    61
     * and has meant the version of the fontconfiguration.properties file
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    62
     * that was read. Since this class doesn't use such files, then what
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    63
     * that really means is whether the methods on this class return
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    64
     * values that are compatible with the classes that do directly read
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    65
     * from such files. It is a compatible subset of version "1".
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    66
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    67
    private static final String fileVersion = "1";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    68
    private String fcInfoFileName = null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    69
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    70
    private FcCompFont[] fcCompFonts = null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    71
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    72
    public FcFontConfiguration(SunFontManager fm) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    73
        super(fm);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    74
        init();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    75
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    76
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    77
    /* This isn't called but is needed to satisfy super-class contract. */
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    78
    public FcFontConfiguration(SunFontManager fm,
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    79
                               boolean preferLocaleFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    80
                               boolean preferPropFonts) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    81
        super(fm, preferLocaleFonts, preferPropFonts);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    82
        init();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    83
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    84
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    85
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    86
    public synchronized boolean init() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    87
        if (fcCompFonts != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    88
            return true;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    89
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    90
2372
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 883
diff changeset
    91
        setFontConfiguration();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    92
        readFcInfo();
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents: 28983
diff changeset
    93
        FcFontManager fm = (FcFontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    94
        FontConfigManager fcm = fm.getFontConfigManager();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    95
        if (fcCompFonts == null) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    96
            fcCompFonts = fcm.loadFontConfig();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    97
            if (fcCompFonts != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    98
                try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    99
                    writeFcInfo();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   100
                } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   101
                    if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   102
                        warning("Exception writing fcInfo " + e);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   103
                    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   104
                }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   105
            } else if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   106
                warning("Failed to get info from libfontconfig");
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   107
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   108
        } else {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   109
            fcm.populateFontConfig(fcCompFonts);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   110
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   111
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   112
        if (fcCompFonts == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   113
            return false; // couldn't load fontconfig.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   114
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   115
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   116
        // NB already in a privileged block from SGE
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   117
        String javaHome = System.getProperty("java.home");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   118
        if (javaHome == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   119
            throw new Error("java.home property not set");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   120
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   121
        String javaLib = javaHome + File.separator + "lib";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   122
        getInstalledFallbackFonts(javaLib);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   123
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   124
        return true;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   125
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   126
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   127
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   128
    public String getFallbackFamilyName(String fontName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   129
                                        String defaultFallback) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   130
        // maintain compatibility with old font.properties files, which either
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   131
        // had aliases for TimesRoman & Co. or defined mappings for them.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   132
        String compatibilityName = getCompatibilityFamilyName(fontName);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   133
        if (compatibilityName != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   134
            return compatibilityName;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   135
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   136
        return defaultFallback;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   137
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   138
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   139
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   140
    protected String
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   141
        getFaceNameFromComponentFontName(String componentFontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   142
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   143
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   144
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   145
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   146
    protected String
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   147
        getFileNameFromComponentFontName(String componentFontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   148
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   149
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   150
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   151
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   152
    public String getFileNameFromPlatformName(String platformName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   153
        /* Platform name is the file name, but rather than returning
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   154
         * the arg, return null*/
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   155
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   156
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   157
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   158
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   159
    protected Charset getDefaultFontCharset(String fontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   160
        return Charset.forName("ISO8859_1");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   161
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   162
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   163
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   164
    protected String getEncoding(String awtFontName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   165
                                 String characterSubsetName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   166
        return "default";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   167
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   168
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   169
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   170
    protected void initReorderMap() {
25573
160050c1b09e 8048980: Fix raw and unchecked lint warnings in platform-specific sun.font files
darcy
parents: 23282
diff changeset
   171
        reorderMap = new HashMap<>();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   172
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   173
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   174
    @Override
23282
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   175
    protected FontDescriptor[] buildFontDescriptors(int fontIndex, int styleIndex) {
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   176
        CompositeFontDescriptor[] cfi = get2DCompositeFontInfo();
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   177
        int idx = fontIndex * NUM_STYLES + styleIndex;
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   178
        String[] componentFaceNames = cfi[idx].getComponentFaceNames();
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   179
        FontDescriptor[] ret = new FontDescriptor[componentFaceNames.length];
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   180
        for (int i = 0; i < componentFaceNames.length; i++) {
28983
432867ba1a45 8067364: Printing to Postscript doesn't support dieresis
neugens
parents: 25859
diff changeset
   181
            ret[i] = new FontDescriptor(componentFaceNames[i], StandardCharsets.ISO_8859_1.newEncoder(), new int[0]);
23282
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   182
        }
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   183
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   184
        return ret;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   185
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   186
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   187
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   188
    public int getNumberCoreFonts() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   189
        return 1;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   190
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   191
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   192
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   193
    public String[] getPlatformFontNames() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   194
        HashSet<String> nameSet = new HashSet<String>();
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents: 28983
diff changeset
   195
        FcFontManager fm = (FcFontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   196
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   197
        FcCompFont[] fcCompFonts = fcm.loadFontConfig();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   198
        for (int i=0; i<fcCompFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   199
            for (int j=0; j<fcCompFonts[i].allFonts.length; j++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   200
                nameSet.add(fcCompFonts[i].allFonts[j].fontFile);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   201
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   202
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   203
        return nameSet.toArray(new String[0]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   204
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   205
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   206
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   207
    public String getExtraFontPath() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   208
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   209
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   210
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   211
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   212
    public boolean needToSearchForFile(String fileName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   213
        return false;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   214
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   215
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   216
    private FontConfigFont[] getFcFontList(FcCompFont[] fcFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   217
                                           String fontname, int style) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   218
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   219
        if (fontname.equals("dialog")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   220
            fontname = "sansserif";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   221
        } else if (fontname.equals("dialoginput")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   222
            fontname = "monospaced";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   223
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   224
        for (int i=0; i<fcFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   225
            if (fontname.equals(fcFonts[i].jdkName) &&
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   226
                style == fcFonts[i].style) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   227
                return fcFonts[i].allFonts;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   228
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   229
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   230
        return fcFonts[0].allFonts;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   231
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   232
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   233
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   234
    public CompositeFontDescriptor[] get2DCompositeFontInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   235
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents: 28983
diff changeset
   236
        FcFontManager fm = (FcFontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   237
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   238
        FcCompFont[] fcCompFonts = fcm.loadFontConfig();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   239
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   240
        CompositeFontDescriptor[] result =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   241
                new CompositeFontDescriptor[NUM_FONTS * NUM_STYLES];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   242
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   243
        for (int fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   244
            String fontName = publicFontNames[fontIndex];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   245
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   246
            for (int styleIndex = 0; styleIndex < NUM_STYLES; styleIndex++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   247
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   248
                String faceName = fontName + "." + styleNames[styleIndex];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   249
                FontConfigFont[] fcFonts =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   250
                    getFcFontList(fcCompFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   251
                                  fontNames[fontIndex], styleIndex);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   252
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   253
                int numFonts = fcFonts.length;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   254
                // fall back fonts listed in the lib/fonts/fallback directory
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   255
                if (installedFallbackFontFiles != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   256
                    numFonts += installedFallbackFontFiles.length;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   257
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   258
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   259
                String[] fileNames = new String[numFonts];
23282
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   260
                String[] faceNames = new String[numFonts];
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   261
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   262
                int index;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   263
                for (index = 0; index < fcFonts.length; index++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   264
                    fileNames[index] = fcFonts[index].fontFile;
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   265
                    faceNames[index] = fcFonts[index].fullName;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   266
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   267
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   268
                if (installedFallbackFontFiles != null) {
9461
4fd9dcb3a5d0 7031011: fallbackfont testing failed on OEL 6.
prr
parents: 9035
diff changeset
   269
                    System.arraycopy(installedFallbackFontFiles, 0,
4fd9dcb3a5d0 7031011: fallbackfont testing failed on OEL 6.
prr
parents: 9035
diff changeset
   270
                                     fileNames, fcFonts.length,
4fd9dcb3a5d0 7031011: fallbackfont testing failed on OEL 6.
prr
parents: 9035
diff changeset
   271
                                     installedFallbackFontFiles.length);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   272
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   273
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   274
                result[fontIndex * NUM_STYLES + styleIndex]
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   275
                        = new CompositeFontDescriptor(
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   276
                            faceName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   277
                            1,
23282
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   278
                            faceNames,
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   279
                            fileNames,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   280
                            null, null);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   281
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   282
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   283
        return result;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   284
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   285
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   286
    /**
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   287
     * Gets the OS version string from a Linux release-specific file.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   288
     */
58592
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   289
    private String getVersionString(File f) {
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   290
        try (Scanner sc  = new Scanner(f)) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   291
            return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
58592
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   292
        } catch (Exception e) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   293
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   294
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   295
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   296
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   297
    /**
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   298
     * Sets the OS name and version from environment information.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   299
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   300
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   301
    protected void setOsNameAndVersion() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   302
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   303
        super.setOsNameAndVersion();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   304
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   305
        if (!osName.equals("Linux")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   306
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   307
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   308
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   309
            File f;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   310
            if ((f = new File("/etc/lsb-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   311
                    /* Ubuntu and (perhaps others) use only lsb-release.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   312
                     * Syntax and encoding is compatible with java properties.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   313
                     * For Ubuntu the ID is "Ubuntu".
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   314
                     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   315
                    Properties props = new Properties();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   316
                    props.load(new FileInputStream(f));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   317
                    osName = props.getProperty("DISTRIB_ID");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   318
                    osVersion =  props.getProperty("DISTRIB_RELEASE");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   319
            } else if ((f = new File("/etc/redhat-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   320
                osName = "RedHat";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   321
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   322
            } else if ((f = new File("/etc/SuSE-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   323
                osName = "SuSE";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   324
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   325
            } else if ((f = new File("/etc/turbolinux-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   326
                osName = "Turbo";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   327
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   328
            } else if ((f = new File("/etc/fedora-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   329
                osName = "Fedora";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   330
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   331
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   332
        } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   333
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   334
                warning("Exception identifying Linux distro.");
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   335
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   336
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   337
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   338
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   339
    private File getFcInfoFile() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   340
        if (fcInfoFileName == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   341
            // NB need security permissions to get true IP address, and
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   342
            // we should have those as the whole initialisation is in a
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   343
            // doPrivileged block. But in this case no exception is thrown,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   344
            // and it returns the loop back address, and so we end up with
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   345
            // "localhost"
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   346
            String hostname;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   347
            try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   348
                hostname = InetAddress.getLocalHost().getHostName();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   349
            } catch (UnknownHostException e) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   350
                hostname = "localhost";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   351
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   352
            String userDir = System.getProperty("user.home");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   353
            String version = System.getProperty("java.version");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   354
            String fs = File.separator;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   355
            String dir = userDir+fs+".java"+fs+"fonts"+fs+version;
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   356
            Locale locale = SunToolkit.getStartupLocale();
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   357
            String lang = locale.getLanguage();
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   358
            String country = locale.getCountry();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   359
            String name = "fcinfo-"+fileVersion+"-"+hostname+"-"+
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   360
                osName+"-"+osVersion+"-"+lang+"-"+country+".properties";
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   361
            fcInfoFileName = dir+fs+name;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   362
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   363
        return new File(fcInfoFileName);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   364
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   365
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   366
    private void writeFcInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   367
        Properties props = new Properties();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   368
        props.setProperty("version", fileVersion);
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents: 28983
diff changeset
   369
        FcFontManager fm = (FcFontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   370
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   371
        FontConfigInfo fcInfo = fcm.getFontConfigInfo();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   372
        props.setProperty("fcversion", Integer.toString(fcInfo.fcVersion));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   373
        if (fcInfo.cacheDirs != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   374
            for (int i=0;i<fcInfo.cacheDirs.length;i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   375
                if (fcInfo.cacheDirs[i] != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   376
                   props.setProperty("cachedir."+i,  fcInfo.cacheDirs[i]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   377
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   378
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   379
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   380
        for (int i=0; i<fcCompFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   381
            FcCompFont fci = fcCompFonts[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   382
            String styleKey = fci.jdkName+"."+fci.style;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   383
            props.setProperty(styleKey+".length",
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   384
                              Integer.toString(fci.allFonts.length));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   385
            for (int j=0; j<fci.allFonts.length; j++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   386
                props.setProperty(styleKey+"."+j+".file",
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   387
                                  fci.allFonts[j].fontFile);
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   388
                if (fci.allFonts[j].fullName != null) {
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   389
                    props.setProperty(styleKey+"."+j+".fullName",
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   390
                                      fci.allFonts[j].fullName);
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   391
                }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   392
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   393
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   394
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   395
            /* This writes into a temp file then renames when done.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   396
             * Since the rename is an atomic action within the same
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   397
             * directory no client will ever see a partially written file.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   398
             */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   399
            File fcInfoFile = getFcInfoFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   400
            File dir = fcInfoFile.getParentFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   401
            dir.mkdirs();
13041
8477cb6992be 7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents: 9461
diff changeset
   402
            File tempFile = Files.createTempFile(dir.toPath(), "fcinfo", null).toFile();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   403
            FileOutputStream fos = new FileOutputStream(tempFile);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   404
            props.store(fos,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   405
                      "JDK Font Configuration Generated File: *Do Not Edit*");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   406
            fos.close();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   407
            boolean renamed = tempFile.renameTo(fcInfoFile);
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   408
            if (!renamed && FontUtilities.debugFonts()) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   409
                System.out.println("rename failed");
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   410
                warning("Failed renaming file to "+ getFcInfoFile());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   411
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   412
        } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   413
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   414
                warning("IOException writing to "+ getFcInfoFile());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   415
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   416
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   417
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   418
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   419
    /* We want to be able to use this cache instead of invoking
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   420
     * fontconfig except when we can detect the system cache has changed.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   421
     * But there doesn't seem to be a way to find the location of
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   422
     * the system cache.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   423
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   424
    private void readFcInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   425
        File fcFile = getFcInfoFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   426
        if (!fcFile.exists()) {
58592
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   427
            if (FontUtilities.debugFonts()) {
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   428
                warning("fontconfig info file " + fcFile.toString() + " does not exist");
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   429
            }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   430
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   431
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   432
        Properties props = new Properties();
58592
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   433
        try (FileInputStream fis = new FileInputStream(fcFile)) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   434
            props.load(fis);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   435
        } catch (IOException e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   436
            if (FontUtilities.debugFonts()) {
58592
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   437
                warning("IOException (" + e.getCause() + ") reading from " + fcFile.toString());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   438
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   439
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   440
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   441
        String version = (String)props.get("version");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   442
        if (version == null || !version.equals(fileVersion)) {
58592
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   443
            if (FontUtilities.debugFonts()) {
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   444
                warning("fontconfig info file version mismatch (found: " + version +
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   445
                    ", expected: " + fileVersion + ")");
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   446
            }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   447
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   448
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   449
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   450
        // If there's a new, different fontconfig installed on the
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   451
        // system, we invalidate our fontconfig file.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   452
        String fcVersionStr = (String)props.get("fcversion");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   453
        if (fcVersionStr != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   454
            int fcVersion;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   455
            try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   456
                fcVersion = Integer.parseInt(fcVersionStr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   457
                if (fcVersion != 0 &&
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 13041
diff changeset
   458
                    fcVersion != FontConfigManager.getFontConfigVersion()) {
58592
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   459
                    if (FontUtilities.debugFonts()) {
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   460
                        warning("new, different fontconfig detected");
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   461
                    }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   462
                    return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   463
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   464
            } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   465
                if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   466
                    warning("Exception parsing version " + fcVersionStr);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   467
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   468
                return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   469
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   470
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   471
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   472
        // If we can locate the fontconfig cache dirs, then compare the
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   473
        // time stamp of those with our properties file. If we are out
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   474
        // of date then re-generate.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   475
        long lastModified = fcFile.lastModified();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   476
        int cacheDirIndex = 0;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   477
        while (cacheDirIndex<4) { // should never be more than 2 anyway.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   478
            String dir = (String)props.get("cachedir."+cacheDirIndex);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   479
            if (dir == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   480
                break;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   481
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   482
            File dirFile = new File(dir);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   483
            if (dirFile.exists() && dirFile.lastModified() > lastModified) {
58592
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   484
                if (FontUtilities.debugFonts()) {
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   485
                    warning("out of date cache directories detected");
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   486
                }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   487
                return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   488
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   489
            cacheDirIndex++;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   490
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   491
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   492
        String[] names = { "sansserif", "serif", "monospaced" };
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   493
        String[] fcnames = { "sans", "serif", "monospace" };
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   494
        int namesLen = names.length;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   495
        int numStyles = 4;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   496
        FcCompFont[] fci = new FcCompFont[namesLen*numStyles];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   497
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   498
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   499
            for (int i=0; i<namesLen; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   500
                for (int s=0; s<numStyles; s++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   501
                    int index = i*numStyles+s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   502
                    fci[index] = new FcCompFont();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   503
                    String key = names[i]+"."+s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   504
                    fci[index].jdkName = names[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   505
                    fci[index].fcFamily = fcnames[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   506
                    fci[index].style = s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   507
                    String lenStr = (String)props.get(key+".length");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   508
                    int nfonts = Integer.parseInt(lenStr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   509
                    if (nfonts <= 0) {
58592
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   510
                        if (FontUtilities.debugFonts()) {
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   511
                            warning("bad non-positive .length entry in fontconfig file " + fcFile.toString());
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   512
                        }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   513
                        return; // bad file
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   514
                    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   515
                    fci[index].allFonts = new FontConfigFont[nfonts];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   516
                    for (int f=0; f<nfonts; f++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   517
                        fci[index].allFonts[f] = new FontConfigFont();
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   518
                        String fkey = key+"."+f+".fullName";
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   519
                        String fullName = (String)props.get(fkey);
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   520
                        fci[index].allFonts[f].fullName = fullName;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   521
                        fkey = key+"."+f+".file";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   522
                        String file = (String)props.get(fkey);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   523
                        if (file == null) {
58592
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   524
                            if (FontUtilities.debugFonts()) {
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   525
                                warning("missing file value for key " + fkey + " in fontconfig file " + fcFile.toString());
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   526
                            }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   527
                            return; // bad file
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   528
                        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   529
                        fci[index].allFonts[f].fontFile = file;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   530
                    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   531
                    fci[index].firstFont =  fci[index].allFonts[0];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   532
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   533
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   534
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   535
            fcCompFonts = fci;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   536
        } catch (Throwable t) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   537
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   538
                warning(t.toString());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   539
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   540
        }
58592
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   541
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   542
        if (FontUtilities.debugFonts()) {
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   543
            PlatformLogger logger = FontUtilities.getLogger();
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   544
            logger.info("successfully parsed the fontconfig file at " + fcFile.toString());
fd7e7bb190aa 8227441: Enhance logging when reading the fontconfig info file
clanger
parents: 55192
diff changeset
   545
        }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   546
    }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   547
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   548
    private static void warning(String msg) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   549
        PlatformLogger logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   550
        logger.warning(msg);
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   551
    }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   552
}