jdk/src/java.desktop/unix/classes/sun/font/MFontConfiguration.java
author prr
Mon, 13 Apr 2015 17:06:04 -0700
changeset 30456 2a753e3fc714
parent 25859 jdk/src/java.desktop/unix/classes/sun/awt/motif/MFontConfiguration.java@3317bb8137f4
child 40139 76f3dc8c0c28
permissions -rw-r--r--
8035302: Eliminate dependency on jdk.charsets from 2D font code. Reviewed-by: mchung, alanb, sherman, serb
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
30456
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
    26
package sun.font;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
11093
e753252dc8a9 6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on
serb
parents: 9035
diff changeset
    28
import sun.awt.FontConfiguration;
e753252dc8a9 6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on
serb
parents: 9035
diff changeset
    29
import sun.awt.X11FontManager;
e753252dc8a9 6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on
serb
parents: 9035
diff changeset
    30
import sun.font.FontUtilities;
e753252dc8a9 6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on
serb
parents: 9035
diff changeset
    31
import sun.font.SunFontManager;
e753252dc8a9 6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on
serb
parents: 9035
diff changeset
    32
import sun.util.logging.PlatformLogger;
e753252dc8a9 6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on
serb
parents: 9035
diff changeset
    33
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.FileInputStream;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    36
import java.nio.charset.Charset;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Scanner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class MFontConfiguration extends FontConfiguration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static FontConfiguration fontConfig = null;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    45
    private static PlatformLogger logger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    47
    public MFontConfiguration(SunFontManager fm) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    48
        super(fm);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    49
        if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    50
            logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        initTables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    56
    public MFontConfiguration(SunFontManager fm,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                              boolean preferLocaleFonts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                              boolean preferPropFonts) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    59
        super(fm, preferLocaleFonts, preferPropFonts);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    60
        if (FontUtilities.debugFonts()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    61
            logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        initTables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /* Needs to be kept in sync with updates in the languages used in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * the fontconfig files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected void initReorderMap() {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 11093
diff changeset
    70
        reorderMap = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        if (osName == null) {  /* null means SunOS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            initReorderMapForSolaris();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            initReorderMapForLinux();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private void initReorderMapForSolaris() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        /* Don't create a no-op entry, so we can optimize this case
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
         * i.e. we don't need to do anything so can avoid slower paths in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
         * the code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
//      reorderMap.put("UTF-8", "latin-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        reorderMap.put("UTF-8.hi", "devanagari"); // NB is in Lucida.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        reorderMap.put("UTF-8.ja",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                       split("japanese-x0201,japanese-x0208,japanese-x0212"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        reorderMap.put("UTF-8.ko", "korean-johab");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        reorderMap.put("UTF-8.th", "thai");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        reorderMap.put("UTF-8.zh.TW", "chinese-big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        reorderMap.put("UTF-8.zh.HK", split("chinese-big5,chinese-hkscs"));
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    91
        if (FontUtilities.isSolaris8) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            reorderMap.put("UTF-8.zh.CN", split("chinese-gb2312,chinese-big5"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            reorderMap.put("UTF-8.zh.CN",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                           split("chinese-gb18030-0,chinese-gb18030-1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        reorderMap.put("UTF-8.zh",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                       split("chinese-big5,chinese-hkscs,chinese-gb18030-0,chinese-gb18030-1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        reorderMap.put("Big5", "chinese-big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        reorderMap.put("Big5-HKSCS", split("chinese-big5,chinese-hkscs"));
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   101
        if (! FontUtilities.isSolaris8 && ! FontUtilities.isSolaris9) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            reorderMap.put("GB2312", split("chinese-gbk,chinese-gb2312"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            reorderMap.put("GB2312","chinese-gb2312");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        reorderMap.put("x-EUC-TW",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            split("chinese-cns11643-1,chinese-cns11643-2,chinese-cns11643-3"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        reorderMap.put("GBK", "chinese-gbk");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        reorderMap.put("GB18030",split("chinese-gb18030-0,chinese-gb18030-1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        reorderMap.put("TIS-620", "thai");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        reorderMap.put("x-PCK",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                       split("japanese-x0201,japanese-x0208,japanese-x0212"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        reorderMap.put("x-eucJP-Open",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                       split("japanese-x0201,japanese-x0208,japanese-x0212"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        reorderMap.put("EUC-KR", "korean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        /* Don't create a no-op entry, so we can optimize this case */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
//      reorderMap.put("ISO-8859-1", "latin-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        reorderMap.put("ISO-8859-2", "latin-2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        reorderMap.put("ISO-8859-5", "cyrillic-iso8859-5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        reorderMap.put("windows-1251", "cyrillic-cp1251");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        reorderMap.put("KOI8-R", "cyrillic-koi8-r");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        reorderMap.put("ISO-8859-6", "arabic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        reorderMap.put("ISO-8859-7", "greek");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        reorderMap.put("ISO-8859-8", "hebrew");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        reorderMap.put("ISO-8859-9", "latin-5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        reorderMap.put("ISO-8859-13", "latin-7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        reorderMap.put("ISO-8859-15", "latin-9");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private void initReorderMapForLinux() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        reorderMap.put("UTF-8.ja.JP", "japanese-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        reorderMap.put("UTF-8.ko.KR", "korean-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        reorderMap.put("UTF-8.zh.TW", "chinese-tw-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        reorderMap.put("UTF-8.zh.HK", "chinese-tw-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        reorderMap.put("UTF-8.zh.CN", "chinese-cn-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        reorderMap.put("x-euc-jp-linux",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                        split("japanese-x0201,japanese-x0208"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        reorderMap.put("GB2312", "chinese-gb18030");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        reorderMap.put("Big5", "chinese-big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        reorderMap.put("EUC-KR", "korean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (osName.equals("Sun")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            reorderMap.put("GB18030", "chinese-cn-iso10646");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            reorderMap.put("GB18030", "chinese-gb18030");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Sets the OS name and version from environment information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    protected void setOsNameAndVersion(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        super.setOsNameAndVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (osName.equals("SunOS")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            //don't care os name on Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            osName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        } else if (osName.equals("Linux")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                File f;
7948
6711180a6212 7013646: remove obsolete fontconfig files for linux and solaris
prr
parents: 5506
diff changeset
   162
                if ((f = new File("/etc/fedora-release")).canRead()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    osName = "Fedora";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    osVersion = getVersionString(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                } else if ((f = new File("/etc/redhat-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    osName = "RedHat";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    osVersion = getVersionString(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                } else if ((f = new File("/etc/turbolinux-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    osName = "Turbo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    osVersion = getVersionString(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                } else if ((f = new File("/etc/SuSE-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    osName = "SuSE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    osVersion = getVersionString(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                } else if ((f = new File("/etc/lsb-release")).canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    /* Ubuntu and (perhaps others) use only lsb-release.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                     * Syntax and encoding is compatible with java properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                     * For Ubuntu the ID is "Ubuntu".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    Properties props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    props.load(new FileInputStream(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    osName = props.getProperty("DISTRIB_ID");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    osVersion =  props.getProperty("DISTRIB_RELEASE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Gets the OS version string from a Linux release-specific file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private String getVersionString(File f){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            Scanner sc  = new Scanner(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        catch (Exception e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private static final String fontsDirPrefix = "$JRE_LIB_FONTS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    protected String mapFileName(String fileName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (fileName != null && fileName.startsWith(fontsDirPrefix)) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   207
            return SunFontManager.jreFontDirName
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    + fileName.substring(fontsDirPrefix.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    // overrides FontConfiguration.getFallbackFamilyName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public String getFallbackFamilyName(String fontName, String defaultFallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // maintain compatibility with old font.properties files, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        // either had aliases for TimesRoman & Co. or defined mappings for them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        String compatibilityName = getCompatibilityFamilyName(fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (compatibilityName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return compatibilityName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return defaultFallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    protected String getEncoding(String awtFontName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            String characterSubsetName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        // extract encoding field from XLFD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        int beginIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        int fieldNum = 13; // charset registry field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        while (fieldNum-- > 0 && beginIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            beginIndex = awtFontName.indexOf("-", beginIndex) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (beginIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return "default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        String xlfdEncoding = awtFontName.substring(beginIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (xlfdEncoding.indexOf("fontspecific") > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            if (awtFontName.indexOf("dingbats") > 0) {
30456
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   238
                return "sun.font.X11Dingbats";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            } else if (awtFontName.indexOf("symbol") > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                return "sun.awt.Symbol";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 11093
diff changeset
   243
        String encoding = encodingMap.get(xlfdEncoding);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (encoding == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            encoding = "default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    protected Charset getDefaultFontCharset(String fontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return Charset.forName("ISO8859_1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    protected String getFaceNameFromComponentFontName(String componentFontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    protected String getFileNameFromComponentFontName(String componentFontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // for X11, component font name is XLFD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        // if we have a file name already, just use it; otherwise let's see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        // what the graphics environment can provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        String fileName = getFileNameFromPlatformName(componentFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (fileName != null && fileName.charAt(0) == '/' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            !needToSearchForFile(fileName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   267
        return ((X11FontManager) fontManager).getFileNameFromXLFD(componentFontName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public HashSet<String> getAWTFontPathSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        HashSet<String> fontDirs = new HashSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        short[] scripts = getCoreScripts(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        for (int i = 0; i< scripts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            String path = getString(table_awtfontpaths[scripts[i]]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                int start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                int colon = path.indexOf(':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                while (colon >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    fontDirs.add(path.substring(start, colon));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    start = colon + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    colon = path.indexOf(':', start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                fontDirs.add((start == 0) ? path : path.substring(start));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return fontDirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /* methods for table setup ***********************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 11093
diff changeset
   291
    private static HashMap<String, String> encodingMap = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    private void initTables() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // encodingMap maps XLFD encoding component to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        // name of corresponding java.nio charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        encodingMap.put("iso8859-1", "ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        encodingMap.put("iso8859-2", "ISO-8859-2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        encodingMap.put("iso8859-4", "ISO-8859-4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        encodingMap.put("iso8859-5", "ISO-8859-5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        encodingMap.put("iso8859-6", "ISO-8859-6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        encodingMap.put("iso8859-7", "ISO-8859-7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        encodingMap.put("iso8859-8", "ISO-8859-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        encodingMap.put("iso8859-9", "ISO-8859-9");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        encodingMap.put("iso8859-13", "ISO-8859-13");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        encodingMap.put("iso8859-15", "ISO-8859-15");
30456
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   306
        encodingMap.put("gb2312.1980-0", "sun.font.X11GB2312");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (osName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            // use standard converter on Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            encodingMap.put("gbk-0", "GBK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        } else {
30456
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   311
            encodingMap.put("gbk-0", "sun.font.X11GBK");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
30456
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   313
        encodingMap.put("gb18030.2000-0", "sun.font.X11GB18030_0");
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   314
        encodingMap.put("gb18030.2000-1", "sun.font.X11GB18030_1");
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   315
        encodingMap.put("cns11643-1", "sun.font.X11CNS11643P1");
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   316
        encodingMap.put("cns11643-2", "sun.font.X11CNS11643P2");
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   317
        encodingMap.put("cns11643-3", "sun.font.X11CNS11643P3");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        encodingMap.put("big5-1", "Big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        encodingMap.put("big5-0", "Big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        encodingMap.put("hkscs-1", "Big5-HKSCS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        encodingMap.put("ansi-1251", "windows-1251");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        encodingMap.put("koi8-r", "KOI8-R");
30456
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   323
        encodingMap.put("jisx0201.1976-0", "JIS0201");
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   324
        encodingMap.put("jisx0208.1983-0", "JIS0208");
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   325
        encodingMap.put("jisx0212.1990-0", "JIS0212");
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   326
        encodingMap.put("ksc5601.1987-0", "sun.font.X11KSC5601");
2a753e3fc714 8035302: Eliminate dependency on jdk.charsets from 2D font code.
prr
parents: 25859
diff changeset
   327
        encodingMap.put("ksc5601.1992-3", "sun.font.X11Johab");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        encodingMap.put("tis620.2533-0", "TIS-620");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        encodingMap.put("iso10646-1", "UTF-16BE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
}