jdk/src/share/classes/sun/font/FontUtilities.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8357 7da1b1af2da0
child 12047 320a714614e9
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:
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8357
diff changeset
     2
 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     4
 *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
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: 4826
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4826
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    10
 *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    15
 * accompanied this code).
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    16
 *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4826
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4826
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4826
diff changeset
    23
 * questions.
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    24
 */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    25
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    26
package sun.font;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    27
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    28
import java.awt.Font;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    29
import java.io.BufferedReader;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    30
import java.io.File;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    31
import java.io.FileInputStream;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    32
import java.io.InputStreamReader;
8357
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
    33
import java.lang.ref.SoftReference;
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
    34
import java.util.concurrent.ConcurrentHashMap;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    35
import java.security.AccessController;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    36
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    37
import java.security.PrivilegedAction;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    38
import javax.swing.plaf.FontUIResource;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    39
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3929
diff changeset
    40
import sun.util.logging.PlatformLogger;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    41
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    42
/**
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    43
 * A collection of utility methods.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    44
 */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    45
public final class FontUtilities {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    46
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    47
    public static boolean isSolaris;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    48
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    49
    public static boolean isLinux;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    50
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    51
    public static boolean isSolaris8;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    52
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    53
    public static boolean isSolaris9;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    54
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    55
    public static boolean isOpenSolaris;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    56
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    57
    public static boolean useT2K;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    58
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    59
    public static boolean isWindows;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    60
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    61
    public static boolean isOpenJDK;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    62
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    63
    static final String LUCIDA_FILE_NAME = "LucidaSansRegular.ttf";
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    64
5939
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
    65
    private static boolean debugFonts = false;
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
    66
    private static PlatformLogger logger = null;
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
    67
    private static boolean logging;
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
    68
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    69
    // This static initializer block figures out the OS constants.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    70
    static {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    71
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    72
        AccessController.doPrivileged(new PrivilegedAction () {
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    73
            public Object run() {
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    74
                String osName = System.getProperty("os.name", "unknownOS");
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    75
                isSolaris = osName.startsWith("SunOS");
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    76
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    77
                isLinux = osName.startsWith("Linux");
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    78
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    79
                String t2kStr = System.getProperty("sun.java2d.font.scaler");
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    80
                if (t2kStr != null) {
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    81
                    useT2K = "t2k".equals(t2kStr);
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    82
                } else {
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    83
                    useT2K = false;
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    84
                }
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    85
                if (isSolaris) {
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    86
                    String version = System.getProperty("os.version", "0.0");
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    87
                    isSolaris8 = version.startsWith("5.8");
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    88
                    isSolaris9 = version.startsWith("5.9");
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    89
                    float ver = Float.parseFloat(version);
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    90
                    if (ver > 5.10f) {
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    91
                        File f = new File("/etc/release");
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    92
                        String line = null;
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    93
                        try {
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    94
                            FileInputStream fis = new FileInputStream(f);
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    95
                            InputStreamReader isr = new InputStreamReader(
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
    96
                                                            fis, "ISO-8859-1");
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    97
                            BufferedReader br = new BufferedReader(isr);
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    98
                            line = br.readLine();
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
    99
                            fis.close();
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   100
                        } catch (Exception ex) {
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   101
                            // Nothing to do here.
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   102
                        }
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   103
                        if (line != null && line.indexOf("OpenSolaris") >= 0) {
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   104
                            isOpenSolaris = true;
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   105
                        } else {
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   106
                            isOpenSolaris = false;
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   107
                        }
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   108
                    } else {
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   109
                        isOpenSolaris = false;
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   110
                    }
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   111
                } else {
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   112
                    isSolaris8 = false;
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   113
                    isSolaris9 = false;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   114
                    isOpenSolaris = false;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   115
                }
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   116
                isWindows = osName.startsWith("Windows");
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   117
                String jreLibDirName = System.getProperty("java.home", "")
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   118
                                                      + File.separator + "lib";
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   119
                String jreFontDirName =
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   120
                        jreLibDirName + File.separator + "fonts";
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   121
                File lucidaFile = new File(jreFontDirName + File.separator
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   122
                                           + LUCIDA_FILE_NAME);
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   123
                isOpenJDK = !lucidaFile.exists();
5939
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   124
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   125
                String debugLevel =
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   126
                    System.getProperty("sun.java2d.debugfonts");
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   127
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   128
                if (debugLevel != null && !debugLevel.equals("false")) {
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   129
                    debugFonts = true;
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   130
                    logger = PlatformLogger.getLogger("sun.java2d");
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   131
                    if (debugLevel.equals("warning")) {
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   132
                        logger.setLevel(PlatformLogger.WARNING);
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   133
                    } else if (debugLevel.equals("severe")) {
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   134
                        logger.setLevel(PlatformLogger.SEVERE);
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   135
                    }
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   136
                }
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   137
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   138
                if (debugFonts) {
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   139
                    logger = PlatformLogger.getLogger("sun.java2d");
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   140
                    logging = logger.isEnabled();
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   141
                }
1882d33f2c60 6968373: FontUtilities static initializer throws AccessControlException
igor
parents: 5506
diff changeset
   142
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   143
                return null;
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   144
            }
4826
878c0606a10c 6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
rkennke
parents: 3938
diff changeset
   145
        });
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   146
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   147
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   148
    /**
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   149
     * Referenced by code in the JDK which wants to test for the
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   150
     * minimum char code for which layout may be required.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   151
     * Note that even basic latin text can benefit from ligatures,
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   152
     * eg "ffi" but we presently apply those only if explicitly
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   153
     * requested with TextAttribute.LIGATURES_ON.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   154
     * The value here indicates the lowest char code for which failing
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   155
     * to invoke layout would prevent acceptable rendering.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   156
     */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   157
    public static final int MIN_LAYOUT_CHARCODE = 0x0300;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   158
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   159
    /**
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   160
     * Referenced by code in the JDK which wants to test for the
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   161
     * maximum char code for which layout may be required.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   162
     * Note this does not account for supplementary characters
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   163
     * where the caller interprets 'layout' to mean any case where
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   164
     * one 'char' (ie the java type char) does not map to one glyph
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   165
     */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   166
    public static final int MAX_LAYOUT_CHARCODE = 0x206F;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   167
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   168
    /**
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   169
     * Calls the private getFont2D() method in java.awt.Font objects.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   170
     *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   171
     * @param font the font object to call
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   172
     *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   173
     * @return the Font2D object returned by Font.getFont2D()
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   174
     */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   175
    public static Font2D getFont2D(Font font) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   176
        return FontAccess.getFontAccess().getFont2D(font);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   177
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   178
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   179
    /**
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   180
     * If there is anything in the text which triggers a case
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   181
     * where char->glyph does not map 1:1 in straightforward
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   182
     * left->right ordering, then this method returns true.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   183
     * Scripts which might require it but are not treated as such
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   184
     * due to JDK implementations will not return true.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   185
     * ie a 'true' return is an indication of the treatment by
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   186
     * the implementation.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   187
     * Whether supplementary characters should be considered is dependent
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   188
     * on the needs of the caller. Since this method accepts the 'char' type
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   189
     * then such chars are always represented by a pair. From a rendering
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   190
     * perspective these will all (in the cases I know of) still be one
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   191
     * unicode character -> one glyph. But if a caller is using this to
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   192
     * discover any case where it cannot make naive assumptions about
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   193
     * the number of chars, and how to index through them, then it may
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   194
     * need the option to have a 'true' return in such a case.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   195
     */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   196
    public static boolean isComplexText(char [] chs, int start, int limit) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   197
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   198
        for (int i = start; i < limit; i++) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   199
            if (chs[i] < MIN_LAYOUT_CHARCODE) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   200
                continue;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   201
            }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   202
            else if (isNonSimpleChar(chs[i])) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   203
                return true;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   204
            }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   205
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   206
        return false;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   207
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   208
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   209
    /* This is almost the same as the method above, except it takes a
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   210
     * char which means it may include undecoded surrogate pairs.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   211
     * The distinction is made so that code which needs to identify all
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   212
     * cases in which we do not have a simple mapping from
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   213
     * char->unicode character->glyph can be be identified.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   214
     * For example measurement cannot simply sum advances of 'chars',
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   215
     * the caret in editable text cannot advance one 'char' at a time, etc.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   216
     * These callers really are asking for more than whether 'layout'
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   217
     * needs to be run, they need to know if they can assume 1->1
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   218
     * char->glyph mapping.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   219
     */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   220
    public static boolean isNonSimpleChar(char ch) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   221
        return
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   222
            isComplexCharCode(ch) ||
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   223
            (ch >= CharToGlyphMapper.HI_SURROGATE_START &&
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   224
             ch <= CharToGlyphMapper.LO_SURROGATE_END);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   225
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   226
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   227
    /* If the character code falls into any of a number of unicode ranges
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   228
     * where we know that simple left->right layout mapping chars to glyphs
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   229
     * 1:1 and accumulating advances is going to produce incorrect results,
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   230
     * we want to know this so the caller can use a more intelligent layout
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   231
     * approach. A caller who cares about optimum performance may want to
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   232
     * check the first case and skip the method call if its in that range.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   233
     * Although there's a lot of tests in here, knowing you can skip
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   234
     * CTL saves a great deal more. The rest of the checks are ordered
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   235
     * so that rather than checking explicitly if (>= start & <= end)
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   236
     * which would mean all ranges would need to be checked so be sure
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   237
     * CTL is not needed, the method returns as soon as it recognises
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   238
     * the code point is outside of a CTL ranges.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   239
     * NOTE: Since this method accepts an 'int' it is asssumed to properly
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   240
     * represent a CHARACTER. ie it assumes the caller has already
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   241
     * converted surrogate pairs into supplementary characters, and so
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   242
     * can handle this case and doesn't need to be told such a case is
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   243
     * 'complex'.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   244
     */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   245
    public static boolean isComplexCharCode(int code) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   246
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   247
        if (code < MIN_LAYOUT_CHARCODE || code > MAX_LAYOUT_CHARCODE) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   248
            return false;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   249
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   250
        else if (code <= 0x036f) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   251
            // Trigger layout for combining diacriticals 0x0300->0x036f
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   252
            return true;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   253
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   254
        else if (code < 0x0590) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   255
            // No automatic layout for Greek, Cyrillic, Armenian.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   256
             return false;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   257
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   258
        else if (code <= 0x06ff) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   259
            // Hebrew 0590 - 05ff
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   260
            // Arabic 0600 - 06ff
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   261
            return true;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   262
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   263
        else if (code < 0x0900) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   264
            return false; // Syriac and Thaana
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   265
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   266
        else if (code <= 0x0e7f) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   267
            // if Indic, assume shaping for conjuncts, reordering:
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   268
            // 0900 - 097F Devanagari
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   269
            // 0980 - 09FF Bengali
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   270
            // 0A00 - 0A7F Gurmukhi
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   271
            // 0A80 - 0AFF Gujarati
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   272
            // 0B00 - 0B7F Oriya
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   273
            // 0B80 - 0BFF Tamil
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   274
            // 0C00 - 0C7F Telugu
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   275
            // 0C80 - 0CFF Kannada
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   276
            // 0D00 - 0D7F Malayalam
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   277
            // 0D80 - 0DFF Sinhala
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   278
            // 0E00 - 0E7F if Thai, assume shaping for vowel, tone marks
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   279
            return true;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   280
        }
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   281
        else if (code <  0x0f00) {
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   282
            return false;
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   283
        }
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   284
        else if (code <= 0x0fff) { // U+0F00 - U+0FFF Tibetan
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   285
            return true;
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   286
        }
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   287
        else if (code < 0x1100) {
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   288
            return false;
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   289
        }
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   290
        else if (code < 0x11ff) { // U+1100 - U+11FF Old Hangul
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   291
            return true;
6a36b1ebc620 6886358: layout code update
srl
parents: 6509
diff changeset
   292
        }
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   293
        else if (code < 0x1780) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   294
            return false;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   295
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   296
        else if (code <= 0x17ff) { // 1780 - 17FF Khmer
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   297
            return true;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   298
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   299
        else if (code < 0x200c) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   300
            return false;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   301
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   302
        else if (code <= 0x200d) { //  zwj or zwnj
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   303
            return true;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   304
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   305
        else if (code >= 0x202a && code <= 0x202e) { // directional control
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   306
            return true;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   307
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   308
        else if (code >= 0x206a && code <= 0x206f) { // directional control
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   309
            return true;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   310
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   311
        return false;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   312
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   313
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3929
diff changeset
   314
    public static PlatformLogger getLogger() {
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   315
        return logger;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   316
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   317
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   318
    public static boolean isLogging() {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   319
        return logging;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   320
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   321
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   322
    public static boolean debugFonts() {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   323
        return debugFonts;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   324
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   325
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   326
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   327
    // The following methods are used by Swing.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   328
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   329
    /* Revise the implementation to in fact mean "font is a composite font.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   330
     * This ensures that Swing components will always benefit from the
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   331
     * fall back fonts
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   332
     */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   333
    public static boolean fontSupportsDefaultEncoding(Font font) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   334
        return getFont2D(font) instanceof CompositeFont;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   335
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   336
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   337
    /**
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   338
     * This method is provided for internal and exclusive use by Swing.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   339
     *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   340
     * It may be used in conjunction with fontSupportsDefaultEncoding(Font)
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   341
     * In the event that a desktop properties font doesn't directly
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   342
     * support the default encoding, (ie because the host OS supports
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   343
     * adding support for the current locale automatically for native apps),
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   344
     * then Swing calls this method to get a font which  uses the specified
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   345
     * font for the code points it covers, but also supports this locale
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   346
     * just as the standard composite fonts do.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   347
     * Note: this will over-ride any setting where an application
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   348
     * specifies it prefers locale specific composite fonts.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   349
     * The logic for this, is that this method is used only where the user or
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   350
     * application has specified that the native L&F be used, and that
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   351
     * we should honour that request to use the same font as native apps use.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   352
     *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   353
     * The behaviour of this method is to construct a new composite
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   354
     * Font object that uses the specified physical font as its first
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   355
     * component, and adds all the components of "dialog" as fall back
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   356
     * components.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   357
     * The method currently assumes that only the size and style attributes
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   358
     * are set on the specified font. It doesn't copy the font transform or
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   359
     * other attributes because they aren't set on a font created from
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   360
     * the desktop. This will need to be fixed if use is broadened.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   361
     *
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   362
     * Operations such as Font.deriveFont will work properly on the
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   363
     * font returned by this method for deriving a different point size.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   364
     * Additionally it tries to support a different style by calling
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   365
     * getNewComposite() below. That also supports replacing slot zero
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   366
     * with a different physical font but that is expected to be "rare".
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   367
     * Deriving with a different style is needed because its been shown
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   368
     * that some applications try to do this for Swing FontUIResources.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   369
     * Also operations such as new Font(font.getFontName(..), Font.PLAIN, 14);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   370
     * will NOT yield the same result, as the new underlying CompositeFont
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   371
     * cannot be "looked up" in the font registry.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   372
     * This returns a FontUIResource as that is the Font sub-class needed
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   373
     * by Swing.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   374
     * Suggested usage is something like :
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   375
     * FontUIResource fuir;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   376
     * Font desktopFont = getDesktopFont(..);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   377
     * // NOTE even if fontSupportsDefaultEncoding returns true because
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   378
     * // you get Tahoma and are running in an English locale, you may
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   379
     * // still want to just call getCompositeFontUIResource() anyway
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   380
     * // as only then will you get fallback fonts - eg for CJK.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   381
     * if (FontManager.fontSupportsDefaultEncoding(desktopFont)) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   382
     *   fuir = new FontUIResource(..);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   383
     * } else {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   384
     *   fuir = FontManager.getCompositeFontUIResource(desktopFont);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   385
     * }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   386
     * return fuir;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   387
     */
8357
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   388
    private static volatile
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   389
        SoftReference<ConcurrentHashMap<PhysicalFont, CompositeFont>>
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   390
        compMapRef = new SoftReference(null);
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   391
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   392
    public static FontUIResource getCompositeFontUIResource(Font font) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   393
6509
ea7fb80902b3 6979979: Rounding error in font sizes selected by the GTK Look and Feel
omajid
parents: 5939
diff changeset
   394
        FontUIResource fuir = new FontUIResource(font);
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   395
        Font2D font2D = FontUtilities.getFont2D(font);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   396
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   397
        if (!(font2D instanceof PhysicalFont)) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   398
            /* Swing should only be calling this when a font is obtained
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   399
             * from desktop properties, so should generally be a physical font,
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   400
             * an exception might be for names like "MS Serif" which are
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   401
             * automatically mapped to "Serif", so there's no need to do
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   402
             * anything special in that case. But note that suggested usage
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   403
             * is first to call fontSupportsDefaultEncoding(Font) and this
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   404
             * method should not be called if that were to return true.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   405
             */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   406
             return fuir;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   407
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   408
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   409
        FontManager fm = FontManagerFactory.getInstance();
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   410
        CompositeFont dialog2D =
8357
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   411
          (CompositeFont) fm.findFont2D("dialog", font.getStyle(),
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   412
                                        FontManager.NO_FALLBACK);
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   413
        if (dialog2D == null) { /* shouldn't happen */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   414
            return fuir;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   415
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   416
        PhysicalFont physicalFont = (PhysicalFont)font2D;
8357
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   417
        ConcurrentHashMap<PhysicalFont, CompositeFont> compMap = compMapRef.get();
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   418
        if (compMap == null) { // Its been collected.
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   419
            compMap = new ConcurrentHashMap<PhysicalFont, CompositeFont>();
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   420
            compMapRef = new SoftReference(compMap);
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   421
        }
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   422
        CompositeFont compFont = compMap.get(physicalFont);
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   423
        if (compFont == null) {
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   424
            compFont = new CompositeFont(physicalFont, dialog2D);
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   425
            compMap.put(physicalFont, compFont);
7da1b1af2da0 7019441: No lookup cache for internal composite font creation leads to java heap growth
prr
parents: 7668
diff changeset
   426
        }
3929
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   427
        FontAccess.getFontAccess().setFont2D(fuir, compFont.handle);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   428
        /* marking this as a created font is needed as only created fonts
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   429
         * copy their creator's handles.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   430
         */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   431
        FontAccess.getFontAccess().setCreatedFont(fuir);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   432
        return fuir;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   433
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   434
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   435
   /* A small "map" from GTK/fontconfig names to the equivalent JDK
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   436
    * logical font name.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   437
    */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   438
    private static final String[][] nameMap = {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   439
        {"sans",       "sansserif"},
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   440
        {"sans-serif", "sansserif"},
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   441
        {"serif",      "serif"},
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   442
        {"monospace",  "monospaced"}
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   443
    };
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   444
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   445
    public static String mapFcName(String name) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   446
        for (int i = 0; i < nameMap.length; i++) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   447
            if (name.equals(nameMap[i][0])) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   448
                return nameMap[i][1];
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   449
            }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   450
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   451
        return null;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   452
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   453
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   454
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   455
    /* This is called by Swing passing in a fontconfig family name
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   456
     * such as "sans". In return Swing gets a FontUIResource instance
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   457
     * that has queried fontconfig to resolve the font(s) used for this.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   458
     * Fontconfig will if asked return a list of fonts to give the largest
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   459
     * possible code point coverage.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   460
     * For now we use only the first font returned by fontconfig, and
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   461
     * back it up with the most closely matching JDK logical font.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   462
     * Essentially this means pre-pending what we return now with fontconfig's
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   463
     * preferred physical font. This could lead to some duplication in cases,
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   464
     * if we already included that font later. We probably should remove such
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   465
     * duplicates, but it is not a significant problem. It can be addressed
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   466
     * later as part of creating a Composite which uses more of the
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   467
     * same fonts as fontconfig. At that time we also should pay more
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   468
     * attention to the special rendering instructions fontconfig returns,
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   469
     * such as whether we should prefer embedded bitmaps over antialiasing.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   470
     * There's no way to express that via a Font at present.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   471
     */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   472
    public static FontUIResource getFontConfigFUIR(String fcFamily,
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   473
                                                   int style, int size) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   474
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   475
        String mapped = mapFcName(fcFamily);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   476
        if (mapped == null) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   477
            mapped = "sansserif";
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   478
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   479
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   480
        FontUIResource fuir;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   481
        FontManager fm = FontManagerFactory.getInstance();
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   482
        if (fm instanceof SunFontManager) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   483
            SunFontManager sfm = (SunFontManager) fm;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   484
            fuir = sfm.getFontConfigFUIR(mapped, style, size);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   485
        } else {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   486
            fuir = new FontUIResource(mapped, style, size);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   487
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   488
        return fuir;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   489
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   490
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   491
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   492
    /**
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   493
     * Used by windows printing to assess if a font is likely to
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   494
     * be layout compatible with JDK
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   495
     * TrueType fonts should be, but if they have no GPOS table,
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   496
     * but do have a GSUB table, then they are probably older
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   497
     * fonts GDI handles differently.
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   498
     */
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   499
    public static boolean textLayoutIsCompatible(Font font) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   500
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   501
        Font2D font2D = getFont2D(font);
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   502
        if (font2D instanceof TrueTypeFont) {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   503
            TrueTypeFont ttf = (TrueTypeFont) font2D;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   504
            return
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   505
                ttf.getDirectoryEntry(TrueTypeFont.GSUBTag) == null ||
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   506
                ttf.getDirectoryEntry(TrueTypeFont.GPOSTag) != null;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   507
        } else {
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   508
            return false;
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   509
        }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   510
    }
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   511
de1a48b7aa41 6869705: Missing files of CR6795908, FontManager refactoring
rkennke
parents:
diff changeset
   512
}