jdk/src/solaris/classes/sun/awt/motif/MFontConfiguration.java
author mchung
Tue, 29 Sep 2009 16:03:03 -0700
changeset 3938 ef327bd847c0
parent 3928 be186a33df9b
child 5506 202f599c92aa
permissions -rw-r--r--
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes Summary: Replace calls to Logger with sun.util.logging.PlatformLogger Reviewed-by: prr, art, alexp, dcherepanov, igor, dav, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2007 Sun Microsystems, Inc.  All Rights Reserved.
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.motif;
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.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.InputStreamReader;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    33
import java.nio.charset.Charset;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Scanner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.FontConfiguration;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    40
import sun.awt.X11FontManager;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.X11GraphicsEnvironment;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    42
import sun.font.FontManager;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    43
import sun.font.SunFontManager;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    44
import sun.font.FontManagerFactory;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    45
import sun.font.FontUtilities;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.java2d.SunGraphicsEnvironment;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    47
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class MFontConfiguration extends FontConfiguration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static FontConfiguration fontConfig = null;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    52
    private static PlatformLogger logger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    54
    public MFontConfiguration(SunFontManager fm) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    55
        super(fm);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    56
        if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    57
            logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        initTables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    63
    public MFontConfiguration(SunFontManager fm,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                              boolean preferLocaleFonts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                              boolean preferPropFonts) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    66
        super(fm, preferLocaleFonts, preferPropFonts);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    67
        if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    68
            logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        initTables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /* Needs to be kept in sync with updates in the languages used in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * the fontconfig files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    protected void initReorderMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        reorderMap = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (osName == null) {  /* null means SunOS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            initReorderMapForSolaris();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            initReorderMapForLinux();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private void initReorderMapForSolaris() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        /* Don't create a no-op entry, so we can optimize this case
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         * i.e. we don't need to do anything so can avoid slower paths in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         * the code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
//      reorderMap.put("UTF-8", "latin-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        reorderMap.put("UTF-8.hi", "devanagari"); // NB is in Lucida.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        reorderMap.put("UTF-8.ja",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                       split("japanese-x0201,japanese-x0208,japanese-x0212"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        reorderMap.put("UTF-8.ko", "korean-johab");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        reorderMap.put("UTF-8.th", "thai");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        reorderMap.put("UTF-8.zh.TW", "chinese-big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        reorderMap.put("UTF-8.zh.HK", split("chinese-big5,chinese-hkscs"));
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    98
        if (FontUtilities.isSolaris8) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            reorderMap.put("UTF-8.zh.CN", split("chinese-gb2312,chinese-big5"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            reorderMap.put("UTF-8.zh.CN",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                           split("chinese-gb18030-0,chinese-gb18030-1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        reorderMap.put("UTF-8.zh",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                       split("chinese-big5,chinese-hkscs,chinese-gb18030-0,chinese-gb18030-1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        reorderMap.put("Big5", "chinese-big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        reorderMap.put("Big5-HKSCS", split("chinese-big5,chinese-hkscs"));
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   108
        if (! FontUtilities.isSolaris8 && ! FontUtilities.isSolaris9) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            reorderMap.put("GB2312", split("chinese-gbk,chinese-gb2312"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            reorderMap.put("GB2312","chinese-gb2312");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        reorderMap.put("x-EUC-TW",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            split("chinese-cns11643-1,chinese-cns11643-2,chinese-cns11643-3"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        reorderMap.put("GBK", "chinese-gbk");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        reorderMap.put("GB18030",split("chinese-gb18030-0,chinese-gb18030-1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        reorderMap.put("TIS-620", "thai");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        reorderMap.put("x-PCK",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                       split("japanese-x0201,japanese-x0208,japanese-x0212"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        reorderMap.put("x-eucJP-Open",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                       split("japanese-x0201,japanese-x0208,japanese-x0212"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        reorderMap.put("EUC-KR", "korean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        /* Don't create a no-op entry, so we can optimize this case */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
//      reorderMap.put("ISO-8859-1", "latin-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        reorderMap.put("ISO-8859-2", "latin-2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        reorderMap.put("ISO-8859-5", "cyrillic-iso8859-5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        reorderMap.put("windows-1251", "cyrillic-cp1251");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        reorderMap.put("KOI8-R", "cyrillic-koi8-r");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        reorderMap.put("ISO-8859-6", "arabic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        reorderMap.put("ISO-8859-7", "greek");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        reorderMap.put("ISO-8859-8", "hebrew");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        reorderMap.put("ISO-8859-9", "latin-5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        reorderMap.put("ISO-8859-13", "latin-7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        reorderMap.put("ISO-8859-15", "latin-9");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private void initReorderMapForLinux() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        reorderMap.put("UTF-8.ja.JP", "japanese-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        reorderMap.put("UTF-8.ko.KR", "korean-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        reorderMap.put("UTF-8.zh.TW", "chinese-tw-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        reorderMap.put("UTF-8.zh.HK", "chinese-tw-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        reorderMap.put("UTF-8.zh.CN", "chinese-cn-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        reorderMap.put("x-euc-jp-linux",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                        split("japanese-x0201,japanese-x0208"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        reorderMap.put("GB2312", "chinese-gb18030");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        reorderMap.put("Big5", "chinese-big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        reorderMap.put("EUC-KR", "korean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (osName.equals("Sun")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            reorderMap.put("GB18030", "chinese-cn-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            reorderMap.put("GB18030", "chinese-gb18030");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Sets the OS name and version from environment information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    protected void setOsNameAndVersion(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        super.setOsNameAndVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (osName.equals("SunOS")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            //don't care os name on Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            osName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        } else if (osName.equals("Linux")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                File f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                if ((f = new File("/etc/sun-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    osName = "Sun";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    osVersion = getVersionString(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                } else if ((f = new File("/etc/fedora-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    osName = "Fedora";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    osVersion = getVersionString(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                } else if ((f = new File("/etc/redhat-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    osName = "RedHat";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    osVersion = getVersionString(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                } else if ((f = new File("/etc/turbolinux-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    osName = "Turbo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    osVersion = getVersionString(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                } else if ((f = new File("/etc/SuSE-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    osName = "SuSE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    osVersion = getVersionString(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                } else if ((f = new File("/etc/lsb-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    /* Ubuntu and (perhaps others) use only lsb-release.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                     * Syntax and encoding is compatible with java properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                     * For Ubuntu the ID is "Ubuntu".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    Properties props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    props.load(new FileInputStream(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    osName = props.getProperty("DISTRIB_ID");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    osVersion =  props.getProperty("DISTRIB_RELEASE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Gets the OS version string from a Linux release-specific file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private String getVersionString(File f){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            Scanner sc  = new Scanner(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        catch (Exception e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private static final String fontsDirPrefix = "$JRE_LIB_FONTS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    protected String mapFileName(String fileName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (fileName != null && fileName.startsWith(fontsDirPrefix)) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   217
            return SunFontManager.jreFontDirName
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    + fileName.substring(fontsDirPrefix.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    // overrides FontConfiguration.getFallbackFamilyName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public String getFallbackFamilyName(String fontName, String defaultFallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        // maintain compatibility with old font.properties files, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        // either had aliases for TimesRoman & Co. or defined mappings for them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        String compatibilityName = getCompatibilityFamilyName(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (compatibilityName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return compatibilityName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return defaultFallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    protected String getEncoding(String awtFontName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            String characterSubsetName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        // extract encoding field from XLFD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        int beginIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        int fieldNum = 13; // charset registry field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        while (fieldNum-- > 0 && beginIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            beginIndex = awtFontName.indexOf("-", beginIndex) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (beginIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return "default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        String xlfdEncoding = awtFontName.substring(beginIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (xlfdEncoding.indexOf("fontspecific") > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            if (awtFontName.indexOf("dingbats") > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                return "sun.awt.motif.X11Dingbats";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            } else if (awtFontName.indexOf("symbol") > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                return "sun.awt.Symbol";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        String encoding = (String) encodingMap.get(xlfdEncoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (encoding == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            encoding = "default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    protected Charset getDefaultFontCharset(String fontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return Charset.forName("ISO8859_1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /* methods for Motif support *********************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private String[][] motifFontSets = new String[NUM_FONTS][NUM_STYLES];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public String getMotifFontSet(String fontName, int style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        assert isLogicalFontFamilyName(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        fontName = fontName.toLowerCase(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        int fontIndex = getFontIndex(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        int styleIndex = getStyleIndex(style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return getMotifFontSet(fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private String getMotifFontSet(int fontIndex, int styleIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        String fontSet = motifFontSets[fontIndex][styleIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (fontSet == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            fontSet = buildMotifFontSet(fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            motifFontSets[fontIndex][styleIndex] = fontSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return fontSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private String buildMotifFontSet(int fontIndex, int styleIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        StringBuilder buffer = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        short[] scripts = getCoreScripts(fontIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        for (int i = 0; i < scripts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            short nameID = getComponentFontIDMotif(scripts[i], fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            if (nameID == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                nameID = getComponentFontID(scripts[i], fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            String name = getComponentFontName(nameID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if (name == null || name.endsWith("fontspecific")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            if (buffer.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                buffer.append(',');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            buffer.append(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return buffer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    protected String getFaceNameFromComponentFontName(String componentFontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    protected String getFileNameFromComponentFontName(String componentFontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        // for X11, component font name is XLFD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        // if we have a file name already, just use it; otherwise let's see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        // what the graphics environment can provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        String fileName = getFileNameFromPlatformName(componentFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (fileName != null && fileName.charAt(0) == '/' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            !needToSearchForFile(fileName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   318
        return ((X11FontManager) fontManager).getFileNameFromXLFD(componentFontName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Get default font for Motif widgets to use, preventing them from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * wasting time accessing inappropriate X resources.  This is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * only from native code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * This is part of a Motif specific performance enhancement.  By
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * default, when Motif widgets are created and initialized, Motif will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * set up default fonts for the widgets, which we ALWAYS override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * This set up includes finding the default font in the widget's X
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * resources and fairly expensive requests of the X server to identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * the specific font or fontset.  We avoid all of this overhead by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * providing a well known font to use at the creation of widgets, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * The X11 fonts are specified by XLFD strings which have %d as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * marker to indicate where the fontsize should be substituted.  [The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * libc function sprintf() is used to replace it.]  The value 140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * specifies a font size of 14 points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    private static String getDefaultMotifFontSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        String font = ((MFontConfiguration) getFontConfiguration()).getMotifFontSet("sansserif", Font.PLAIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (font != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            while ((i = font.indexOf("%d")) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                font = font.substring(0, i) + "140" + font.substring(i+2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public HashSet<String> getAWTFontPathSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        HashSet<String> fontDirs = new HashSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        short[] scripts = getCoreScripts(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        for (int i = 0; i< scripts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            String path = getString(table_awtfontpaths[scripts[i]]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                int start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                int colon = path.indexOf(':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                while (colon >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    fontDirs.add(path.substring(start, colon));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    start = colon + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    colon = path.indexOf(':', start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                fontDirs.add((start == 0) ? path : path.substring(start));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return fontDirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /* methods for table setup ***********************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    private static HashMap encodingMap = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    private void initTables() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        // encodingMap maps XLFD encoding component to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        // name of corresponding java.nio charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        encodingMap.put("iso8859-1", "ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        encodingMap.put("iso8859-2", "ISO-8859-2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        encodingMap.put("iso8859-4", "ISO-8859-4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        encodingMap.put("iso8859-5", "ISO-8859-5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        encodingMap.put("iso8859-6", "ISO-8859-6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        encodingMap.put("iso8859-7", "ISO-8859-7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        encodingMap.put("iso8859-8", "ISO-8859-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        encodingMap.put("iso8859-9", "ISO-8859-9");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        encodingMap.put("iso8859-13", "ISO-8859-13");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        encodingMap.put("iso8859-15", "ISO-8859-15");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        encodingMap.put("gb2312.1980-0", "sun.awt.motif.X11GB2312");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        if (osName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            // use standard converter on Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            encodingMap.put("gbk-0", "GBK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            encodingMap.put("gbk-0", "sun.awt.motif.X11GBK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        encodingMap.put("gb18030.2000-0", "sun.awt.motif.X11GB18030_0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        encodingMap.put("gb18030.2000-1", "sun.awt.motif.X11GB18030_1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        encodingMap.put("cns11643-1", "sun.awt.motif.X11CNS11643P1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        encodingMap.put("cns11643-2", "sun.awt.motif.X11CNS11643P2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        encodingMap.put("cns11643-3", "sun.awt.motif.X11CNS11643P3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        encodingMap.put("big5-1", "Big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        encodingMap.put("big5-0", "Big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        encodingMap.put("hkscs-1", "Big5-HKSCS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        encodingMap.put("ansi-1251", "windows-1251");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        encodingMap.put("koi8-r", "KOI8-R");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        encodingMap.put("jisx0201.1976-0", "sun.awt.motif.X11JIS0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        encodingMap.put("jisx0208.1983-0", "sun.awt.motif.X11JIS0208");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        encodingMap.put("jisx0212.1990-0", "sun.awt.motif.X11JIS0212");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        encodingMap.put("ksc5601.1987-0", "sun.awt.motif.X11KSC5601");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        encodingMap.put("ksc5601.1992-3", "sun.awt.motif.X11Johab");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        encodingMap.put("tis620.2533-0", "TIS-620");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        encodingMap.put("iso10646-1", "UTF-16BE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
}