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