jdk/src/solaris/classes/sun/awt/motif/MFontConfiguration.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7948 6711180a6212
child 11093 e753252dc8a9
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7948
diff changeset
     2
 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.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;
7948
6711180a6212 7013646: remove obsolete fontconfig files for linux and solaris
prr
parents: 5506
diff changeset
   169
                if ((f = new File("/etc/fedora-release")).canRead()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    osName = "Fedora";
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/redhat-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    osName = "RedHat";
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/turbolinux-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    osName = "Turbo";
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/SuSE-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    osName = "SuSE";
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/lsb-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    /* Ubuntu and (perhaps others) use only lsb-release.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                     * Syntax and encoding is compatible with java properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                     * For Ubuntu the ID is "Ubuntu".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    Properties props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    props.load(new FileInputStream(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    osName = props.getProperty("DISTRIB_ID");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    osVersion =  props.getProperty("DISTRIB_RELEASE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Gets the OS version string from a Linux release-specific file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private String getVersionString(File f){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            Scanner sc  = new Scanner(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        catch (Exception e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    private static final String fontsDirPrefix = "$JRE_LIB_FONTS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    protected String mapFileName(String fileName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (fileName != null && fileName.startsWith(fontsDirPrefix)) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   214
            return SunFontManager.jreFontDirName
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    + fileName.substring(fontsDirPrefix.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    // overrides FontConfiguration.getFallbackFamilyName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public String getFallbackFamilyName(String fontName, String defaultFallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        // maintain compatibility with old font.properties files, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        // either had aliases for TimesRoman & Co. or defined mappings for them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        String compatibilityName = getCompatibilityFamilyName(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (compatibilityName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return compatibilityName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return defaultFallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    protected String getEncoding(String awtFontName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            String characterSubsetName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        // extract encoding field from XLFD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        int beginIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        int fieldNum = 13; // charset registry field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        while (fieldNum-- > 0 && beginIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            beginIndex = awtFontName.indexOf("-", beginIndex) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (beginIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return "default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        String xlfdEncoding = awtFontName.substring(beginIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (xlfdEncoding.indexOf("fontspecific") > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if (awtFontName.indexOf("dingbats") > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                return "sun.awt.motif.X11Dingbats";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            } else if (awtFontName.indexOf("symbol") > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                return "sun.awt.Symbol";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        String encoding = (String) encodingMap.get(xlfdEncoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (encoding == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            encoding = "default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    protected Charset getDefaultFontCharset(String fontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return Charset.forName("ISO8859_1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /* methods for Motif support *********************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    private String[][] motifFontSets = new String[NUM_FONTS][NUM_STYLES];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public String getMotifFontSet(String fontName, int style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        assert isLogicalFontFamilyName(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        fontName = fontName.toLowerCase(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        int fontIndex = getFontIndex(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        int styleIndex = getStyleIndex(style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return getMotifFontSet(fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private String getMotifFontSet(int fontIndex, int styleIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        String fontSet = motifFontSets[fontIndex][styleIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (fontSet == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            fontSet = buildMotifFontSet(fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            motifFontSets[fontIndex][styleIndex] = fontSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return fontSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private String buildMotifFontSet(int fontIndex, int styleIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        StringBuilder buffer = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        short[] scripts = getCoreScripts(fontIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        for (int i = 0; i < scripts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            short nameID = getComponentFontIDMotif(scripts[i], fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            if (nameID == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                nameID = getComponentFontID(scripts[i], fontIndex, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            String name = getComponentFontName(nameID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (name == null || name.endsWith("fontspecific")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if (buffer.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                buffer.append(',');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            buffer.append(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return buffer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    protected String getFaceNameFromComponentFontName(String componentFontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    protected String getFileNameFromComponentFontName(String componentFontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // for X11, component font name is XLFD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        // if we have a file name already, just use it; otherwise let's see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        // what the graphics environment can provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        String fileName = getFileNameFromPlatformName(componentFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (fileName != null && fileName.charAt(0) == '/' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            !needToSearchForFile(fileName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   315
        return ((X11FontManager) fontManager).getFileNameFromXLFD(componentFontName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Get default font for Motif widgets to use, preventing them from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * wasting time accessing inappropriate X resources.  This is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * only from native code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * This is part of a Motif specific performance enhancement.  By
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * default, when Motif widgets are created and initialized, Motif will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * set up default fonts for the widgets, which we ALWAYS override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * This set up includes finding the default font in the widget's X
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * resources and fairly expensive requests of the X server to identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * the specific font or fontset.  We avoid all of this overhead by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * providing a well known font to use at the creation of widgets, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * The X11 fonts are specified by XLFD strings which have %d as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * marker to indicate where the fontsize should be substituted.  [The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * libc function sprintf() is used to replace it.]  The value 140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * specifies a font size of 14 points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    private static String getDefaultMotifFontSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        String font = ((MFontConfiguration) getFontConfiguration()).getMotifFontSet("sansserif", Font.PLAIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (font != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            while ((i = font.indexOf("%d")) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                font = font.substring(0, i) + "140" + font.substring(i+2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public HashSet<String> getAWTFontPathSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        HashSet<String> fontDirs = new HashSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        short[] scripts = getCoreScripts(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        for (int i = 0; i< scripts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            String path = getString(table_awtfontpaths[scripts[i]]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                int start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                int colon = path.indexOf(':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                while (colon >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    fontDirs.add(path.substring(start, colon));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    start = colon + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    colon = path.indexOf(':', start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                fontDirs.add((start == 0) ? path : path.substring(start));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return fontDirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /* methods for table setup ***********************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    private static HashMap encodingMap = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    private void initTables() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        // encodingMap maps XLFD encoding component to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        // name of corresponding java.nio charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        encodingMap.put("iso8859-1", "ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        encodingMap.put("iso8859-2", "ISO-8859-2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        encodingMap.put("iso8859-4", "ISO-8859-4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        encodingMap.put("iso8859-5", "ISO-8859-5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        encodingMap.put("iso8859-6", "ISO-8859-6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        encodingMap.put("iso8859-7", "ISO-8859-7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        encodingMap.put("iso8859-8", "ISO-8859-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        encodingMap.put("iso8859-9", "ISO-8859-9");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        encodingMap.put("iso8859-13", "ISO-8859-13");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        encodingMap.put("iso8859-15", "ISO-8859-15");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        encodingMap.put("gb2312.1980-0", "sun.awt.motif.X11GB2312");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if (osName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            // use standard converter on Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            encodingMap.put("gbk-0", "GBK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            encodingMap.put("gbk-0", "sun.awt.motif.X11GBK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        encodingMap.put("gb18030.2000-0", "sun.awt.motif.X11GB18030_0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        encodingMap.put("gb18030.2000-1", "sun.awt.motif.X11GB18030_1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        encodingMap.put("cns11643-1", "sun.awt.motif.X11CNS11643P1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        encodingMap.put("cns11643-2", "sun.awt.motif.X11CNS11643P2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        encodingMap.put("cns11643-3", "sun.awt.motif.X11CNS11643P3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        encodingMap.put("big5-1", "Big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        encodingMap.put("big5-0", "Big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        encodingMap.put("hkscs-1", "Big5-HKSCS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        encodingMap.put("ansi-1251", "windows-1251");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        encodingMap.put("koi8-r", "KOI8-R");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        encodingMap.put("jisx0201.1976-0", "sun.awt.motif.X11JIS0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        encodingMap.put("jisx0208.1983-0", "sun.awt.motif.X11JIS0208");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        encodingMap.put("jisx0212.1990-0", "sun.awt.motif.X11JIS0212");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        encodingMap.put("ksc5601.1987-0", "sun.awt.motif.X11KSC5601");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        encodingMap.put("ksc5601.1992-3", "sun.awt.motif.X11Johab");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        encodingMap.put("tis620.2533-0", "TIS-620");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        encodingMap.put("iso10646-1", "UTF-16BE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
}