jdk/src/solaris/classes/sun/font/FcFontConfiguration.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7948 6711180a6212
child 9461 4fd9dcb3a5d0
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
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
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7948
diff changeset
     2
 * Copyright (c) 2008, 2011, 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;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    36
import java.util.HashMap;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    37
import java.util.HashSet;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    38
import java.util.Properties;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    39
import java.util.Scanner;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    40
import sun.awt.FontConfiguration;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    41
import sun.awt.FontDescriptor;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    42
import sun.awt.SunToolkit;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    43
import sun.awt.X11FontManager;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    44
import sun.font.CompositeFontDescriptor;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    45
import sun.font.FontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    46
import sun.font.FontConfigManager.FontConfigInfo;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    47
import sun.font.FontConfigManager.FcCompFont;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    48
import sun.font.FontConfigManager.FontConfigFont;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    49
import sun.java2d.SunGraphicsEnvironment;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
    50
import sun.util.logging.PlatformLogger;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    51
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    52
public class FcFontConfiguration extends FontConfiguration {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    53
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    54
    /** Version of the cache file format understood by this code.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    55
     * Its part of the file name so that we can rev this at
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    56
     * any time, even in a minor JDK update.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    57
     * It is stored as the value of the "version" property.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    58
     * This is distinct from the version of "libfontconfig" that generated
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    59
     * the cached results, and which is the "fcversion" property in the file.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    60
     * {@code FontConfiguration.getVersion()} also returns a version string,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    61
     * and has meant the version of the fontconfiguration.properties file
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    62
     * that was read. Since this class doesn't use such files, then what
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    63
     * that really means is whether the methods on this class return
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    64
     * values that are compatible with the classes that do directly read
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    65
     * from such files. It is a compatible subset of version "1".
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    66
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    67
    private static final String fileVersion = "1";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    68
    private String fcInfoFileName = null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    69
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    70
    private FcCompFont[] fcCompFonts = null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    71
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    72
    public FcFontConfiguration(SunFontManager fm) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    73
        super(fm);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    74
        init();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    75
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    76
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    77
    /* This isn't called but is needed to satisfy super-class contract. */
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    78
    public FcFontConfiguration(SunFontManager fm,
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    79
                               boolean preferLocaleFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    80
                               boolean preferPropFonts) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    81
        super(fm, preferLocaleFonts, preferPropFonts);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    82
        init();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    83
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    84
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    85
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    86
    public synchronized boolean init() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    87
        if (fcCompFonts != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    88
            return true;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    89
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    90
2372
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 883
diff changeset
    91
        setFontConfiguration();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    92
        readFcInfo();
3930
738bc2599ca8 6870238: Font2DTest fails on Debian after FontManager refactoring
rkennke
parents: 3928
diff changeset
    93
        X11FontManager fm = (X11FontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    94
        FontConfigManager fcm = fm.getFontConfigManager();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    95
        if (fcCompFonts == null) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
    96
            fcCompFonts = fcm.loadFontConfig();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    97
            if (fcCompFonts != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    98
                try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
    99
                    writeFcInfo();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   100
                } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   101
                    if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   102
                        warning("Exception writing fcInfo " + e);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   103
                    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   104
                }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   105
            } else if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   106
                warning("Failed to get info from libfontconfig");
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   107
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   108
        } else {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   109
            fcm.populateFontConfig(fcCompFonts);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   110
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   111
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   112
        if (fcCompFonts == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   113
            return false; // couldn't load fontconfig.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   114
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   115
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   116
        // NB already in a privileged block from SGE
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   117
        String javaHome = System.getProperty("java.home");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   118
        if (javaHome == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   119
            throw new Error("java.home property not set");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   120
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   121
        String javaLib = javaHome + File.separator + "lib";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   122
        getInstalledFallbackFonts(javaLib);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   123
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   124
        return true;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   125
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   126
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   127
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   128
    public String getFallbackFamilyName(String fontName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   129
                                        String defaultFallback) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   130
        // maintain compatibility with old font.properties files, which either
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   131
        // had aliases for TimesRoman & Co. or defined mappings for them.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   132
        String compatibilityName = getCompatibilityFamilyName(fontName);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   133
        if (compatibilityName != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   134
            return compatibilityName;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   135
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   136
        return defaultFallback;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   137
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   138
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   139
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   140
    protected String
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   141
        getFaceNameFromComponentFontName(String componentFontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   142
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   143
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   144
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   145
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   146
    protected String
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   147
        getFileNameFromComponentFontName(String componentFontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   148
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   149
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   150
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   151
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   152
    public String getFileNameFromPlatformName(String platformName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   153
        /* Platform name is the file name, but rather than returning
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   154
         * the arg, return null*/
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   155
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   156
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   157
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   158
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   159
    protected Charset getDefaultFontCharset(String fontName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   160
        return Charset.forName("ISO8859_1");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   161
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   162
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   163
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   164
    protected String getEncoding(String awtFontName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   165
                                 String characterSubsetName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   166
        return "default";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   167
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   168
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   169
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   170
    protected void initReorderMap() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   171
        reorderMap = new HashMap();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   172
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   173
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   174
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   175
    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
   176
        return new FontDescriptor[0];
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   177
    }
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
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   180
    public int getNumberCoreFonts() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   181
        return 1;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   182
    }
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
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   185
    public String[] getPlatformFontNames() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   186
        HashSet<String> nameSet = new HashSet<String>();
3930
738bc2599ca8 6870238: Font2DTest fails on Debian after FontManager refactoring
rkennke
parents: 3928
diff changeset
   187
        X11FontManager fm = (X11FontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   188
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   189
        FcCompFont[] fcCompFonts = fcm.loadFontConfig();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   190
        for (int i=0; i<fcCompFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   191
            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
   192
                nameSet.add(fcCompFonts[i].allFonts[j].fontFile);
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
        return nameSet.toArray(new String[0]);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   196
    }
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
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   199
    public String getExtraFontPath() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   200
        return null;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   201
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   202
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   203
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   204
    public boolean needToSearchForFile(String fileName) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   205
        return false;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   206
    }
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
    private FontConfigFont[] getFcFontList(FcCompFont[] fcFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   209
                                           String fontname, int style) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   210
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   211
        if (fontname.equals("dialog")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   212
            fontname = "sansserif";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   213
        } else if (fontname.equals("dialoginput")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   214
            fontname = "monospaced";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   215
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   216
        for (int i=0; i<fcFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   217
            if (fontname.equals(fcFonts[i].jdkName) &&
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   218
                style == fcFonts[i].style) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   219
                return fcFonts[i].allFonts;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   220
            }
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
        return fcFonts[0].allFonts;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   223
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   224
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   225
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   226
    public CompositeFontDescriptor[] get2DCompositeFontInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   227
3930
738bc2599ca8 6870238: Font2DTest fails on Debian after FontManager refactoring
rkennke
parents: 3928
diff changeset
   228
        X11FontManager fm = (X11FontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   229
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   230
        FcCompFont[] fcCompFonts = fcm.loadFontConfig();
883
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
        CompositeFontDescriptor[] result =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   233
                new CompositeFontDescriptor[NUM_FONTS * NUM_STYLES];
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
        for (int fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   236
            String fontName = publicFontNames[fontIndex];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   237
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   238
            for (int styleIndex = 0; styleIndex < NUM_STYLES; styleIndex++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   239
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   240
                String faceName = fontName + "." + styleNames[styleIndex];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   241
                FontConfigFont[] fcFonts =
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   242
                    getFcFontList(fcCompFonts,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   243
                                  fontNames[fontIndex], styleIndex);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   244
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   245
                int numFonts = fcFonts.length;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   246
                // 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
   247
                if (installedFallbackFontFiles != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   248
                    numFonts += installedFallbackFontFiles.length;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   249
                }
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[] fileNames = new String[numFonts];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   252
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   253
                int index;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   254
                for (index = 0; index < fcFonts.length; index++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   255
                    fileNames[index] = fcFonts[index].fontFile;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   256
                }
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
                if (installedFallbackFontFiles != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   259
                    System.arraycopy(fileNames, index,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   260
                                     installedFallbackFontFiles,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   261
                                     0, installedFallbackFontFiles.length);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   262
                }
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
                result[fontIndex * NUM_STYLES + styleIndex]
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   265
                        = new CompositeFontDescriptor(
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   266
                            faceName,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   267
                            1,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   268
                            null,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   269
                            fileNames,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   270
                            null, null);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   271
            }
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
        return result;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   274
    }
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
     * 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
   278
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   279
    private String getVersionString(File f){
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   280
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   281
            Scanner sc  = new Scanner(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   282
            return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   283
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   284
        catch (Exception e){
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 null;
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
     * Sets the OS name and version from environment information.
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
    @Override
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   293
    protected void setOsNameAndVersion() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   294
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   295
        super.setOsNameAndVersion();
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
        if (!osName.equals("Linux")) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   298
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   299
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   300
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   301
            File f;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   302
            if ((f = new File("/etc/lsb-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   303
                    /* Ubuntu and (perhaps others) use only lsb-release.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   304
                     * Syntax and encoding is compatible with java properties.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   305
                     * For Ubuntu the ID is "Ubuntu".
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   306
                     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   307
                    Properties props = new Properties();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   308
                    props.load(new FileInputStream(f));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   309
                    osName = props.getProperty("DISTRIB_ID");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   310
                    osVersion =  props.getProperty("DISTRIB_RELEASE");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   311
            } else if ((f = new File("/etc/redhat-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   312
                osName = "RedHat";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   313
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   314
            } else if ((f = new File("/etc/SuSE-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   315
                osName = "SuSE";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   316
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   317
            } else if ((f = new File("/etc/turbolinux-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   318
                osName = "Turbo";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   319
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   320
            } else if ((f = new File("/etc/fedora-release")).canRead()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   321
                osName = "Fedora";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   322
                osVersion = getVersionString(f);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   323
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   324
        } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   325
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   326
                warning("Exception identifying Linux distro.");
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   327
            }
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
    private File getFcInfoFile() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   332
        if (fcInfoFileName == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   333
            // 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
   334
            // 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
   335
            // 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
   336
            // 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
   337
            // "localhost"
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   338
            String hostname;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   339
            try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   340
                hostname = InetAddress.getLocalHost().getHostName();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   341
            } catch (UnknownHostException e) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   342
                hostname = "localhost";
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
            String userDir = System.getProperty("user.home");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   345
            String version = System.getProperty("java.version");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   346
            String fs = File.separator;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   347
            String dir = userDir+fs+".java"+fs+"fonts"+fs+version;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   348
            String lang = SunToolkit.getStartupLocale().getLanguage();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   349
            String name = "fcinfo-"+fileVersion+"-"+hostname+"-"+
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   350
                osName+"-"+osVersion+"-"+lang+".properties";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   351
            fcInfoFileName = dir+fs+name;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   352
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   353
        return new File(fcInfoFileName);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   354
    }
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
    private void writeFcInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   357
        Properties props = new Properties();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   358
        props.setProperty("version", fileVersion);
3930
738bc2599ca8 6870238: Font2DTest fails on Debian after FontManager refactoring
rkennke
parents: 3928
diff changeset
   359
        X11FontManager fm = (X11FontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   360
        FontConfigManager fcm = fm.getFontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   361
        FontConfigInfo fcInfo = fcm.getFontConfigInfo();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   362
        props.setProperty("fcversion", Integer.toString(fcInfo.fcVersion));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   363
        if (fcInfo.cacheDirs != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   364
            for (int i=0;i<fcInfo.cacheDirs.length;i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   365
                if (fcInfo.cacheDirs[i] != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   366
                   props.setProperty("cachedir."+i,  fcInfo.cacheDirs[i]);
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
            }
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
        for (int i=0; i<fcCompFonts.length; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   371
            FcCompFont fci = fcCompFonts[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   372
            String styleKey = fci.jdkName+"."+fci.style;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   373
            props.setProperty(styleKey+".length",
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   374
                              Integer.toString(fci.allFonts.length));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   375
            for (int j=0; j<fci.allFonts.length; j++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   376
                props.setProperty(styleKey+"."+j+".family",
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   377
                                  fci.allFonts[j].familyName);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   378
                props.setProperty(styleKey+"."+j+".file",
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   379
                                  fci.allFonts[j].fontFile);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   380
            }
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
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   383
            /* 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
   384
             * 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
   385
             * 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
   386
             */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   387
            File fcInfoFile = getFcInfoFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   388
            File dir = fcInfoFile.getParentFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   389
            dir.mkdirs();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   390
            File tempFile = File.createTempFile("fcinfo", null, dir);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   391
            FileOutputStream fos = new FileOutputStream(tempFile);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   392
            props.store(fos,
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   393
                      "JDK Font Configuration Generated File: *Do Not Edit*");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   394
            fos.close();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   395
            boolean renamed = tempFile.renameTo(fcInfoFile);
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   396
            if (!renamed && FontUtilities.debugFonts()) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   397
                System.out.println("rename failed");
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   398
                warning("Failed renaming file to "+ getFcInfoFile());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   399
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   400
        } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   401
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   402
                warning("IOException writing to "+ getFcInfoFile());
883
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
        }
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
    /* 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
   408
     * 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
   409
     * 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
   410
     * the system cache.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   411
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   412
    private void readFcInfo() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   413
        File fcFile = getFcInfoFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   414
        if (!fcFile.exists()) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   415
            return;
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
        Properties props = new Properties();
3930
738bc2599ca8 6870238: Font2DTest fails on Debian after FontManager refactoring
rkennke
parents: 3928
diff changeset
   418
        X11FontManager fm = (X11FontManager) fontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   419
        FontConfigManager fcm = fm.getFontConfigManager();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   420
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   421
            FileInputStream fis = new FileInputStream(fcFile);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   422
            props.load(fis);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   423
            fis.close();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   424
        } catch (IOException e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   425
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   426
                warning("IOException reading from "+fcFile.toString());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   427
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   428
            return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   429
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   430
        String version = (String)props.get("version");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   431
        if (version == null || !version.equals(fileVersion)) {
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
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   435
        // 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
   436
        // system, we invalidate our fontconfig file.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   437
        String fcVersionStr = (String)props.get("fcversion");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   438
        if (fcVersionStr != null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   439
            int fcVersion;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   440
            try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   441
                fcVersion = Integer.parseInt(fcVersionStr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   442
                if (fcVersion != 0 &&
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   443
                    fcVersion != fcm.getFontConfigVersion()) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   444
                    return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   445
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   446
            } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   447
                if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   448
                    warning("Exception parsing version " + fcVersionStr);
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   449
                }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   450
                return;
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
        }
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
        // 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
   455
        // 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
   456
        // of date then re-generate.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   457
        long lastModified = fcFile.lastModified();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   458
        int cacheDirIndex = 0;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   459
        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
   460
            String dir = (String)props.get("cachedir."+cacheDirIndex);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   461
            if (dir == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   462
                break;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   463
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   464
            File dirFile = new File(dir);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   465
            if (dirFile.exists() && dirFile.lastModified() > lastModified) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   466
                return;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   467
            }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   468
            cacheDirIndex++;
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
        String[] names = { "sansserif", "serif", "monospaced" };
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   472
        String[] fcnames = { "sans", "serif", "monospace" };
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   473
        int namesLen = names.length;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   474
        int numStyles = 4;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   475
        FcCompFont[] fci = new FcCompFont[namesLen*numStyles];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   476
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   477
        try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   478
            for (int i=0; i<namesLen; i++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   479
                for (int s=0; s<numStyles; s++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   480
                    int index = i*numStyles+s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   481
                    fci[index] = new FcCompFont();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   482
                    String key = names[i]+"."+s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   483
                    fci[index].jdkName = names[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   484
                    fci[index].fcFamily = fcnames[i];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   485
                    fci[index].style = s;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   486
                    String lenStr = (String)props.get(key+".length");
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   487
                    int nfonts = Integer.parseInt(lenStr);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   488
                    if (nfonts <= 0) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   489
                        return; // bad file
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   490
                    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   491
                    fci[index].allFonts = new FontConfigFont[nfonts];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   492
                    for (int f=0; f<nfonts; f++) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   493
                        fci[index].allFonts[f] = new FontConfigFont();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   494
                        String fkey = key+"."+f+".family";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   495
                        String family = (String)props.get(fkey);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   496
                        fci[index].allFonts[f].familyName = family;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   497
                        fkey = key+"."+f+".file";
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   498
                        String file = (String)props.get(fkey);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   499
                        if (file == null) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   500
                            return; // bad file
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   501
                        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   502
                        fci[index].allFonts[f].fontFile = file;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   503
                    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   504
                    fci[index].firstFont =  fci[index].allFonts[0];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   505
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
            fcCompFonts = fci;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   509
        } catch (Throwable t) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2374
diff changeset
   510
            if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   511
                warning(t.toString());
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   512
            }
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
    }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   515
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   516
    private static void warning(String msg) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   517
        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
   518
        logger.warning(msg);
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3930
diff changeset
   519
    }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
diff changeset
   520
}