jdk/src/solaris/classes/sun/font/FcFontConfiguration.java
author darcy
Wed, 22 Jan 2014 23:20:58 -0800
changeset 22567 5816a47fa4dd
parent 13041 8477cb6992be
child 23282 3ea147eb359c
permissions -rw-r--r--
8032047: Fix static lint warnings in client libraries 8032048: Add static lint warning to build of jdk repository Reviewed-by: pchelko, serb, erikj
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
/*
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 13041
diff changeset
     2
 * Copyright (c) 2008, 2014, 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;
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;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    39
import java.util.Properties;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    40
import java.util.Scanner;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    41
import sun.awt.FontConfiguration;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    42
import sun.awt.FontDescriptor;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    43
import sun.awt.SunToolkit;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    44
import sun.awt.X11FontManager;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    45
import sun.font.CompositeFontDescriptor;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    46
import sun.font.FontManager;
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;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    50
import sun.java2d.SunGraphicsEnvironment;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
    51
import sun.util.logging.PlatformLogger;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    52
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    53
public class FcFontConfiguration extends FontConfiguration {
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
    /** 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
    56
     * 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
    57
     * any time, even in a minor JDK update.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    58
     * 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
    59
     * 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
    60
     * 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
    61
     * {@code FontConfiguration.getVersion()} also returns a version string,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    62
     * 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
    63
     * 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
    64
     * 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
    65
     * 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
    66
     * 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
    67
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    68
    private static final String fileVersion = "1";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    69
    private String fcInfoFileName = null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    70
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    71
    private FcCompFont[] fcCompFonts = null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    72
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    73
    public FcFontConfiguration(SunFontManager fm) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    74
        super(fm);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    75
        init();
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    78
    /* This isn't called but is needed to satisfy super-class contract. */
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    79
    public FcFontConfiguration(SunFontManager fm,
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    80
                               boolean preferLocaleFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    81
                               boolean preferPropFonts) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    82
        super(fm, preferLocaleFonts, preferPropFonts);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    83
        init();
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    86
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    87
    public synchronized boolean init() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    88
        if (fcCompFonts != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    89
            return true;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    90
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    91
2372
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 883
diff changeset
    92
        setFontConfiguration();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    93
        readFcInfo();
3930
738bc2599ca8 6870238: Font2DTest fails on Debian after FontManager refactoring
rkennke
parents: 3928
diff changeset
    94
        X11FontManager fm = (X11FontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    95
        FontConfigManager fcm = fm.getFontConfigManager();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    96
        if (fcCompFonts == null) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    97
            fcCompFonts = fcm.loadFontConfig();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    98
            if (fcCompFonts != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    99
                try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   100
                    writeFcInfo();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   101
                } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   102
                    if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   103
                        warning("Exception writing fcInfo " + e);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   104
                    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   105
                }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   106
            } else if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   107
                warning("Failed to get info from libfontconfig");
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   108
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   109
        } else {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   110
            fcm.populateFontConfig(fcCompFonts);
883
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   113
        if (fcCompFonts == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   114
            return false; // couldn't load fontconfig.
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   117
        // NB already in a privileged block from SGE
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   118
        String javaHome = System.getProperty("java.home");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   119
        if (javaHome == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   120
            throw new Error("java.home property not set");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   121
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   122
        String javaLib = javaHome + File.separator + "lib";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   123
        getInstalledFallbackFonts(javaLib);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   124
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   125
        return true;
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   128
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   129
    public String getFallbackFamilyName(String fontName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   130
                                        String defaultFallback) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   131
        // maintain compatibility with old font.properties files, which either
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   132
        // 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
   133
        String compatibilityName = getCompatibilityFamilyName(fontName);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   134
        if (compatibilityName != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   135
            return compatibilityName;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   136
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   137
        return defaultFallback;
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   140
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   141
    protected String
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   142
        getFaceNameFromComponentFontName(String componentFontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   143
        return null;
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   146
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   147
    protected String
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   148
        getFileNameFromComponentFontName(String componentFontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   149
        return null;
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   152
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   153
    public String getFileNameFromPlatformName(String platformName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   154
        /* 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
   155
         * the arg, return null*/
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   156
        return null;
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   159
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   160
    protected Charset getDefaultFontCharset(String fontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   161
        return Charset.forName("ISO8859_1");
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   164
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   165
    protected String getEncoding(String awtFontName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   166
                                 String characterSubsetName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   167
        return "default";
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   170
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   171
    protected void initReorderMap() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   172
        reorderMap = new HashMap();
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   175
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   176
    public FontDescriptor[] getFontDescriptors(String fontName, int style) {
2374
a79da6a9d184 6752622: java.awt.Font.getPeer throws "java.lang.InternalError: Not implemented" on Linux
prr
parents: 2372
diff changeset
   177
        return new FontDescriptor[0];
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   178
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   179
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   180
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   181
    public int getNumberCoreFonts() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   182
        return 1;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   183
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   184
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   185
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   186
    public String[] getPlatformFontNames() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   187
        HashSet<String> nameSet = new HashSet<String>();
3930
738bc2599ca8 6870238: Font2DTest fails on Debian after FontManager refactoring
rkennke
parents: 3928
diff changeset
   188
        X11FontManager fm = (X11FontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   189
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   190
        FcCompFont[] fcCompFonts = fcm.loadFontConfig();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   191
        for (int i=0; i<fcCompFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   192
            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
   193
                nameSet.add(fcCompFonts[i].allFonts[j].fontFile);
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
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   196
        return nameSet.toArray(new String[0]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   197
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   198
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   199
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   200
    public String getExtraFontPath() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   201
        return null;
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   204
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   205
    public boolean needToSearchForFile(String fileName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   206
        return false;
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
    private FontConfigFont[] getFcFontList(FcCompFont[] fcFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   210
                                           String fontname, int style) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   211
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   212
        if (fontname.equals("dialog")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   213
            fontname = "sansserif";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   214
        } else if (fontname.equals("dialoginput")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   215
            fontname = "monospaced";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   216
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   217
        for (int i=0; i<fcFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   218
            if (fontname.equals(fcFonts[i].jdkName) &&
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   219
                style == fcFonts[i].style) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   220
                return fcFonts[i].allFonts;
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
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   223
        return fcFonts[0].allFonts;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   224
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   225
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   226
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   227
    public CompositeFontDescriptor[] get2DCompositeFontInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   228
3930
738bc2599ca8 6870238: Font2DTest fails on Debian after FontManager refactoring
rkennke
parents: 3928
diff changeset
   229
        X11FontManager fm = (X11FontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   230
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   231
        FcCompFont[] fcCompFonts = fcm.loadFontConfig();
883
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
        CompositeFontDescriptor[] result =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   234
                new CompositeFontDescriptor[NUM_FONTS * NUM_STYLES];
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
        for (int fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   237
            String fontName = publicFontNames[fontIndex];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   238
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   239
            for (int styleIndex = 0; styleIndex < NUM_STYLES; styleIndex++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   240
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   241
                String faceName = fontName + "." + styleNames[styleIndex];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   242
                FontConfigFont[] fcFonts =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   243
                    getFcFontList(fcCompFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   244
                                  fontNames[fontIndex], styleIndex);
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
                int numFonts = fcFonts.length;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   247
                // 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
   248
                if (installedFallbackFontFiles != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   249
                    numFonts += installedFallbackFontFiles.length;
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   252
                String[] fileNames = new String[numFonts];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   253
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   254
                int index;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   255
                for (index = 0; index < fcFonts.length; index++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   256
                    fileNames[index] = fcFonts[index].fontFile;
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
                if (installedFallbackFontFiles != null) {
9461
4fd9dcb3a5d0 7031011: fallbackfont testing failed on OEL 6.
prr
parents: 9035
diff changeset
   260
                    System.arraycopy(installedFallbackFontFiles, 0,
4fd9dcb3a5d0 7031011: fallbackfont testing failed on OEL 6.
prr
parents: 9035
diff changeset
   261
                                     fileNames, fcFonts.length,
4fd9dcb3a5d0 7031011: fallbackfont testing failed on OEL 6.
prr
parents: 9035
diff changeset
   262
                                     installedFallbackFontFiles.length);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   263
                }
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
                result[fontIndex * NUM_STYLES + styleIndex]
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   266
                        = new CompositeFontDescriptor(
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   267
                            faceName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   268
                            1,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   269
                            null,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   270
                            fileNames,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   271
                            null, null);
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
        return result;
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
    /**
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   278
     * 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
   279
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   280
    private String getVersionString(File f){
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   281
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   282
            Scanner sc  = new Scanner(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   283
            return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
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
        catch (Exception e){
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
        return null;
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
    /**
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   291
     * Sets the OS name and version from environment information.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   292
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   293
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   294
    protected void setOsNameAndVersion() {
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
        super.setOsNameAndVersion();
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
        if (!osName.equals("Linux")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   299
            return;
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
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   302
            File f;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   303
            if ((f = new File("/etc/lsb-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   304
                    /* Ubuntu and (perhaps others) use only lsb-release.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   305
                     * Syntax and encoding is compatible with java properties.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   306
                     * For Ubuntu the ID is "Ubuntu".
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
                    Properties props = new Properties();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   309
                    props.load(new FileInputStream(f));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   310
                    osName = props.getProperty("DISTRIB_ID");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   311
                    osVersion =  props.getProperty("DISTRIB_RELEASE");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   312
            } else if ((f = new File("/etc/redhat-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   313
                osName = "RedHat";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   314
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   315
            } else if ((f = new File("/etc/SuSE-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   316
                osName = "SuSE";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   317
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   318
            } else if ((f = new File("/etc/turbolinux-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   319
                osName = "Turbo";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   320
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   321
            } else if ((f = new File("/etc/fedora-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   322
                osName = "Fedora";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   323
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   324
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   325
        } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   326
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   327
                warning("Exception identifying Linux distro.");
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   328
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   329
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   330
    }
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
    private File getFcInfoFile() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   333
        if (fcInfoFileName == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   334
            // 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
   335
            // 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
   336
            // 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
   337
            // 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
   338
            // "localhost"
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   339
            String hostname;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   340
            try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   341
                hostname = InetAddress.getLocalHost().getHostName();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   342
            } catch (UnknownHostException e) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   343
                hostname = "localhost";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   344
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   345
            String userDir = System.getProperty("user.home");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   346
            String version = System.getProperty("java.version");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   347
            String fs = File.separator;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   348
            String dir = userDir+fs+".java"+fs+"fonts"+fs+version;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   349
            String lang = SunToolkit.getStartupLocale().getLanguage();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   350
            String name = "fcinfo-"+fileVersion+"-"+hostname+"-"+
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   351
                osName+"-"+osVersion+"-"+lang+".properties";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   352
            fcInfoFileName = dir+fs+name;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   353
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   354
        return new File(fcInfoFileName);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   355
    }
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
    private void writeFcInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   358
        Properties props = new Properties();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   359
        props.setProperty("version", fileVersion);
3930
738bc2599ca8 6870238: Font2DTest fails on Debian after FontManager refactoring
rkennke
parents: 3928
diff changeset
   360
        X11FontManager fm = (X11FontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   361
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   362
        FontConfigInfo fcInfo = fcm.getFontConfigInfo();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   363
        props.setProperty("fcversion", Integer.toString(fcInfo.fcVersion));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   364
        if (fcInfo.cacheDirs != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   365
            for (int i=0;i<fcInfo.cacheDirs.length;i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   366
                if (fcInfo.cacheDirs[i] != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   367
                   props.setProperty("cachedir."+i,  fcInfo.cacheDirs[i]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   368
                }
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
        for (int i=0; i<fcCompFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   372
            FcCompFont fci = fcCompFonts[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   373
            String styleKey = fci.jdkName+"."+fci.style;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   374
            props.setProperty(styleKey+".length",
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   375
                              Integer.toString(fci.allFonts.length));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   376
            for (int j=0; j<fci.allFonts.length; j++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   377
                props.setProperty(styleKey+"."+j+".family",
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   378
                                  fci.allFonts[j].familyName);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   379
                props.setProperty(styleKey+"."+j+".file",
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   380
                                  fci.allFonts[j].fontFile);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   381
            }
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
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   384
            /* 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
   385
             * 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
   386
             * 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
   387
             */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   388
            File fcInfoFile = getFcInfoFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   389
            File dir = fcInfoFile.getParentFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   390
            dir.mkdirs();
13041
8477cb6992be 7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents: 9461
diff changeset
   391
            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
   392
            FileOutputStream fos = new FileOutputStream(tempFile);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   393
            props.store(fos,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   394
                      "JDK Font Configuration Generated File: *Do Not Edit*");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   395
            fos.close();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   396
            boolean renamed = tempFile.renameTo(fcInfoFile);
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   397
            if (!renamed && FontUtilities.debugFonts()) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   398
                System.out.println("rename failed");
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   399
                warning("Failed renaming file to "+ getFcInfoFile());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   400
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   401
        } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   402
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   403
                warning("IOException writing to "+ getFcInfoFile());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   404
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   405
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   406
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   407
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   408
    /* 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
   409
     * 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
   410
     * 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
   411
     * the system cache.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   412
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   413
    private void readFcInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   414
        File fcFile = getFcInfoFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   415
        if (!fcFile.exists()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   416
            return;
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
        Properties props = new Properties();
3930
738bc2599ca8 6870238: Font2DTest fails on Debian after FontManager refactoring
rkennke
parents: 3928
diff changeset
   419
        X11FontManager fm = (X11FontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   420
        FontConfigManager fcm = fm.getFontConfigManager();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   421
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   422
            FileInputStream fis = new FileInputStream(fcFile);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   423
            props.load(fis);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   424
            fis.close();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   425
        } catch (IOException e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   426
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   427
                warning("IOException reading from "+fcFile.toString());
883
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
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   430
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   431
        String version = (String)props.get("version");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   432
        if (version == null || !version.equals(fileVersion)) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   433
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   434
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   435
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   436
        // 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
   437
        // system, we invalidate our fontconfig file.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   438
        String fcVersionStr = (String)props.get("fcversion");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   439
        if (fcVersionStr != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   440
            int fcVersion;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   441
            try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   442
                fcVersion = Integer.parseInt(fcVersionStr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   443
                if (fcVersion != 0 &&
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 13041
diff changeset
   444
                    fcVersion != FontConfigManager.getFontConfigVersion()) {
883
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
            } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   448
                if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   449
                    warning("Exception parsing version " + fcVersionStr);
883
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
                return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   452
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   453
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   454
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   455
        // 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
   456
        // 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
   457
        // of date then re-generate.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   458
        long lastModified = fcFile.lastModified();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   459
        int cacheDirIndex = 0;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   460
        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
   461
            String dir = (String)props.get("cachedir."+cacheDirIndex);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   462
            if (dir == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   463
                break;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   464
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   465
            File dirFile = new File(dir);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   466
            if (dirFile.exists() && dirFile.lastModified() > lastModified) {
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
            cacheDirIndex++;
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
        String[] names = { "sansserif", "serif", "monospaced" };
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   473
        String[] fcnames = { "sans", "serif", "monospace" };
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   474
        int namesLen = names.length;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   475
        int numStyles = 4;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   476
        FcCompFont[] fci = new FcCompFont[namesLen*numStyles];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   477
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   478
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   479
            for (int i=0; i<namesLen; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   480
                for (int s=0; s<numStyles; s++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   481
                    int index = i*numStyles+s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   482
                    fci[index] = new FcCompFont();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   483
                    String key = names[i]+"."+s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   484
                    fci[index].jdkName = names[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   485
                    fci[index].fcFamily = fcnames[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   486
                    fci[index].style = s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   487
                    String lenStr = (String)props.get(key+".length");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   488
                    int nfonts = Integer.parseInt(lenStr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   489
                    if (nfonts <= 0) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   490
                        return; // bad file
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
                    fci[index].allFonts = new FontConfigFont[nfonts];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   493
                    for (int f=0; f<nfonts; f++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   494
                        fci[index].allFonts[f] = new FontConfigFont();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   495
                        String fkey = key+"."+f+".family";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   496
                        String family = (String)props.get(fkey);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   497
                        fci[index].allFonts[f].familyName = family;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   498
                        fkey = key+"."+f+".file";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   499
                        String file = (String)props.get(fkey);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   500
                        if (file == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   501
                            return; // bad file
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   502
                        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   503
                        fci[index].allFonts[f].fontFile = file;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   504
                    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   505
                    fci[index].firstFont =  fci[index].allFonts[0];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   506
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
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   509
            fcCompFonts = fci;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   510
        } catch (Throwable t) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   511
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   512
                warning(t.toString());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   513
            }
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
    }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   516
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   517
    private static void warning(String msg) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   518
        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
   519
        logger.warning(msg);
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   520
    }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   521
}