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