jdk/src/share/classes/sun/awt/FontConfiguration.java
author denis
Wed, 27 Mar 2013 16:19:51 +0400
changeset 16705 1caaa379eded
parent 12811 859419a97d2b
child 21278 ef8a3a2a72f2
permissions -rw-r--r--
7075105: WIN: Provide a way to format HTML on drop Reviewed-by: uta, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10406
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
     2
 * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
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
2
90ce3da70b43 Initial load
duke
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.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
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.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.DataInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.DataOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.nio.charset.CharsetEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.PrivilegedAction;
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
    40
import java.util.Arrays;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.Map.Entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.font.CompositeFontDescriptor;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
    50
import sun.font.SunFontManager;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
    51
import sun.font.FontManagerFactory;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
    52
import sun.font.FontUtilities;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    53
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Provides the definitions of the five logical fonts: Serif, SansSerif,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * Monospaced, Dialog, and DialogInput. The necessary information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * is obtained from fontconfig files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public abstract class FontConfiguration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    //static global runtime env
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected static String osVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected static String osName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected static String encoding; // canonical name of default nio charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected static Locale startupLocale = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected static Hashtable localeMap = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static FontConfiguration fontConfig;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    69
    private static PlatformLogger logger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected static boolean isProperties = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
    72
    protected SunFontManager fontManager;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected boolean preferLocaleFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected boolean preferPropFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
    76
    private File fontConfigFile;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
    77
    private boolean foundOsSpecificFile;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
    78
    private boolean inited;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
    79
    private String javaLib;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
    80
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /* A default FontConfiguration must be created before an alternate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * one to ensure proper static initialisation takes place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
    84
    public FontConfiguration(SunFontManager fm) {
8945
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 7777
diff changeset
    85
        if (FontUtilities.debugFonts()) {
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 7777
diff changeset
    86
            FontUtilities.getLogger()
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 7777
diff changeset
    87
                .info("Creating standard Font Configuration");
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 7777
diff changeset
    88
        }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
    89
        if (FontUtilities.debugFonts() && logger == null) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    90
            logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
    92
        fontManager = fm;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        setOsNameAndVersion();  /* static initialization */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        setEncoding();          /* static initialization */
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
    95
        /* Separating out the file location from the rest of the
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
    96
         * initialisation, so the caller has the option of doing
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
    97
         * something else if a suitable file isn't found.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
    98
         */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
    99
        findFontConfigFile();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   100
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   102
    public synchronized boolean init() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   103
        if (!inited) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   104
            this.preferLocaleFonts = false;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   105
            this.preferPropFonts = false;
2372
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 889
diff changeset
   106
            setFontConfiguration();
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   107
            readFontConfigFile(fontConfigFile);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   108
            initFontConfig();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   109
            inited = true;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   110
        }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   111
        return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
   114
    public FontConfiguration(SunFontManager fm,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                             boolean preferLocaleFonts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                             boolean preferPropFonts) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
   117
        fontManager = fm;
8945
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 7777
diff changeset
   118
        if (FontUtilities.debugFonts()) {
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 7777
diff changeset
   119
            FontUtilities.getLogger()
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 7777
diff changeset
   120
                .info("Creating alternate Font Configuration");
4718885476ee 7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents: 7777
diff changeset
   121
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.preferLocaleFonts = preferLocaleFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this.preferPropFonts = preferPropFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        /* fontConfig should be initialised by default constructor, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         * its data tables can be shared, since readFontConfigFile doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         * update any other state. Also avoid a doPrivileged block.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        initFontConfig();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Fills in this instance's osVersion and osName members. By
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * default uses the system properties os.name and os.version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * subclasses may override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    protected void setOsNameAndVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        osName = System.getProperty("os.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        osVersion = System.getProperty("os.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private void setEncoding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        encoding = Charset.defaultCharset().name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        startupLocale = SunToolkit.getStartupLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    // methods for loading the FontConfig file                         //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /////////////////////////////////////////////////////////////////////
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   149
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   150
    public boolean foundOsSpecificFile() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   151
        return foundOsSpecificFile;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   152
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   153
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   154
    /* Smoke test to see if we can trust this configuration by testing if
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   155
     * the first slot of a composite font maps to an installed file.
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   156
     */
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   157
    public boolean fontFilesArePresent() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   158
        init();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   159
        short fontNameID = compFontNameIDs[0][0][0];
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   160
        short fileNameID = getComponentFileID(fontNameID);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   161
        final String fileName = mapFileName(getComponentFileName(fileNameID));
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   162
        Boolean exists = (Boolean)java.security.AccessController.doPrivileged(
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   163
            new java.security.PrivilegedAction() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   164
                 public Object run() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   165
                     try {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   166
                         File f = new File(fileName);
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   167
                         return Boolean.valueOf(f.exists());
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   168
                     }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   169
                     catch (Exception e) {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   170
                         return false;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   171
                     }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   172
                 }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   173
                });
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   174
        return exists.booleanValue();
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   175
    }
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   176
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   177
    private void findFontConfigFile() {
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   178
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   179
        foundOsSpecificFile = true; // default assumption.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        String javaHome = System.getProperty("java.home");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (javaHome == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            throw new Error("java.home property not set");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   184
        javaLib = javaHome + File.separator + "lib";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        String userConfigFile = System.getProperty("sun.awt.fontconfig");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (userConfigFile != null) {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   187
            fontConfigFile = new File(userConfigFile);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        } else {
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   189
            fontConfigFile = findFontConfigFile(javaLib);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   191
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   193
    private void readFontConfigFile(File f) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        /* This is invoked here as readFontConfigFile is only invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         * once per VM, and always in a privileged context, thus the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         * directory containing installed fall back fonts is accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         * from this context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        getInstalledFallbackFonts(javaLib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                FileInputStream in = new FileInputStream(f.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                if (isProperties) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    loadProperties(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    loadBinary(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                in.close();
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
   210
                if (FontUtilities.debugFonts()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    logger.config("Read logical font configuration from " + f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            } catch (IOException e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
   214
                if (FontUtilities.debugFonts()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    logger.config("Failed to read logical font configuration from " + f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        String version = getVersion();
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
   220
        if (!"1".equals(version) && FontUtilities.debugFonts()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            logger.config("Unsupported fontconfig version: " + version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   225
    protected void getInstalledFallbackFonts(String javaLib) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        String fallbackDirName = javaLib + File.separator +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            "fonts" + File.separator + "fallback";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        File fallbackDir = new File(fallbackDirName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (fallbackDir.exists() && fallbackDir.isDirectory()) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
   231
            String[] ttfs = fallbackDir.list(fontManager.getTrueTypeFilter());
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
   232
            String[] t1s = fallbackDir.list(fontManager.getType1Filter());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            int numTTFs = (ttfs == null) ? 0 : ttfs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            int numT1s = (t1s == null) ? 0 : t1s.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            int len = numTTFs + numT1s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (numTTFs + numT1s == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            installedFallbackFontFiles = new String[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            for (int i=0; i<numTTFs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                installedFallbackFontFiles[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    fallbackDir + File.separator + ttfs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            for (int i=0; i<numT1s; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                installedFallbackFontFiles[i+numTTFs] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    fallbackDir + File.separator + t1s[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
   248
            fontManager.registerFontsInDir(fallbackDirName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private File findImpl(String fname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        File f = new File(fname + ".properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (f.canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            isProperties = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        f = new File(fname + ".bfc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (f.canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            isProperties = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private File findFontConfigFile(String javaLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        String baseName = javaLib + File.separator + "fontconfig";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        File configFile;
10406
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   269
        String osMajorVersion = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (osVersion != null && osName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            configFile = findImpl(baseName + "." + osName + "." + osVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            if (configFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                return configFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
10406
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   275
            int decimalPointIndex = osVersion.indexOf(".");
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   276
            if (decimalPointIndex != -1) {
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   277
                osMajorVersion = osVersion.substring(0, osVersion.indexOf("."));
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   278
                configFile = findImpl(baseName + "." + osName + "." + osMajorVersion);
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   279
                if (configFile != null) {
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   280
                    return configFile;
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   281
                }
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   282
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (osName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            configFile = findImpl(baseName + "." + osName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            if (configFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                return configFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (osVersion != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            configFile = findImpl(baseName + "." + osVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (configFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                return configFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
10406
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   295
            if (osMajorVersion != null) {
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   296
                configFile = findImpl(baseName + "." + osMajorVersion);
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   297
                if (configFile != null) {
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   298
                    return configFile;
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   299
                }
70c2151d530b 7074386: fallback to fontconfig.<major_version>.bfc/properties if fontconfig.<major_version>.<minor_version>.
dbuck
parents: 8945
diff changeset
   300
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   302
        foundOsSpecificFile = false;
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   303
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        configFile = findImpl(baseName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (configFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            return configFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /* Initialize the internal data tables from binary format font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * configuration file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public static void loadBinary(InputStream inStream) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        DataInputStream in = new DataInputStream(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        head = readShortTable(in, HEAD_LENGTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        int[] tableSizes = new int[INDEX_TABLEEND];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        for (int i = 0; i < INDEX_TABLEEND; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            tableSizes[i] = head[i + 1] - head[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        table_scriptIDs       = readShortTable(in, tableSizes[INDEX_scriptIDs]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        table_scriptFonts     = readShortTable(in, tableSizes[INDEX_scriptFonts]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        table_elcIDs          = readShortTable(in, tableSizes[INDEX_elcIDs]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        table_sequences        = readShortTable(in, tableSizes[INDEX_sequences]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        table_fontfileNameIDs = readShortTable(in, tableSizes[INDEX_fontfileNameIDs]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        table_componentFontNameIDs = readShortTable(in, tableSizes[INDEX_componentFontNameIDs]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        table_filenames       = readShortTable(in, tableSizes[INDEX_filenames]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        table_awtfontpaths    = readShortTable(in, tableSizes[INDEX_awtfontpaths]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        table_exclusions      = readShortTable(in, tableSizes[INDEX_exclusions]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        table_proportionals   = readShortTable(in, tableSizes[INDEX_proportionals]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        table_scriptFontsMotif   = readShortTable(in, tableSizes[INDEX_scriptFontsMotif]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        table_alphabeticSuffix   = readShortTable(in, tableSizes[INDEX_alphabeticSuffix]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        table_stringIDs       = readShortTable(in, tableSizes[INDEX_stringIDs]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        //StringTable cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        stringCache = new String[table_stringIDs.length + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        int len = tableSizes[INDEX_stringTable];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        byte[] bb = new byte[len * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        table_stringTable = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        in.read(bb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        int i = 0, j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        while (i < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
           table_stringTable[i++] = (char)(bb[j++] << 8 | (bb[j++] & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            dump();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /* Generate a binary format font configuration from internal data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * tables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public static void saveBinary(OutputStream out) throws IOException {
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
   355
        sanityCheck();
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
   356
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        DataOutputStream dataOut = new DataOutputStream(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        writeShortTable(dataOut, head);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        writeShortTable(dataOut, table_scriptIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        writeShortTable(dataOut, table_scriptFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        writeShortTable(dataOut, table_elcIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        writeShortTable(dataOut, table_sequences);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        writeShortTable(dataOut, table_fontfileNameIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        writeShortTable(dataOut, table_componentFontNameIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        writeShortTable(dataOut, table_filenames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        writeShortTable(dataOut, table_awtfontpaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        writeShortTable(dataOut, table_exclusions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        writeShortTable(dataOut, table_proportionals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        writeShortTable(dataOut, table_scriptFontsMotif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        writeShortTable(dataOut, table_alphabeticSuffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        writeShortTable(dataOut, table_stringIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        //stringTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        dataOut.writeChars(new String(table_stringTable));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            dump();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    //private static boolean loadingProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    private static short stringIDNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    private static short[] stringIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    private static StringBuilder stringTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public static void loadProperties(InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        //loadingProperties = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        //StringID starts from "1", "0" is reserved for "not defined"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        stringIDNum = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        stringIDs = new short[1000];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        stringTable = new StringBuilder(4096);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (verbose && logger == null) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   393
            logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        new PropertiesHandler().load(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        //loadingProperties = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        stringIDs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        stringTable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    // methods for initializing the FontConfig                         //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *  set initLocale, initEncoding and initELC for this FontConfig object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *  currently we just simply use the startup locale and encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    private void initFontConfig() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        initLocale = startupLocale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        initEncoding = encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (preferLocaleFonts && !willReorderForStartupLocale()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            preferLocaleFonts = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        initELC = getInitELC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        initAllComponentFonts();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    //"ELC" stands for "Encoding.Language.Country". This method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    //the ID of the matched elc setting of "initLocale" in elcIDs table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    //If no match is found, it returns the default ID, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    //"NULL.NULL.NULL" in elcIDs table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    private short getInitELC() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (initELC != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            return initELC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        HashMap <String, Integer> elcIDs = new HashMap<String, Integer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        for (int i = 0; i < table_elcIDs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            elcIDs.put(getString(table_elcIDs[i]), i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        String language = initLocale.getLanguage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        String country = initLocale.getCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        String elc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (elcIDs.containsKey(elc=initEncoding + "." + language + "." + country)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            || elcIDs.containsKey(elc=initEncoding + "." + language)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            || elcIDs.containsKey(elc=initEncoding)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            initELC = elcIDs.get(elc).shortValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            initELC = elcIDs.get("NULL.NULL.NULL").shortValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        while (i < table_alphabeticSuffix.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            if (initELC == table_alphabeticSuffix[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                alphabeticSuffix = getString(table_alphabeticSuffix[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                return initELC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            i += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return initELC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public static boolean verbose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    private short    initELC = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    private Locale   initLocale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    private String   initEncoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    private String   alphabeticSuffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    private short[][][] compFontNameIDs = new short[NUM_FONTS][NUM_STYLES][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    private int[][][] compExclusions = new int[NUM_FONTS][][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    private int[] compCoreNum = new int[NUM_FONTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    private Set<Short> coreFontNameIDs = new HashSet<Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    private Set<Short> fallbackFontNameIDs = new HashSet<Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    private void initAllComponentFonts() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        short[] fallbackScripts = getFallbackScripts();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        for (int fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            short[] coreScripts = getCoreScripts(fontIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            compCoreNum[fontIndex] = coreScripts.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            System.out.println("coreScriptID=" + table_sequences[initELC * 5 + fontIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            for (int i = 0; i < coreScripts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            System.out.println("  " + i + " :" + getString(table_scriptIDs[coreScripts[i]]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            //init exclusionRanges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            int[][] exclusions = new int[coreScripts.length][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            for (int i = 0; i < coreScripts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                exclusions[i] = getExclusionRanges(coreScripts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            compExclusions[fontIndex] = exclusions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            //init componentFontNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            for (int styleIndex = 0; styleIndex < NUM_STYLES; styleIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                short[] nameIDs = new short[coreScripts.length + fallbackScripts.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                //core
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                for (index = 0; index < coreScripts.length; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    nameIDs[index] = getComponentFontID(coreScripts[index],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                               fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    if (preferLocaleFonts && localeMap != null &&
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
   493
                            fontManager.usingAlternateFontforJALocales()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        nameIDs[index] = remapLocaleMap(fontIndex, styleIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                                        coreScripts[index], nameIDs[index]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                    if (preferPropFonts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                        nameIDs[index] = remapProportional(fontIndex, nameIDs[index]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    //System.out.println("nameid=" + nameIDs[index]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    coreFontNameIDs.add(nameIDs[index]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                //fallback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                for (int i = 0; i < fallbackScripts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                    short id = getComponentFontID(fallbackScripts[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                                               fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    if (preferLocaleFonts && localeMap != null &&
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
   508
                            fontManager.usingAlternateFontforJALocales()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                        id = remapLocaleMap(fontIndex, styleIndex, fallbackScripts[i], id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    if (preferPropFonts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                        id = remapProportional(fontIndex, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    if (contains(nameIDs, id, index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                      System.out.println("fontIndex=" + fontIndex + ", styleIndex=" + styleIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                           + ", fbIndex=" + i + ",fbS=" + fallbackScripts[i] + ", id=" + id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    fallbackFontNameIDs.add(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    nameIDs[index++] = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                if (index < nameIDs.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    short[] newNameIDs = new short[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    System.arraycopy(nameIDs, 0, newNameIDs, 0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    nameIDs = newNameIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                compFontNameIDs[fontIndex][styleIndex] = nameIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
   private short remapLocaleMap(int fontIndex, int styleIndex, short scriptID, short fontID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        String scriptName = getString(table_scriptIDs[scriptID]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        String value = (String)localeMap.get(scriptName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            String fontName = fontNames[fontIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            String styleName = styleNames[styleIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            value = (String)localeMap.get(fontName + "." + styleName + "." + scriptName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            return fontID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        for (int i = 0; i < table_componentFontNameIDs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            String name = getString(table_componentFontNameIDs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            if (value.equalsIgnoreCase(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                fontID = (short)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return fontID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    public static boolean hasMonoToPropMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        return table_proportionals != null && table_proportionals.length != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    private short remapProportional(int fontIndex, short id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    if (preferPropFonts &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        table_proportionals.length != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        fontIndex != 2 &&         //"monospaced"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        fontIndex != 4) {         //"dialoginput"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            while (i < table_proportionals.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                if (table_proportionals[i] == id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                    return table_proportionals[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                i += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    /////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    // Methods for handling font and style names                       //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    /////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    protected static final int NUM_FONTS = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    protected static final int NUM_STYLES = 4;
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   582
    protected static final String[] fontNames
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            = {"serif", "sansserif", "monospaced", "dialog", "dialoginput"};
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   584
    protected static final String[] publicFontNames
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            = {Font.SERIF, Font.SANS_SERIF, Font.MONOSPACED, Font.DIALOG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
               Font.DIALOG_INPUT};
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   587
    protected static final String[] styleNames
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            = {"plain", "bold", "italic", "bolditalic"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * Checks whether the given font family name is a valid logical font name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * The check is case insensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    public static boolean isLogicalFontFamilyName(String fontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        return isLogicalFontFamilyNameLC(fontName.toLowerCase(Locale.ENGLISH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Checks whether the given font family name is a valid logical font name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * The check is case sensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public static boolean isLogicalFontFamilyNameLC(String fontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        for (int i = 0; i < fontNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            if (fontName.equals(fontNames[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Checks whether the given style name is a valid logical font style name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    private static boolean isLogicalFontStyleName(String styleName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        for (int i = 0; i < styleNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            if (styleName.equals(styleNames[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Checks whether the given font face name is a valid logical font name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * The check is case insensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    public static boolean isLogicalFontFaceName(String fontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        return isLogicalFontFaceNameLC(fontName.toLowerCase(Locale.ENGLISH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    * Checks whether the given font face name is a valid logical font name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    * The check is case sensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    public static boolean isLogicalFontFaceNameLC(String fontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        int period = fontName.indexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        if (period >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            String familyName = fontName.substring(0, period);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            String styleName = fontName.substring(period + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            return isLogicalFontFamilyName(familyName) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    isLogicalFontStyleName(styleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            return isLogicalFontFamilyName(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    protected static int getFontIndex(String fontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        return getArrayIndex(fontNames, fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    protected static int getStyleIndex(String styleName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        return getArrayIndex(styleNames, styleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    private static int getArrayIndex(String[] names, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        for (int i = 0; i < names.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            if (name.equals(names[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    protected static int getStyleIndex(int style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        switch (style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            case Font.PLAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            case Font.BOLD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            case Font.ITALIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            case Font.BOLD | Font.ITALIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                return 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    protected static String getFontName(int fontIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        return fontNames[fontIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    protected static String getStyleName(int styleIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        return styleNames[styleIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * Returns the font face name for the given logical font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * family name and style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * The style argument is interpreted as in java.awt.Font.Font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    public static String getLogicalFontFaceName(String familyName, int style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        assert isLogicalFontFamilyName(familyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        return familyName.toLowerCase(Locale.ENGLISH) + "." + getStyleString(style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Returns the string typically used in properties files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * for the given style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * The style argument is interpreted as in java.awt.Font.Font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    public static String getStyleString(int style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        return getStyleName(getStyleIndex(style));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * Returns a fallback name for the given font name. For a few known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * font names, matching logical font names are returned. For all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * other font names, defaultFallback is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * defaultFallback differs between AWT and 2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    public abstract String getFallbackFamilyName(String fontName, String defaultFallback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * Returns the 1.1 equivalent for some old 1.0 font family names for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * which we need to maintain compatibility in some configurations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * Returns null for other font names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    protected String getCompatibilityFamilyName(String fontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        fontName = fontName.toLowerCase(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        if (fontName.equals("timesroman")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            return "serif";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        } else if (fontName.equals("helvetica")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            return "sansserif";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        } else if (fontName.equals("courier")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            return "monospaced";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
883
c3e81f0acd3d 6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents: 438
diff changeset
   732
    protected static String[] installedFallbackFontFiles = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * Maps a file name given in the font configuration file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * to a format appropriate for the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    protected String mapFileName(String fileName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    //////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    //  reordering                                                      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    //////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    /* Mappings from file encoding to font config name for font supporting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * the corresponding language. This is filled in by initReorderMap()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    protected HashMap reorderMap = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    /* Platform-specific mappings */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    protected abstract void initReorderMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    /* Move item at index "src" to "dst", shuffling all values in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * between down
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    private void shuffle(String[] seq, int src, int dst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        if (dst >= src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        String tmp = seq[src];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        for (int i=src; i>dst; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            seq[i] = seq[i-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        seq[dst] = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    /* Called to determine if there's a re-order sequence for this locale/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * encoding. If there's none then the caller can "bail" and avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * unnecessary work
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    public static boolean willReorderForStartupLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        return getReorderSequence() != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    private static Object getReorderSequence() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        if (fontConfig.reorderMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
             fontConfig.initReorderMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        HashMap reorderMap = fontConfig.reorderMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        /* Find the most specific mapping */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        String language = startupLocale.getLanguage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        String country = startupLocale.getCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        Object val = reorderMap.get(encoding + "." + language + "." + country);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            val = reorderMap.get(encoding + "." + language);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            val = reorderMap.get(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    /* This method reorders the sequence such that the matches for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * file encoding are moved ahead of other elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * If an encoding uses more than one font, they are all moved up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     private void reorderSequenceForLocale(String[] seq) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        Object val =  getReorderSequence();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        if (val instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            for (int i=0; i< seq.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                if (seq[i].equals(val)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                    shuffle(seq, i, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        } else if (val instanceof String[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            String[] fontLangs = (String[])val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            for (int l=0; l<fontLangs.length;l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                for (int i=0; i<seq.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                    if (seq[i].equals(fontLangs[l])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                        shuffle(seq, i, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    private static Vector splitSequence(String sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        //String.split would be more convenient, but incurs big performance penalty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        Vector parts = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        int start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        int end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        while ((end = sequence.indexOf(',', start)) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            parts.add(sequence.substring(start, end));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            start = end + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        if (sequence.length() > start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            parts.add(sequence.substring(start, sequence.length()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        return parts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    protected String[] split(String sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        Vector v = splitSequence(sequence);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        return (String[])v.toArray(new String[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    ////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    // Methods for extracting information from the fontconfig data for AWT//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    ////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    private Hashtable charsetRegistry = new Hashtable(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * Returns FontDescriptors describing the physical fonts used for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * given logical font name and style. The font name is interpreted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * in a case insensitive way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * The style argument is interpreted as in java.awt.Font.Font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    public FontDescriptor[] getFontDescriptors(String fontName, int style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        assert isLogicalFontFamilyName(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        fontName = fontName.toLowerCase(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        int fontIndex = getFontIndex(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        int styleIndex = getStyleIndex(style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        return getFontDescriptors(fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    private FontDescriptor[][][] fontDescriptors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        new FontDescriptor[NUM_FONTS][NUM_STYLES][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    private FontDescriptor[] getFontDescriptors(int fontIndex, int styleIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        FontDescriptor[] descriptors = fontDescriptors[fontIndex][styleIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        if (descriptors == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            descriptors = buildFontDescriptors(fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            fontDescriptors[fontIndex][styleIndex] = descriptors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        return descriptors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    private FontDescriptor[] buildFontDescriptors(int fontIndex, int styleIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        String fontName = fontNames[fontIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        String styleName = styleNames[styleIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        short[] scriptIDs = getCoreScripts(fontIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        short[] nameIDs = compFontNameIDs[fontIndex][styleIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        String[] sequence = new String[scriptIDs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        String[] names = new String[scriptIDs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        for (int i = 0; i < sequence.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            names[i] = getComponentFontName(nameIDs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            sequence[i] = getScriptName(scriptIDs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            if (alphabeticSuffix != null && "alphabetic".equals(sequence[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                sequence[i] = sequence[i] + "/" + alphabeticSuffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        int[][] fontExclusionRanges = compExclusions[fontIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        FontDescriptor[] descriptors = new FontDescriptor[names.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        for (int i = 0; i < names.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            String awtFontName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            String encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            awtFontName = makeAWTFontName(names[i], sequence[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            // look up character encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            encoding = getEncoding(names[i], sequence[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            if (encoding == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                encoding = "default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            CharsetEncoder enc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                    = getFontCharsetEncoder(encoding.trim(), awtFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            // we already have the exclusion ranges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            int[] exclusionRanges = fontExclusionRanges[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            // create descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            descriptors[i] = new FontDescriptor(awtFontName, enc, exclusionRanges);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        return descriptors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * Returns the AWT font name for the given platform font name and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * character subset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    protected String makeAWTFontName(String platformFontName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            String characterSubsetName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        return platformFontName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * Returns the java.io name of the platform character encoding for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * given AWT font name and character subset. May return "default"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * to indicate that getDefaultFontCharset should be called to obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * a charset encoder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    protected abstract String getEncoding(String awtFontName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            String characterSubsetName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    private CharsetEncoder getFontCharsetEncoder(final String charsetName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            String fontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        Charset fc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        if (charsetName.equals("default")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            fc = (Charset) charsetRegistry.get(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            fc = (Charset) charsetRegistry.get(charsetName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        if (fc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            return fc.newEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        if (!charsetName.startsWith("sun.awt.") && !charsetName.equals("default")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            fc = Charset.forName(charsetName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            Class fcc = (Class) AccessController.doPrivileged(new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                            return Class.forName(charsetName, true,
12811
859419a97d2b 7120895: FontConfiguration should not use thread contextClassLoader
bae
parents: 10406
diff changeset
   950
                                                 ClassLoader.getSystemClassLoader());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            if (fcc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                    fc = (Charset) fcc.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        if (fc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            fc = getDefaultFontCharset(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        if (charsetName.equals("default")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            charsetRegistry.put(fontName, fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            charsetRegistry.put(charsetName, fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        return fc.newEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    protected abstract Charset getDefaultFontCharset(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            String fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    /* This retrieves the platform font directories (path) calculated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * by setAWTFontPathSequence(String[]). The default implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * returns null, its expected that X11 platforms may return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * non-null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    public HashSet<String> getAWTFontPathSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    ////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    // methods for extracting information from the fontconfig data for 2D //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    ////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * Returns an array of composite font descriptors for all logical font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * faces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * If the font configuration file doesn't specify Lucida Sans Regular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * or the given fallback font as component fonts, they are added here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    public CompositeFontDescriptor[] get2DCompositeFontInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        CompositeFontDescriptor[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                new CompositeFontDescriptor[NUM_FONTS * NUM_STYLES];
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
  1001
        String defaultFontFile = fontManager.getDefaultFontFile();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
  1002
        String defaultFontFaceName = fontManager.getDefaultFontFaceName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        for (int fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            String fontName = publicFontNames[fontIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            // determine exclusion ranges for font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            // AWT uses separate exclusion range array per component font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            // 2D packs all range boundaries into one array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            // Both use separate entries for lower and upper boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            int[][] exclusions = compExclusions[fontIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            int numExclusionRanges = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            for (int i = 0; i < exclusions.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                numExclusionRanges += exclusions[i].length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            int[] exclusionRanges = new int[numExclusionRanges];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            int[] exclusionRangeLimits = new int[exclusions.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            int exclusionRangeIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            int exclusionRangeLimitIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            for (int i = 0; i < exclusions.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                int[] componentRanges = exclusions[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                for (int j = 0; j < componentRanges.length; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                    int value = componentRanges[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                    exclusionRanges[exclusionRangeIndex++] = componentRanges[j++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                    exclusionRanges[exclusionRangeIndex++] = componentRanges[j++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                exclusionRangeLimits[i] = exclusionRangeIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            // other info is per style
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            for (int styleIndex = 0; styleIndex < NUM_STYLES; styleIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                int maxComponentFontCount = compFontNameIDs[fontIndex][styleIndex].length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                boolean sawDefaultFontFile = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                // fall back fonts listed in the lib/fonts/fallback directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                if (installedFallbackFontFiles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                    maxComponentFontCount += installedFallbackFontFiles.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                String faceName = fontName + "." + styleNames[styleIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                // determine face names and file names of component fonts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                String[] componentFaceNames = new String[maxComponentFontCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                String[] componentFileNames = new String[maxComponentFontCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                for (index = 0; index < compFontNameIDs[fontIndex][styleIndex].length; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                    short fontNameID = compFontNameIDs[fontIndex][styleIndex][index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                    short fileNameID = getComponentFileID(fontNameID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                    componentFaceNames[index] = getFaceNameFromComponentFontName(getComponentFontName(fontNameID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                    componentFileNames[index] = mapFileName(getComponentFileName(fileNameID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                    if (componentFileNames[index] == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                        needToSearchForFile(componentFileNames[index])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                        componentFileNames[index] = getFileNameFromComponentFontName(getComponentFontName(fontNameID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                    if (!sawDefaultFontFile &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                        defaultFontFile.equals(componentFileNames[index])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                        sawDefaultFontFile = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                    System.out.println(publicFontNames[fontIndex] + "." + styleNames[styleIndex] + "."
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                        + getString(table_scriptIDs[coreScripts[index]]) + "=" + componentFileNames[index]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                //"Lucida Sans Regular" is not in the list, we add it here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                if (!sawDefaultFontFile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                    int len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                    if (installedFallbackFontFiles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                        len = installedFallbackFontFiles.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                    if (index + len == maxComponentFontCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                        String[] newComponentFaceNames = new String[maxComponentFontCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                        System.arraycopy(componentFaceNames, 0, newComponentFaceNames, 0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                        componentFaceNames = newComponentFaceNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                        String[] newComponentFileNames = new String[maxComponentFontCount + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                        System.arraycopy(componentFileNames, 0, newComponentFileNames, 0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                        componentFileNames = newComponentFileNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                    componentFaceNames[index] = defaultFontFaceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                    componentFileNames[index] = defaultFontFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                if (installedFallbackFontFiles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                    for (int ifb=0; ifb<installedFallbackFontFiles.length; ifb++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                        componentFaceNames[index] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                        componentFileNames[index] = installedFallbackFontFiles[ifb];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                        index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                if (index < maxComponentFontCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                    String[] newComponentFaceNames = new String[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                    System.arraycopy(componentFaceNames, 0, newComponentFaceNames, 0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                    componentFaceNames = newComponentFaceNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                    String[] newComponentFileNames = new String[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                    System.arraycopy(componentFileNames, 0, newComponentFileNames, 0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                    componentFileNames = newComponentFileNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                // exclusion range limit array length must match component face name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                // array length - native code relies on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                int[] clippedExclusionRangeLimits = exclusionRangeLimits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                if (index != clippedExclusionRangeLimits.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                    int len = exclusionRangeLimits.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                    clippedExclusionRangeLimits = new int[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                    System.arraycopy(exclusionRangeLimits, 0, clippedExclusionRangeLimits, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                    //padding for various fallback fonts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                    for (int i = len; i < index; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                        clippedExclusionRangeLimits[i] = exclusionRanges.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                System.out.println(faceName + ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                for (int i = 0; i < componentFileNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                    System.out.println("    " + componentFaceNames[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                         + "  -> " + componentFileNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                result[fontIndex * NUM_STYLES + styleIndex]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                        = new CompositeFontDescriptor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                            faceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                            compCoreNum[fontIndex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                            componentFaceNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                            componentFileNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                            exclusionRanges,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                            clippedExclusionRangeLimits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    protected abstract String getFaceNameFromComponentFontName(String componentFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    protected abstract String getFileNameFromComponentFontName(String componentFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    public class 2dFont {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        public String platformName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        public String fontfileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    private 2dFont [] componentFonts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    /* Used on Linux to test if a file referenced in a font configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * file exists in the location that is expected. If it does, no need
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * to search for it. If it doesn't then unless its a fallback font,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * return that expensive code should be invoked to search for the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    HashMap<String, Boolean> existsMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    public boolean needToSearchForFile(String fileName) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
  1149
        if (!FontUtilities.isLinux) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        } else if (existsMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
           existsMap = new HashMap<String, Boolean>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        Boolean exists = existsMap.get(fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        if (exists == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            /* call getNumberCoreFonts() to ensure these are initialised, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
             * if this file isn't for a core component, ie, is a for a fallback
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
             * font which very typically isn't available, then can't afford
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
             * to take the start-up penalty to search for it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            getNumberCoreFonts();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            if (!coreFontFileNames.contains(fileName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                exists = Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                exists = Boolean.valueOf((new File(fileName)).exists());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                existsMap.put(fileName, exists);
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
  1167
                if (FontUtilities.debugFonts() &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                    exists == Boolean.FALSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                    logger.warning("Couldn't locate font file " + fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        return exists == Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    private int numCoreFonts = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    private String[] componentFonts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    HashMap <String, String> filenamesMap = new HashMap<String, String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    HashSet <String> coreFontFileNames = new HashSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    /* Return the number of core fonts. Note this isn't thread safe but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * a calling thread can call this and getPlatformFontNames() in either
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    public int getNumberCoreFonts() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        if (numCoreFonts == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            numCoreFonts = coreFontNameIDs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            Short[] emptyShortArray = new Short[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            Short[] core = coreFontNameIDs.toArray(emptyShortArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            Short[] fallback = fallbackFontNameIDs.toArray(emptyShortArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            int numFallbackFonts = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            for (i = 0; i < fallback.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                if (coreFontNameIDs.contains(fallback[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                    fallback[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                numFallbackFonts++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            componentFonts = new String[numCoreFonts + numFallbackFonts];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            String filename = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            for (i = 0; i < core.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                short fontid = core[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                short fileid = getComponentFileID(fontid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                componentFonts[i] = getComponentFontName(fontid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                String compFileName = getComponentFileName(fileid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                if (compFileName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                    coreFontFileNames.add(compFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                filenamesMap.put(componentFonts[i], mapFileName(compFileName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            for (int j = 0; j < fallback.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                if (fallback[j] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                    short fontid = fallback[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                    short fileid = getComponentFileID(fontid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                    componentFonts[i] = getComponentFontName(fontid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                    filenamesMap.put(componentFonts[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                                     mapFileName(getComponentFileName(fileid)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                    i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        return numCoreFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    /* Return all platform font names used by this font configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * The first getNumberCoreFonts() entries are guaranteed to be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * core fonts - ie no fall back only fonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    public String[] getPlatformFontNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        if (numCoreFonts == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            getNumberCoreFonts();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        return componentFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * Returns a file name for the physical font represented by this platform font name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * if the font configuration has such information available, or null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * information is unavailable. The file name returned is just a hint; a null return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * value doesn't necessarily mean that the font is unavailable, nor does a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * return value guarantee that the file exists and contains the physical font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * The file name can be an absolute or a relative path name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    public String getFileNameFromPlatformName(String platformName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        // get2DCompositeFontInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        //     ->  getFileNameFromComponentfontName()  (W/M)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        //       ->   getFileNameFromPlatformName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        // it's a waste of time on Win32, but I have to give X11 a chance to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        // call getFileNameFromXLFD()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        return filenamesMap.get(platformName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * Returns a configuration specific path to be appended to the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * search path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    public String getExtraFontPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        return getString(head[INDEX_appendedfontpath]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    public String getVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        return getString(head[INDEX_version]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    /* subclass support */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    protected static FontConfiguration getFontConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        return fontConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
2372
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 889
diff changeset
  1272
    protected void setFontConfiguration() {
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 889
diff changeset
  1273
        fontConfig = this;      /* static initialization */
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 889
diff changeset
  1274
    }
229b2c88d29c 6752638: java.awt.GraphicsEnvironment.preferLocaleFonts() throws NPE on Linux
prr
parents: 889
diff changeset
  1275
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    //////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    // FontConfig data tables and the index constants in binary file    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    //////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    /* The binary font configuration file begins with a short[] "head", which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * contains the offsets to the starts of the individual data table which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * immediately follow. Teh current implemention includes the tables shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * (00) table_scriptIDs    :stringIDs of all defined CharacterSubsetNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * (01) table_scriptFonts  :scriptID x fontIndex x styleIndex->
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     *                          PlatformFontNameID mapping. Each scriptID might
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     *                          have 1 or 20 entries depends on if it is defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     *                          via a "allfonts.CharacterSubsetname" or a list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     *                          "LogicalFontName.StyleName.CharacterSubsetName"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     *                          entries, positive entry means it's a "allfonts"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     *                          entry, a negative value means this is a offset to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     *                          a NUM_FONTS x NUM_STYLES subtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * (02) table_elcIDs       :stringIDs of all defined ELC names, string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     *                          "NULL.NULL.NULL" is used for "default"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * (03) table_sequences    :elcID x logicalFont -> scriptIDs table defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     *                          by "sequence.allfonts/LogicalFontName.ELC" in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     *                          font configuration file, each "elcID" has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     *                          NUM_FONTS (5) entries in this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * (04) table_fontfileNameIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     *                         :stringIDs of all defined font file names
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * (05) table_componentFontNameIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     *                         :stringIDs of all defined PlatformFontNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     * (06) table_filenames    :platformFontNamesID->fontfileNameID mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     *                          table, the index is the platformFontNamesID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * (07) table_awtfontpaths :CharacterSubsetNames->awtfontpaths mapping table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     *                          the index is the CharacterSubsetName's stringID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     *                          and content is the stringID of awtfontpath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * (08) table_exclusions   :scriptID -> exclusionRanges mapping table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     *                          the index is the scriptID and the content is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                                a id of an exclusionRanges int[].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     * (09) table_proportionals:list of pairs of PlatformFontNameIDs, stores
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     *                          the replacement info defined by "proportional"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     *                          keyword.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * (10) table_scriptFontsMotif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     *                         :same as (01) except this table stores the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     *                          info defined with ".motif" keyword
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * (11) table_alphabeticSuffix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     *                         :elcID -> stringID of alphabetic/XXXX entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * (12) table_stringIDs    :The index of this table is the string ID, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     *                          content is the "start index" of this string in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     *                          stringTable, use the start index of next entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     *                          as the "end index".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * (13) table_stringTable  :The real storage of all character strings defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     *                          /used this font configuration, need a pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     *                          "start" and "end" indices to access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * (14) reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * (15) table_fallbackScripts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     *                         :stringIDs of fallback CharacterSubsetnames, stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     *                          in the order of they are defined in sequence.fallback.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     * (16) table_appendedfontpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     *                         :stringtID of the "appendedfontpath" defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     * (17) table_version   :stringID of the version number of this fontconfig file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    private static final int HEAD_LENGTH = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    private static final int INDEX_scriptIDs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    private static final int INDEX_scriptFonts = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    private static final int INDEX_elcIDs = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    private static final int INDEX_sequences = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    private static final int INDEX_fontfileNameIDs = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    private static final int INDEX_componentFontNameIDs = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    private static final int INDEX_filenames = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    private static final int INDEX_awtfontpaths = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    private static final int INDEX_exclusions = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    private static final int INDEX_proportionals = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    private static final int INDEX_scriptFontsMotif = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    private static final int INDEX_alphabeticSuffix = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    private static final int INDEX_stringIDs = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    private static final int INDEX_stringTable = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    private static final int INDEX_TABLEEND = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    private static final int INDEX_fallbackScripts = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    private static final int INDEX_appendedfontpath = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    private static final int INDEX_version = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    private static short[] head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    private static short[] table_scriptIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    private static short[] table_scriptFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    private static short[] table_elcIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    private static short[] table_sequences;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
    private static short[] table_fontfileNameIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    private static short[] table_componentFontNameIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    private static short[] table_filenames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
    protected static short[] table_awtfontpaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    private static short[] table_exclusions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    private static short[] table_proportionals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    private static short[] table_scriptFontsMotif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    private static short[] table_alphabeticSuffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    private static short[] table_stringIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    private static char[]  table_stringTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1370
    /**
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1371
     * Checks consistencies of complied fontconfig data. This method
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1372
     * is called only at the build-time from
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1373
     * build.tools.compilefontconfig.CompileFontConfig.
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1374
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    private static void sanityCheck() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        int errors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        //This method will only be called during build time, do we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        //need do PrivilegedAction?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        String osName = (String)java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                            new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                return System.getProperty("os.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        //componentFontNameID starts from "1"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        for (int ii = 1; ii < table_filenames.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            if (table_filenames[ii] == -1) {
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1390
                // The corresponding finename entry for a component
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1391
                // font name is mandatory on Windows, but it's
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1392
                // optional on Solaris and Linux.
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1393
                if (osName.contains("Windows")) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1394
                    System.err.println("\n Error: <filename."
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1395
                                       + getString(table_componentFontNameIDs[ii])
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1396
                                       + "> entry is missing!!!");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                    errors++;
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1398
                } else {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1399
                    if (verbose && !isEmpty(table_filenames)) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1400
                        System.err.println("\n Note: 'filename' entry is undefined for \""
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1401
                                           + getString(table_componentFontNameIDs[ii])
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1402
                                           + "\"");
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1403
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
        for (int ii = 0; ii < table_scriptIDs.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            short fid = table_scriptFonts[ii];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            if (fid == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                System.out.println("\n Error: <allfonts."
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                                   + getString(table_scriptIDs[ii])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                                   + "> entry is missing!!!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                errors++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            } else if (fid < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                fid = (short)-fid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                for (int iii = 0; iii < NUM_FONTS; iii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                    for (int iij = 0; iij < NUM_STYLES; iij++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                        int jj = iii * NUM_STYLES + iij;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                        short ffid = table_scriptFonts[fid + jj];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                        if (ffid == 0) {
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1422
                            System.err.println("\n Error: <"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                                           + getFontName(iii) + "."
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                                           + getStyleName(iij) + "."
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                                           + getString(table_scriptIDs[ii])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                                           + "> entry is missing!!!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                            errors++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        if ("SunOS".equals(osName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            for (int ii = 0; ii < table_awtfontpaths.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                if (table_awtfontpaths[ii] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                    String script = getString(table_scriptIDs[ii]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                    if (script.contains("lucida") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                        script.contains("dingbats") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                        script.contains("symbol")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                    }
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1442
                    System.err.println("\nError: "
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                                       + "<awtfontpath."
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                                       + script
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                                       + "> entry is missing!!!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                    errors++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        if (errors != 0) {
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1451
            System.err.println("!!THERE ARE " + errors + " ERROR(S) IN "
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                               + "THE FONTCONFIG FILE, PLEASE CHECK ITS CONTENT!!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
            System.exit(1);
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1454
        }
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1455
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1457
    private static boolean isEmpty(short[] a) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1458
        for (short s : a) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1459
            if (s != -1) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1460
                return false;
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1461
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        }
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1463
        return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    //dump the fontconfig data tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
    private static void dump() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        System.out.println("\n----Head Table------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        for (int ii = 0; ii < HEAD_LENGTH; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            System.out.println("  " + ii + " : " + head[ii]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        System.out.println("\n----scriptIDs-------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        printTable(table_scriptIDs, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        System.out.println("\n----scriptFonts----------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        for (int ii = 0; ii < table_scriptIDs.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
            short fid = table_scriptFonts[ii];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
            if (fid >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                System.out.println("  allfonts."
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                                   + getString(table_scriptIDs[ii])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                                   + "="
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                                   + getString(table_componentFontNameIDs[fid]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        for (int ii = 0; ii < table_scriptIDs.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            short fid = table_scriptFonts[ii];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            if (fid < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                fid = (short)-fid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                for (int iii = 0; iii < NUM_FONTS; iii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                    for (int iij = 0; iij < NUM_STYLES; iij++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                        int jj = iii * NUM_STYLES + iij;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                        short ffid = table_scriptFonts[fid + jj];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                        System.out.println("  "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                                           + getFontName(iii) + "."
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                                           + getStyleName(iij) + "."
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                                           + getString(table_scriptIDs[ii])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                                           + "="
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                                           + getString(table_componentFontNameIDs[ffid]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        System.out.println("\n----elcIDs----------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        printTable(table_elcIDs, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        System.out.println("\n----sequences-------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        for (int ii = 0; ii< table_elcIDs.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            System.out.println("  " + ii + "/" + getString((short)table_elcIDs[ii]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            short[] ss = getShortArray(table_sequences[ii * NUM_FONTS + 0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            for (int jj = 0; jj < ss.length; jj++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                System.out.println("     " + getString((short)table_scriptIDs[ss[jj]]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        System.out.println("\n----fontfileNameIDs-------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        printTable(table_fontfileNameIDs, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        System.out.println("\n----componentFontNameIDs--");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        printTable(table_componentFontNameIDs, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
        System.out.println("\n----filenames-------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        for (int ii = 0; ii < table_filenames.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            if (table_filenames[ii] == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                System.out.println("  " + ii + " : null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                System.out.println("  " + ii + " : "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                   + getString(table_fontfileNameIDs[table_filenames[ii]]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        System.out.println("\n----awtfontpaths---------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        for (int ii = 0; ii < table_awtfontpaths.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            System.out.println("  " + getString(table_scriptIDs[ii])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                               + " : "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                               + getString(table_awtfontpaths[ii]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        System.out.println("\n----proportionals--------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        for (int ii = 0; ii < table_proportionals.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
            System.out.println("  "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                   + getString((short)table_componentFontNameIDs[table_proportionals[ii++]])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                   + " -> "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                   + getString((short)table_componentFontNameIDs[table_proportionals[ii]]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        System.out.println("\n----alphabeticSuffix----");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        while (i < table_alphabeticSuffix.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
          System.out.println("    " + getString(table_elcIDs[table_alphabeticSuffix[i++]])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                             + " -> " + getString(table_alphabeticSuffix[i++]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        System.out.println("\n----String Table---------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        System.out.println("    stringID:    Num =" + table_stringIDs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        System.out.println("    stringTable: Size=" + table_stringTable.length * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        System.out.println("\n----fallbackScriptIDs---");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        short[] fbsIDs = getShortArray(head[INDEX_fallbackScripts]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        for (int ii = 0; ii < fbsIDs.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
          System.out.println("  " + getString(table_scriptIDs[fbsIDs[ii]]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
        System.out.println("\n----appendedfontpath-----");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        System.out.println("  " + getString(head[INDEX_appendedfontpath]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        System.out.println("\n----Version--------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        System.out.println("  " + getString(head[INDEX_version]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
    //////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
    // Data table access methods                                        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    //////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    /* Return the fontID of the platformFontName defined in this font config
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
     * by "LogicalFontName.StyleName.CharacterSubsetName" entry or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     * "allfonts.CharacterSubsetName" entry in properties format fc file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    protected static short getComponentFontID(short scriptID, int fontIndex, int styleIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        short fid = table_scriptFonts[scriptID];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        //System.out.println("fid=" + fid + "/ scriptID=" + scriptID + ", fi=" + fontIndex + ", si=" + styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
        if (fid >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            //"allfonts"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            return fid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            return table_scriptFonts[-fid + fontIndex * NUM_STYLES + styleIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    /* Same as getCompoentFontID() except this method returns the fontID define by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     * "xxxx.motif" entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    protected static short getComponentFontIDMotif(short scriptID, int fontIndex, int styleIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        if (table_scriptFontsMotif.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
        short fid = table_scriptFontsMotif[scriptID];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
        if (fid >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            //"allfonts" > 0 or "not defined" == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
            return fid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
            return table_scriptFontsMotif[-fid + fontIndex * NUM_STYLES + styleIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    private static int[] getExclusionRanges(short scriptID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
        short exID = table_exclusions[scriptID];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        if (exID == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
            return EMPTY_INT_ARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
            char[] exChar = getString(exID).toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
            int[] exInt = new int[exChar.length / 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
            for (int j = 0; j < exInt.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                exInt[j] = (exChar[i++] << 16) + (exChar[i++] & 0xffff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
            return exInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    private static boolean contains(short IDs[], short id, int limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
        for (int i = 0; i < limit; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
            if (IDs[i] == id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    /* Return the PlatformFontName from its fontID*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    protected static String getComponentFontName(short id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        if (id < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        return getString(table_componentFontNameIDs[id]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
    private static String getComponentFileName(short id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
        if (id < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        return getString(table_fontfileNameIDs[id]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
    //componentFontID -> componentFileID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    private static short getComponentFileID(short nameID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        return table_filenames[nameID];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
    private static String getScriptName(short scriptID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        return getString(table_scriptIDs[scriptID]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
   private HashMap<String, Short> reorderScripts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
   protected short[] getCoreScripts(int fontIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
        short elc = getInitELC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
          System.out.println("getCoreScripts: elc=" + elc + ", fontIndex=" + fontIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
          short[] ss = getShortArray(table_sequences[elc * NUM_FONTS + fontIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
          for (int i = 0; i < ss.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
              System.out.println("     " + getString((short)table_scriptIDs[ss[i]]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        short[] scripts = getShortArray(table_sequences[elc * NUM_FONTS + fontIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        if (preferLocaleFonts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
            if (reorderScripts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                reorderScripts = new HashMap<String, Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
            String[] ss = new String[scripts.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            for (int i = 0; i < ss.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                ss[i] = getScriptName(scripts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                reorderScripts.put(ss[i], scripts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
            reorderSequenceForLocale(ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
            for (int i = 0; i < ss.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                scripts[i] = reorderScripts.get(ss[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
         return scripts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
    private static short[] getFallbackScripts() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
        return getShortArray(head[INDEX_fallbackScripts]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
    private static void printTable(short[] list, int start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
        for (int i = start; i < list.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
            System.out.println("  " + i + " : " + getString(list[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
    private static short[] readShortTable(DataInputStream in, int len )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
        if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            return EMPTY_SHORT_ARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        short[] data = new short[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
        byte[] bb = new byte[len * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
        in.read(bb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
        int i = 0,j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
        while (i < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
            data[i++] = (short)(bb[j++] << 8 | (bb[j++] & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
        return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
    private static void writeShortTable(DataOutputStream out, short[] data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        throws IOException {
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1700
        for (short val : data) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1701
            out.writeShort(val);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1705
    private static short[] toList(HashMap<String, Short> map) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        short[] list = new short[map.size()];
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1707
        Arrays.fill(list, (short) -1);
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1708
        for (Entry<String, Short> entry : map.entrySet()) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1709
            list[entry.getValue()] = getStringID(entry.getKey());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
    //runtime cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
    private static String[] stringCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
    protected static String getString(short stringID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
        if (stringID == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        if (loadingProperties) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
            return stringTable.substring(stringIDs[stringID],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                                         stringIDs[stringID+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
        //sync if we want it to be MT-enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        if (stringCache[stringID] == null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
            stringCache[stringID] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
              new String (table_stringTable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                          table_stringIDs[stringID],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                          table_stringIDs[stringID+1] - table_stringIDs[stringID]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        return stringCache[stringID];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    private static short[] getShortArray(short shortArrayID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        String s = getString(shortArrayID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        char[] cc = s.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        short[] ss = new short[cc.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        for (int i = 0; i < cc.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            ss[i] = (short)(cc[i] & 0xffff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        return ss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
    private static short getStringID(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
            return (short)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
        short pos0 = (short)stringTable.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
        stringTable.append(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        short pos1 = (short)stringTable.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
        stringIDs[stringIDNum] = pos0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
        stringIDs[stringIDNum + 1] = pos1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
        stringIDNum++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
        if (stringIDNum + 1 >= stringIDs.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
            short[] tmp = new short[stringIDNum + 1000];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
            System.arraycopy(stringIDs, 0, tmp, 0, stringIDNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
            stringIDs = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        return (short)(stringIDNum - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
    private static short getShortArrayID(short sa[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        char[] cc = new char[sa.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
        for (int i = 0; i < sa.length; i ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
            cc[i] = (char)sa[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
        String s = new String(cc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        return getStringID(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
    //utility "empty" objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
    private static final int[] EMPTY_INT_ARRAY = new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
    private static final String[] EMPTY_STRING_ARRAY = new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
    private static final short[] EMPTY_SHORT_ARRAY = new short[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
    private static final String UNDEFINED_COMPONENT_FONT = "unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
    //////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
    //Convert the FontConfig data in Properties file to binary data tables  //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
    //////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
    static class PropertiesHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
        public void load(InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            initLogicalNameStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            initHashMaps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
            FontProperties fp = new FontProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            fp.load(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
            initBinaryTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        private void initBinaryTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
            //(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
            head = new short[HEAD_LENGTH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            head[INDEX_scriptIDs] = (short)HEAD_LENGTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            table_scriptIDs = toList(scriptIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
            //(1)a: scriptAllfonts scriptID/allfonts -> componentFontNameID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            //   b: scriptFonts    scriptID -> componentFontNameID[20]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            //if we have a "allfonts.script" def, then we just put
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
            //the "-platformFontID" value in the slot, otherwise the slot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
            //value is "offset" which "offset" is where 20 entries located
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
            //in the table attached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
            head[INDEX_scriptFonts] = (short)(head[INDEX_scriptIDs]  + table_scriptIDs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
            int len = table_scriptIDs.length + scriptFonts.size() * 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
            table_scriptFonts = new short[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1807
            for (Entry<Short, Short> entry : scriptAllfonts.entrySet()) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1808
                table_scriptFonts[entry.getKey().intValue()] = entry.getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            int off = table_scriptIDs.length;
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1811
            for (Entry<Short, Short[]> entry : scriptFonts.entrySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                table_scriptFonts[entry.getKey().intValue()] = (short)-off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                Short[] v = entry.getValue();
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1814
                for (int i = 0; i < 20; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                    if (v[i] != null) {
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1816
                        table_scriptFonts[off++] = v[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                        table_scriptFonts[off++] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
            //(2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
            head[INDEX_elcIDs] = (short)(head[INDEX_scriptFonts]  + table_scriptFonts.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
            table_elcIDs = toList(elcIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
            //(3) sequences  elcID -> XXXX[1|5] -> scriptID[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            head[INDEX_sequences] = (short)(head[INDEX_elcIDs]  + table_elcIDs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
            table_sequences = new short[elcIDs.size() * NUM_FONTS];
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1830
            for (Entry<Short, short[]> entry : sequences.entrySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                //table_sequences[entry.getKey().intValue()] = (short)-off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                int k = entry.getKey().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                short[] v = entry.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                  System.out.println("elc=" + k + "/" + getString((short)table_elcIDs[k]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                  short[] ss = getShortArray(v[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                  for (int i = 0; i < ss.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                  System.out.println("     " + getString((short)table_scriptIDs[ss[i]]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                if (v.length == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                    //the "allfonts" entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                    for (int i = 0; i < NUM_FONTS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                        table_sequences[k * NUM_FONTS + i] = v[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                    for (int i = 0; i < NUM_FONTS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                        table_sequences[k * NUM_FONTS + i] = v[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            //(4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
            head[INDEX_fontfileNameIDs] = (short)(head[INDEX_sequences]  + table_sequences.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
            table_fontfileNameIDs = toList(fontfileNameIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
            //(5)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
            head[INDEX_componentFontNameIDs] = (short)(head[INDEX_fontfileNameIDs]  + table_fontfileNameIDs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
            table_componentFontNameIDs = toList(componentFontNameIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
            //(6)componentFontNameID -> filenameID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            head[INDEX_filenames] = (short)(head[INDEX_componentFontNameIDs]  + table_componentFontNameIDs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
            table_filenames = new short[table_componentFontNameIDs.length];
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1863
            Arrays.fill(table_filenames, (short) -1);
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1864
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1865
            for (Entry<Short, Short> entry : filenames.entrySet()) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1866
                table_filenames[entry.getKey()] = entry.getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
            //(7)scriptID-> awtfontpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            //the paths are stored as scriptID -> stringID in awtfontpahts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
            head[INDEX_awtfontpaths] = (short)(head[INDEX_filenames]  + table_filenames.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
            table_awtfontpaths = new short[table_scriptIDs.length];
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1873
            for (Entry<Short, Short> entry : awtfontpaths.entrySet()) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1874
                table_awtfontpaths[entry.getKey()] = entry.getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            //(8)exclusions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
            head[INDEX_exclusions] = (short)(head[INDEX_awtfontpaths]  + table_awtfontpaths.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
            table_exclusions = new short[scriptIDs.size()];
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1880
            for (Entry<Short, int[]> entry : exclusions.entrySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                int[] exI = entry.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                char[] exC = new char[exI.length * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                for (int i = 0; i < exI.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                    exC[j++] = (char) (exI[i] >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                    exC[j++] = (char) (exI[i] & 0xffff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                }
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1888
                table_exclusions[entry.getKey()] = getStringID(new String (exC));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            //(9)proportionals
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
            head[INDEX_proportionals] = (short)(head[INDEX_exclusions]  + table_exclusions.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
            table_proportionals = new short[proportionals.size() * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            int j = 0;
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1894
            for (Entry<Short, Short> entry : proportionals.entrySet()) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1895
                table_proportionals[j++] = entry.getKey();
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1896
                table_proportionals[j++] = entry.getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
            //(10) see (1) for info, the only difference is "xxx.motif"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
            head[INDEX_scriptFontsMotif] = (short)(head[INDEX_proportionals] + table_proportionals.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
            if (scriptAllfontsMotif.size() != 0 || scriptFontsMotif.size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                len = table_scriptIDs.length + scriptFontsMotif.size() * 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                table_scriptFontsMotif = new short[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1905
                for (Entry<Short, Short> entry : scriptAllfontsMotif.entrySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                    table_scriptFontsMotif[entry.getKey().intValue()] =
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1907
                      (short)entry.getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                off = table_scriptIDs.length;
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1910
                for (Entry<Short, Short[]> entry : scriptFontsMotif.entrySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                    table_scriptFontsMotif[entry.getKey().intValue()] = (short)-off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                    Short[] v = entry.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
                    int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                    while (i < 20) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                        if (v[i] != null) {
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1916
                            table_scriptFontsMotif[off++] = v[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                            table_scriptFontsMotif[off++] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
                table_scriptFontsMotif = EMPTY_SHORT_ARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
            //(11)short[] alphabeticSuffix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            head[INDEX_alphabeticSuffix] = (short)(head[INDEX_scriptFontsMotif] + table_scriptFontsMotif.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
            table_alphabeticSuffix = new short[alphabeticSuffix.size() * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
            j = 0;
7777
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1931
            for (Entry<Short, Short> entry : alphabeticSuffix.entrySet()) {
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1932
                table_alphabeticSuffix[j++] = entry.getKey();
1241aaaec247 6990037: font warnings in the build, missing fonts
okutsu
parents: 5506
diff changeset
  1933
                table_alphabeticSuffix[j++] = entry.getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            //(15)short[] fallbackScriptIDs; just put the ID in head
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
            head[INDEX_fallbackScripts] = getShortArrayID(fallbackScriptIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
            //(16)appendedfontpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
            head[INDEX_appendedfontpath] = getStringID(appendedfontpath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
            //(17)version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
            head[INDEX_version] = getStringID(version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
            //(12)short[] StringIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
            head[INDEX_stringIDs] = (short)(head[INDEX_alphabeticSuffix] + table_alphabeticSuffix.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
            table_stringIDs = new short[stringIDNum + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
            System.arraycopy(stringIDs, 0, table_stringIDs, 0, stringIDNum + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
            //(13)StringTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
            head[INDEX_stringTable] = (short)(head[INDEX_stringIDs] + stringIDNum + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
            table_stringTable = stringTable.toString().toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
            //(14)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
            head[INDEX_TABLEEND] = (short)(head[INDEX_stringTable] + stringTable.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
            //StringTable cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
            stringCache = new String[table_stringIDs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        //////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
        private HashMap<String, Short> scriptIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
        //elc -> Encoding.Language.Country
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        private HashMap<String, Short> elcIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
        //componentFontNameID starts from "1", "0" reserves for "undefined"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        private HashMap<String, Short> componentFontNameIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        private HashMap<String, Short> fontfileNameIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        private HashMap<String, Integer> logicalFontIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        private HashMap<String, Integer> fontStyleIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
        //componentFontNameID -> fontfileNameID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
        private HashMap<Short, Short>  filenames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        //elcID -> allfonts/logicalFont -> scriptID list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        //(1)if we have a "allfonts", then the length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
        //   value array is "1", otherwise it's 5, each font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
        //   must have their own individual entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
        //scriptID list "short[]" is stored as an ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
        private HashMap<Short, short[]> sequences;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
        //scriptID ->logicFontID/fontStyleID->componentFontNameID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
        //a 20-entry array (5-name x 4-style) for each script
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
        private HashMap<Short, Short[]> scriptFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        //scriptID -> componentFontNameID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
        private HashMap<Short, Short> scriptAllfonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        //scriptID -> exclusionRanges[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
        private HashMap<Short, int[]> exclusions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
        //scriptID -> fontpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        private HashMap<Short, Short> awtfontpaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        //fontID -> fontID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
        private HashMap<Short, Short> proportionals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
        //scriptID -> componentFontNameID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
        private HashMap<Short, Short> scriptAllfontsMotif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
        //scriptID ->logicFontID/fontStyleID->componentFontNameID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
        private HashMap<Short, Short[]> scriptFontsMotif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
        //elcID -> stringID of alphabetic/XXXX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        private HashMap<Short, Short> alphabeticSuffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
        private short[] fallbackScriptIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
        private String version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
        private String appendedfontpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
        private void initLogicalNameStyle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
            logicalFontIDs = new HashMap<String, Integer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
            fontStyleIDs = new HashMap<String, Integer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
            logicalFontIDs.put("serif",      0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
            logicalFontIDs.put("sansserif",  1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            logicalFontIDs.put("monospaced", 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
            logicalFontIDs.put("dialog",     3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            logicalFontIDs.put("dialoginput",4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
            fontStyleIDs.put("plain",      0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            fontStyleIDs.put("bold",       1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
            fontStyleIDs.put("italic",     2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            fontStyleIDs.put("bolditalic", 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        private void initHashMaps() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
            scriptIDs = new HashMap<String, Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
            elcIDs = new HashMap<String, Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
            componentFontNameIDs = new HashMap<String, Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
            /*Init these tables to allow componentFontNameID, fontfileNameIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
              to start from "1".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
            */
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  2030
            componentFontNameIDs.put("", Short.valueOf((short)0));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
            fontfileNameIDs = new HashMap<String, Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
            filenames = new HashMap<Short, Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            sequences = new HashMap<Short, short[]>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
            scriptFonts = new HashMap<Short, Short[]>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
            scriptAllfonts = new HashMap<Short, Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
            exclusions = new HashMap<Short, int[]>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
            awtfontpaths = new HashMap<Short, Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
            proportionals = new HashMap<Short, Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
            scriptFontsMotif = new HashMap<Short, Short[]>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
            scriptAllfontsMotif = new HashMap<Short, Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
            alphabeticSuffix = new HashMap<Short, Short>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
            fallbackScriptIDs = EMPTY_SHORT_ARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
              version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
              appendedfontpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        private int[] parseExclusions(String key, String exclusions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
            if (exclusions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                return EMPTY_INT_ARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
            // range format is xxxx-XXXX,yyyyyy-YYYYYY,.....
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
            int numExclusions = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
            int pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
            while ((pos = exclusions.indexOf(',', pos)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
                numExclusions++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
                pos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
            int[] exclusionRanges = new int[numExclusions * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
            pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
            int newPos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
            for (int j = 0; j < numExclusions * 2; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                String lower, upper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
                int lo = 0, up = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                    newPos = exclusions.indexOf('-', pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                    lower = exclusions.substring(pos, newPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                    pos = newPos + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                    newPos = exclusions.indexOf(',', pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                    if (newPos == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                        newPos = exclusions.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
                    upper = exclusions.substring(pos, newPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                    pos = newPos + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
                    int lowerLength = lower.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
                    int upperLength = upper.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                    if (lowerLength != 4 && lowerLength != 6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                        || upperLength != 4 && upperLength != 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
                        throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                    lo = Integer.parseInt(lower, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
                    up = Integer.parseInt(upper, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                    if (lo > up) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                        throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                } catch (Exception e) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
  2089
                    if (FontUtilities.debugFonts() &&
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2372
diff changeset
  2090
                        logger != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
                        logger.config("Failed parsing " + key +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                                  " property of font configuration.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                    return EMPTY_INT_ARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                exclusionRanges[j++] = lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                exclusionRanges[j++] = up;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
            return exclusionRanges;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        private Short getID(HashMap<String, Short> map, String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
            Short ret = map.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            if ( ret == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
                map.put(key, (short)map.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                return map.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
        class FontProperties extends Properties {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
            public synchronized Object put(Object k, Object v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
                parseProperty((String)k, (String)v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
        private void parseProperty(String key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
            if (key.startsWith("filename.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                //the only special case is "MingLiu_HKSCS" which has "_" in its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                //facename, we dont want to replace the "_" with " "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
                key = key.substring(9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                if (!"MingLiU_HKSCS".equals(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
                    key = key.replace('_', ' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
                Short faceID = getID(componentFontNameIDs, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
                Short fileID = getID(fontfileNameIDs, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
                //System.out.println("faceID=" + faceID + "/" + key + " -> "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
                //    + "fileID=" + fileID + "/" + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
                filenames.put(faceID, fileID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
            } else if (key.startsWith("exclusion.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                key = key.substring(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                exclusions.put(getID(scriptIDs,key), parseExclusions(key,value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
            } else if (key.startsWith("sequence.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                key = key.substring(9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                boolean hasDefault = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                boolean has1252 = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
                //get the scriptID list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
                String[] ss = (String[])splitSequence(value).toArray(EMPTY_STRING_ARRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
                short [] sa = new short[ss.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
                for (int i = 0; i < ss.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
                    if ("alphabetic/default".equals(ss[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
                        //System.out.println(key + " -> " + ss[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
                        ss[i] = "alphabetic";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
                        hasDefault = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                    } else if ("alphabetic/1252".equals(ss[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
                        //System.out.println(key + " -> " + ss[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
                        ss[i] = "alphabetic";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
                        has1252 = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
                    sa[i] = getID(scriptIDs, ss[i]).shortValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
                    //System.out.println("scriptID=" + si[i] + "/" + ss[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
                //convert the "short[] -> string -> stringID"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
                short scriptArrayID = getShortArrayID(sa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
                Short elcID = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
                int dot = key.indexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
                if (dot == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
                    if ("fallback".equals(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
                        fallbackScriptIDs = sa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
                    if ("allfonts".equals(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
                        elcID = getID(elcIDs, "NULL.NULL.NULL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
                        if (logger != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
                            logger.config("Error sequence def: <sequence." + key + ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
                    elcID = getID(elcIDs, key.substring(dot + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
                    //System.out.println("elcID=" + elcID + "/" + key.substring(dot + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
                    key = key.substring(0, dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
                short[] scriptArrayIDs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
                if ("allfonts".equals(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
                    scriptArrayIDs = new short[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
                    scriptArrayIDs[0] = scriptArrayID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
                    scriptArrayIDs = sequences.get(elcID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
                    if (scriptArrayIDs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
                       scriptArrayIDs = new short[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
                    Integer fid = logicalFontIDs.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
                    if (fid == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                        if (logger != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
                            logger.config("Unrecognizable logicfont name " + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
                    //System.out.println("sequence." + key + "/" + id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                    scriptArrayIDs[fid.intValue()] = scriptArrayID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
                sequences.put(elcID, scriptArrayIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
                if (hasDefault) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
                    alphabeticSuffix.put(elcID, getStringID("default"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
                } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
                if (has1252) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
                    alphabeticSuffix.put(elcID, getStringID("1252"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
            } else if (key.startsWith("allfonts.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                key = key.substring(9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
                if (key.endsWith(".motif")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
                    key = key.substring(0, key.length() - 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
                    //System.out.println("motif: all." + key + "=" + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
                    scriptAllfontsMotif.put(getID(scriptIDs,key), getID(componentFontNameIDs,value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
                    scriptAllfonts.put(getID(scriptIDs,key), getID(componentFontNameIDs,value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
            } else if (key.startsWith("awtfontpath.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
                key = key.substring(12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
                //System.out.println("scriptID=" + getID(scriptIDs, key) + "/" + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
                awtfontpaths.put(getID(scriptIDs, key), getStringID(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
            } else if ("version".equals(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
                version = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
            } else if ("appendedfontpath".equals(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
                appendedfontpath = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
            } else if (key.startsWith("proportional.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
                key = key.substring(13).replace('_', ' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
                //System.out.println(key + "=" + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
                proportionals.put(getID(componentFontNameIDs, key),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
                                  getID(componentFontNameIDs, value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
                //"name.style.script(.motif)", we dont care anything else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
                int dot1, dot2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
                boolean isMotif = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
                dot1 = key.indexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
                if (dot1 == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
                    if (logger != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
                        logger.config("Failed parsing " + key +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
                                  " property of font configuration.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
                dot2 = key.indexOf('.', dot1 + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
                if (dot2 == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
                    if (logger != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
                        logger.config("Failed parsing " + key +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
                                  " property of font configuration.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
                if (key.endsWith(".motif")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
                    key = key.substring(0, key.length() - 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
                    isMotif = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
                    //System.out.println("motif: " + key + "=" + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
                Integer nameID = logicalFontIDs.get(key.substring(0, dot1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
                Integer styleID = fontStyleIDs.get(key.substring(dot1+1, dot2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
                Short scriptID = getID(scriptIDs, key.substring(dot2 + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
                if (nameID == null || styleID == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
                    if (logger != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
                        logger.config("unrecognizable logicfont name/style at " + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
                Short[] pnids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
                if (isMotif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
                    pnids = scriptFontsMotif.get(scriptID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
                    pnids = scriptFonts.get(scriptID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
                if (pnids == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
                    pnids =  new Short[20];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
                pnids[nameID.intValue() * NUM_STYLES + styleID.intValue()]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
                  = getID(componentFontNameIDs, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
                System.out.println("key=" + key + "/<" + nameID + "><" + styleID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
                                     + "><" + scriptID + ">=" + value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
                                     + "/" + getID(componentFontNameIDs, value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
                */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
                if (isMotif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
                    scriptFontsMotif.put(scriptID, pnids);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
                    scriptFonts.put(scriptID, pnids);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
}