src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java
author tnakamura
Sun, 02 Jun 2019 16:59:41 -0700
changeset 55192 26dd6fdc4165
parent 47216 71c04702a3d5
child 58592 fd7e7bb190aa
permissions -rw-r--r--
8219901: Noto fonts for East Asian countries cannot belong to CompositeFont Reviewed-by: prr, jdv
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.awt.Font;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    29
import java.io.File;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    30
import java.io.FileInputStream;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    31
import java.io.FileOutputStream;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    32
import java.io.IOException;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    33
import java.net.InetAddress;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    34
import java.net.UnknownHostException;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    35
import java.nio.charset.Charset;
23282
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
    36
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
    37
import java.nio.file.Files;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    38
import java.util.HashMap;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    39
import java.util.HashSet;
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
    40
import java.util.Locale;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    41
import java.util.Properties;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    42
import java.util.Scanner;
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents: 28983
diff changeset
    43
import sun.awt.FcFontManager;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    44
import sun.awt.FontConfiguration;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    45
import sun.awt.FontDescriptor;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    46
import sun.awt.SunToolkit;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    47
import sun.font.CompositeFontDescriptor;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    48
import sun.font.FontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    49
import sun.font.FontConfigManager.FontConfigInfo;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    50
import sun.font.FontConfigManager.FcCompFont;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    51
import sun.font.FontConfigManager.FontConfigFont;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    52
import sun.java2d.SunGraphicsEnvironment;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
    53
import sun.util.logging.PlatformLogger;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    54
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    55
public class FcFontConfiguration extends FontConfiguration {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    56
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    57
    /** 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
    58
     * 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
    59
     * any time, even in a minor JDK update.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    60
     * 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
    61
     * 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
    62
     * 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
    63
     * {@code FontConfiguration.getVersion()} also returns a version string,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    64
     * 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
    65
     * 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
    66
     * 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
    67
     * 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
    68
     * 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
    69
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    70
    private static final String fileVersion = "1";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    71
    private String fcInfoFileName = null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    72
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    73
    private FcCompFont[] fcCompFonts = null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    74
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    75
    public FcFontConfiguration(SunFontManager fm) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    76
        super(fm);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    77
        init();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    78
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    79
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    80
    /* This isn't called but is needed to satisfy super-class contract. */
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    81
    public FcFontConfiguration(SunFontManager fm,
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    82
                               boolean preferLocaleFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    83
                               boolean preferPropFonts) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    84
        super(fm, preferLocaleFonts, preferPropFonts);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    85
        init();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    86
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    87
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    88
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    89
    public synchronized boolean init() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    90
        if (fcCompFonts != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    91
            return true;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    92
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    93
2372
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 883
diff changeset
    94
        setFontConfiguration();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    95
        readFcInfo();
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents: 28983
diff changeset
    96
        FcFontManager fm = (FcFontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    97
        FontConfigManager fcm = fm.getFontConfigManager();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    98
        if (fcCompFonts == null) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    99
            fcCompFonts = fcm.loadFontConfig();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   100
            if (fcCompFonts != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   101
                try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   102
                    writeFcInfo();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   103
                } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   104
                    if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   105
                        warning("Exception writing fcInfo " + e);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   106
                    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   107
                }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   108
            } else if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   109
                warning("Failed to get info from libfontconfig");
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
        } else {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   112
            fcm.populateFontConfig(fcCompFonts);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   113
        }
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
        if (fcCompFonts == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   116
            return false; // couldn't load fontconfig.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   117
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   118
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   119
        // NB already in a privileged block from SGE
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   120
        String javaHome = System.getProperty("java.home");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   121
        if (javaHome == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   122
            throw new Error("java.home property not set");
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
        String javaLib = javaHome + File.separator + "lib";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   125
        getInstalledFallbackFonts(javaLib);
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
        return true;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   128
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   129
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   130
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   131
    public String getFallbackFamilyName(String fontName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   132
                                        String defaultFallback) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   133
        // maintain compatibility with old font.properties files, which either
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   134
        // 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
   135
        String compatibilityName = getCompatibilityFamilyName(fontName);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   136
        if (compatibilityName != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   137
            return compatibilityName;
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
        return defaultFallback;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   140
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   141
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   142
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   143
    protected String
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   144
        getFaceNameFromComponentFontName(String componentFontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   145
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   146
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   147
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   148
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   149
    protected String
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   150
        getFileNameFromComponentFontName(String componentFontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   151
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   152
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   153
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   154
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   155
    public String getFileNameFromPlatformName(String platformName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   156
        /* 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
   157
         * the arg, return null*/
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   158
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   159
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   160
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   161
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   162
    protected Charset getDefaultFontCharset(String fontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   163
        return Charset.forName("ISO8859_1");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   164
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   165
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   166
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   167
    protected String getEncoding(String awtFontName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   168
                                 String characterSubsetName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   169
        return "default";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   170
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   171
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   172
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   173
    protected void initReorderMap() {
25573
160050c1b09e 8048980: Fix raw and unchecked lint warnings in platform-specific sun.font files
darcy
parents: 23282
diff changeset
   174
        reorderMap = new HashMap<>();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   175
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   176
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   177
    @Override
23282
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   178
    protected FontDescriptor[] buildFontDescriptors(int fontIndex, int styleIndex) {
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   179
        CompositeFontDescriptor[] cfi = get2DCompositeFontInfo();
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   180
        int idx = fontIndex * NUM_STYLES + styleIndex;
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   181
        String[] componentFaceNames = cfi[idx].getComponentFaceNames();
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   182
        FontDescriptor[] ret = new FontDescriptor[componentFaceNames.length];
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   183
        for (int i = 0; i < componentFaceNames.length; i++) {
28983
432867ba1a45 8067364: Printing to Postscript doesn't support dieresis
neugens
parents: 25859
diff changeset
   184
            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
   185
        }
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   186
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   187
        return ret;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   188
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   189
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   190
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   191
    public int getNumberCoreFonts() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   192
        return 1;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   193
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   194
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   195
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   196
    public String[] getPlatformFontNames() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   197
        HashSet<String> nameSet = new HashSet<String>();
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents: 28983
diff changeset
   198
        FcFontManager fm = (FcFontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   199
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   200
        FcCompFont[] fcCompFonts = fcm.loadFontConfig();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   201
        for (int i=0; i<fcCompFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   202
            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
   203
                nameSet.add(fcCompFonts[i].allFonts[j].fontFile);
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
        return nameSet.toArray(new String[0]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   207
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   208
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   209
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   210
    public String getExtraFontPath() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   211
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   212
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   213
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   214
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   215
    public boolean needToSearchForFile(String fileName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   216
        return false;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   217
    }
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
    private FontConfigFont[] getFcFontList(FcCompFont[] fcFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   220
                                           String fontname, int style) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   221
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   222
        if (fontname.equals("dialog")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   223
            fontname = "sansserif";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   224
        } else if (fontname.equals("dialoginput")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   225
            fontname = "monospaced";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   226
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   227
        for (int i=0; i<fcFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   228
            if (fontname.equals(fcFonts[i].jdkName) &&
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   229
                style == fcFonts[i].style) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   230
                return fcFonts[i].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
        return fcFonts[0].allFonts;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   234
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   235
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   236
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   237
    public CompositeFontDescriptor[] get2DCompositeFontInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   238
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents: 28983
diff changeset
   239
        FcFontManager fm = (FcFontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   240
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   241
        FcCompFont[] fcCompFonts = fcm.loadFontConfig();
883
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
        CompositeFontDescriptor[] result =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   244
                new CompositeFontDescriptor[NUM_FONTS * NUM_STYLES];
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 fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   247
            String fontName = publicFontNames[fontIndex];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   248
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   249
            for (int styleIndex = 0; styleIndex < NUM_STYLES; styleIndex++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   250
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   251
                String faceName = fontName + "." + styleNames[styleIndex];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   252
                FontConfigFont[] fcFonts =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   253
                    getFcFontList(fcCompFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   254
                                  fontNames[fontIndex], styleIndex);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   255
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   256
                int numFonts = fcFonts.length;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   257
                // 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
   258
                if (installedFallbackFontFiles != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   259
                    numFonts += installedFallbackFontFiles.length;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   260
                }
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
                String[] fileNames = new String[numFonts];
23282
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   263
                String[] faceNames = new String[numFonts];
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   264
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   265
                int index;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   266
                for (index = 0; index < fcFonts.length; index++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   267
                    fileNames[index] = fcFonts[index].fontFile;
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   268
                    faceNames[index] = fcFonts[index].fullName;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   269
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   270
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   271
                if (installedFallbackFontFiles != null) {
9461
4fd9dcb3a5d0 7031011: fallbackfont testing failed on OEL 6.
prr
parents: 9035
diff changeset
   272
                    System.arraycopy(installedFallbackFontFiles, 0,
4fd9dcb3a5d0 7031011: fallbackfont testing failed on OEL 6.
prr
parents: 9035
diff changeset
   273
                                     fileNames, fcFonts.length,
4fd9dcb3a5d0 7031011: fallbackfont testing failed on OEL 6.
prr
parents: 9035
diff changeset
   274
                                     installedFallbackFontFiles.length);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   275
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   276
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   277
                result[fontIndex * NUM_STYLES + styleIndex]
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   278
                        = new CompositeFontDescriptor(
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   279
                            faceName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   280
                            1,
23282
3ea147eb359c 8023990: Regression: postscript size increase from 6u18
anashaty
parents: 22567
diff changeset
   281
                            faceNames,
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   282
                            fileNames,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   283
                            null, null);
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
        return result;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   287
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   288
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   289
    /**
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   290
     * 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
   291
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   292
    private String getVersionString(File f){
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   293
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   294
            Scanner sc  = new Scanner(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   295
            return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
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
        catch (Exception e){
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   298
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   299
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   300
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   301
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
     * Sets the OS name and version from environment information.
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
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   306
    protected void setOsNameAndVersion() {
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
        super.setOsNameAndVersion();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   309
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   310
        if (!osName.equals("Linux")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   311
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   312
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   313
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   314
            File f;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   315
            if ((f = new File("/etc/lsb-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   316
                    /* Ubuntu and (perhaps others) use only lsb-release.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   317
                     * Syntax and encoding is compatible with java properties.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   318
                     * For Ubuntu the ID is "Ubuntu".
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   319
                     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   320
                    Properties props = new Properties();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   321
                    props.load(new FileInputStream(f));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   322
                    osName = props.getProperty("DISTRIB_ID");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   323
                    osVersion =  props.getProperty("DISTRIB_RELEASE");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   324
            } else if ((f = new File("/etc/redhat-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   325
                osName = "RedHat";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   326
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   327
            } else if ((f = new File("/etc/SuSE-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   328
                osName = "SuSE";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   329
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   330
            } else if ((f = new File("/etc/turbolinux-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   331
                osName = "Turbo";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   332
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   333
            } else if ((f = new File("/etc/fedora-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   334
                osName = "Fedora";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   335
                osVersion = getVersionString(f);
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
        } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   338
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   339
                warning("Exception identifying Linux distro.");
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   340
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   341
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   342
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   343
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   344
    private File getFcInfoFile() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   345
        if (fcInfoFileName == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   346
            // 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
   347
            // 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
   348
            // 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
   349
            // 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
   350
            // "localhost"
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   351
            String hostname;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   352
            try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   353
                hostname = InetAddress.getLocalHost().getHostName();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   354
            } catch (UnknownHostException e) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   355
                hostname = "localhost";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   356
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   357
            String userDir = System.getProperty("user.home");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   358
            String version = System.getProperty("java.version");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   359
            String fs = File.separator;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   360
            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
   361
            Locale locale = SunToolkit.getStartupLocale();
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   362
            String lang = locale.getLanguage();
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   363
            String country = locale.getCountry();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   364
            String name = "fcinfo-"+fileVersion+"-"+hostname+"-"+
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   365
                osName+"-"+osVersion+"-"+lang+"-"+country+".properties";
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   366
            fcInfoFileName = dir+fs+name;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   367
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   368
        return new File(fcInfoFileName);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   369
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   370
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   371
    private void writeFcInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   372
        Properties props = new Properties();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   373
        props.setProperty("version", fileVersion);
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents: 28983
diff changeset
   374
        FcFontManager fm = (FcFontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   375
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   376
        FontConfigInfo fcInfo = fcm.getFontConfigInfo();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   377
        props.setProperty("fcversion", Integer.toString(fcInfo.fcVersion));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   378
        if (fcInfo.cacheDirs != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   379
            for (int i=0;i<fcInfo.cacheDirs.length;i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   380
                if (fcInfo.cacheDirs[i] != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   381
                   props.setProperty("cachedir."+i,  fcInfo.cacheDirs[i]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   382
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   383
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   384
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   385
        for (int i=0; i<fcCompFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   386
            FcCompFont fci = fcCompFonts[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   387
            String styleKey = fci.jdkName+"."+fci.style;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   388
            props.setProperty(styleKey+".length",
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   389
                              Integer.toString(fci.allFonts.length));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   390
            for (int j=0; j<fci.allFonts.length; j++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   391
                props.setProperty(styleKey+"."+j+".file",
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   392
                                  fci.allFonts[j].fontFile);
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   393
                if (fci.allFonts[j].fullName != null) {
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   394
                    props.setProperty(styleKey+"."+j+".fullName",
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   395
                                      fci.allFonts[j].fullName);
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   396
                }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   397
            }
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
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   400
            /* 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
   401
             * 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
   402
             * 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
   403
             */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   404
            File fcInfoFile = getFcInfoFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   405
            File dir = fcInfoFile.getParentFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   406
            dir.mkdirs();
13041
8477cb6992be 7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents: 9461
diff changeset
   407
            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
   408
            FileOutputStream fos = new FileOutputStream(tempFile);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   409
            props.store(fos,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   410
                      "JDK Font Configuration Generated File: *Do Not Edit*");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   411
            fos.close();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   412
            boolean renamed = tempFile.renameTo(fcInfoFile);
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   413
            if (!renamed && FontUtilities.debugFonts()) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   414
                System.out.println("rename failed");
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   415
                warning("Failed renaming file to "+ getFcInfoFile());
883
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
        } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   418
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   419
                warning("IOException writing to "+ getFcInfoFile());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   420
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   421
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   422
    }
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
    /* 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
   425
     * 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
   426
     * 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
   427
     * the system cache.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   428
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   429
    private void readFcInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   430
        File fcFile = getFcInfoFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   431
        if (!fcFile.exists()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   432
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   433
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   434
        Properties props = new Properties();
29513
643ff69483e8 8072436: Refactor X11FontManager
rkennke
parents: 28983
diff changeset
   435
        FcFontManager fm = (FcFontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   436
        FontConfigManager fcm = fm.getFontConfigManager();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   437
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   438
            FileInputStream fis = new FileInputStream(fcFile);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   439
            props.load(fis);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   440
            fis.close();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   441
        } catch (IOException e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   442
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   443
                warning("IOException reading from "+fcFile.toString());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   444
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   445
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   446
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   447
        String version = (String)props.get("version");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   448
        if (version == null || !version.equals(fileVersion)) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   449
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   450
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   451
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   452
        // 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
   453
        // system, we invalidate our fontconfig file.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   454
        String fcVersionStr = (String)props.get("fcversion");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   455
        if (fcVersionStr != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   456
            int fcVersion;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   457
            try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   458
                fcVersion = Integer.parseInt(fcVersionStr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   459
                if (fcVersion != 0 &&
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 13041
diff changeset
   460
                    fcVersion != FontConfigManager.getFontConfigVersion()) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   461
                    return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   462
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   463
            } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   464
                if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   465
                    warning("Exception parsing version " + fcVersionStr);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   466
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   467
                return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   468
            }
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
        // 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
   472
        // 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
   473
        // of date then re-generate.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   474
        long lastModified = fcFile.lastModified();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   475
        int cacheDirIndex = 0;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   476
        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
   477
            String dir = (String)props.get("cachedir."+cacheDirIndex);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   478
            if (dir == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   479
                break;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   480
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   481
            File dirFile = new File(dir);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   482
            if (dirFile.exists() && dirFile.lastModified() > lastModified) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   483
                return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   484
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   485
            cacheDirIndex++;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   486
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   487
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   488
        String[] names = { "sansserif", "serif", "monospaced" };
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   489
        String[] fcnames = { "sans", "serif", "monospace" };
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   490
        int namesLen = names.length;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   491
        int numStyles = 4;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   492
        FcCompFont[] fci = new FcCompFont[namesLen*numStyles];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   493
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   494
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   495
            for (int i=0; i<namesLen; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   496
                for (int s=0; s<numStyles; s++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   497
                    int index = i*numStyles+s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   498
                    fci[index] = new FcCompFont();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   499
                    String key = names[i]+"."+s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   500
                    fci[index].jdkName = names[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   501
                    fci[index].fcFamily = fcnames[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   502
                    fci[index].style = s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   503
                    String lenStr = (String)props.get(key+".length");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   504
                    int nfonts = Integer.parseInt(lenStr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   505
                    if (nfonts <= 0) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   506
                        return; // bad file
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   507
                    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   508
                    fci[index].allFonts = new FontConfigFont[nfonts];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   509
                    for (int f=0; f<nfonts; f++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   510
                        fci[index].allFonts[f] = new FontConfigFont();
55192
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   511
                        String fkey = key+"."+f+".fullName";
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   512
                        String fullName = (String)props.get(fkey);
26dd6fdc4165 8219901: Noto fonts for East Asian countries cannot belong to CompositeFont
tnakamura
parents: 47216
diff changeset
   513
                        fci[index].allFonts[f].fullName = fullName;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   514
                        fkey = key+"."+f+".file";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   515
                        String file = (String)props.get(fkey);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   516
                        if (file == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   517
                            return; // bad file
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   518
                        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   519
                        fci[index].allFonts[f].fontFile = file;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   520
                    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   521
                    fci[index].firstFont =  fci[index].allFonts[0];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   522
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   523
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   524
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   525
            fcCompFonts = fci;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   526
        } catch (Throwable t) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   527
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   528
                warning(t.toString());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   529
            }
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
    }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   532
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   533
    private static void warning(String msg) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   534
        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
   535
        logger.warning(msg);
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   536
    }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   537
}