jdk/src/java.desktop/share/classes/sun/font/TrueTypeGlyphMapper.java
author ddehaven
Tue, 19 Aug 2014 10:32:16 -0700
changeset 26037 508779ce6619
parent 26020 jdk/src/share/classes/sun/font/TrueTypeGlyphMapper.java@68deef2ad1c9
parent 25859 jdk/src/share/classes/sun/font/TrueTypeGlyphMapper.java@3317bb8137f4
child 40139 76f3dc8c0c28
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     2
 * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
public class TrueTypeGlyphMapper extends CharToGlyphMapper {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    static final char REVERSE_SOLIDUS = 0x005c; // the backslash char.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    static final char JA_YEN = 0x00a5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    static final char JA_FULLWIDTH_TILDE_CHAR = 0xff5e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    static final char JA_WAVE_DASH_CHAR = 0x301c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /* if running on Solaris and default Locale is ja_JP then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * we map need to remap reverse solidus (backslash) to Yen as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * apparently expected there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static final boolean isJAlocale = Locale.JAPAN.equals(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private final boolean needsJAremapping;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private boolean remapJAWaveDash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    TrueTypeFont font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    CMap cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    int numGlyphs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public TrueTypeGlyphMapper(TrueTypeFont font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        this.font = font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            cmap = CMap.initialize(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            cmap = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        if (cmap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            handleBadCMAP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        missingGlyph = 0; /* standard for TrueType fonts */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        ByteBuffer buffer = font.getTableBuffer(TrueTypeFont.maxpTag);
26020
68deef2ad1c9 8052396: Catch exceptions resulting from missing font cmap
prr
parents: 24527
diff changeset
    62
        if (buffer != null && buffer.capacity() >= 6) {
68deef2ad1c9 8052396: Catch exceptions resulting from missing font cmap
prr
parents: 24527
diff changeset
    63
            numGlyphs = buffer.getChar(4); // offset 4 bytes in MAXP table.
68deef2ad1c9 8052396: Catch exceptions resulting from missing font cmap
prr
parents: 24527
diff changeset
    64
        } else {
68deef2ad1c9 8052396: Catch exceptions resulting from missing font cmap
prr
parents: 24527
diff changeset
    65
            handleBadCMAP();
68deef2ad1c9 8052396: Catch exceptions resulting from missing font cmap
prr
parents: 24527
diff changeset
    66
        }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    67
        if (FontUtilities.isSolaris && isJAlocale && font.supportsJA()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            needsJAremapping = true;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    69
            if (FontUtilities.isSolaris8 &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                getGlyphFromCMAP(JA_WAVE_DASH_CHAR) == missingGlyph) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                remapJAWaveDash = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            needsJAremapping = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public int getNumGlyphs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return numGlyphs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private char getGlyphFromCMAP(int charCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            char glyphCode = cmap.getGlyph(charCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            if (glyphCode < numGlyphs ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                glyphCode >= FileFontStrike.INVISIBLE_GLYPHS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                return glyphCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            } else {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    89
                if (FontUtilities.isLogging()) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    90
                    FontUtilities.getLogger().warning
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                        (font + " out of range glyph id=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                         Integer.toHexString((int)glyphCode) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                         " for char " + Integer.toHexString(charCode));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                return (char)missingGlyph;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            handleBadCMAP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            return (char) missingGlyph;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private void handleBadCMAP() {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   104
        if (FontUtilities.isLogging()) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   105
            FontUtilities.getLogger().severe("Null Cmap for " + font +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                      "substituting for this font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   108
        SunFontManager.getInstance().deRegisterBadFont(font);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        /* The next line is not really a solution, but might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         * reduce the exceptions until references to this font2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         * are gone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        cmap = CMap.theNullCmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
24527
779f94d50411 8039862: Fix fallthrough lint warnings in 2d
darcy
parents: 5506
diff changeset
   116
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private final char remapJAChar(char unicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        switch (unicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        case REVERSE_SOLIDUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            return JA_YEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            /* This is a workaround for bug 4533422.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
             * Japanese wave dash missing from Solaris JA TrueType fonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        case JA_WAVE_DASH_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            if (remapJAWaveDash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                return JA_FULLWIDTH_TILDE_CHAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        default: return unicode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
24527
779f94d50411 8039862: Fix fallthrough lint warnings in 2d
darcy
parents: 5506
diff changeset
   131
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private final int remapJAIntChar(int unicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        switch (unicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        case REVERSE_SOLIDUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return JA_YEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            /* This is a workaround for bug 4533422.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
             * Japanese wave dash missing from Solaris JA TrueType fonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        case JA_WAVE_DASH_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            if (remapJAWaveDash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                return JA_FULLWIDTH_TILDE_CHAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        default: return unicode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public int charToGlyph(char unicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (needsJAremapping) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            unicode = remapJAChar(unicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        int glyph = getGlyphFromCMAP(unicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (font.checkUseNatives() && glyph < font.glyphToCharMap.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            font.glyphToCharMap[glyph] = unicode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return glyph;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public int charToGlyph(int unicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (needsJAremapping) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            unicode = remapJAIntChar(unicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        int glyph = getGlyphFromCMAP(unicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (font.checkUseNatives() && glyph < font.glyphToCharMap.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            font.glyphToCharMap[glyph] = (char)unicode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return glyph;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public void charsToGlyphs(int count, int[] unicodes, int[] glyphs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        for (int i=0;i<count;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (needsJAremapping) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                glyphs[i] = getGlyphFromCMAP(remapJAIntChar(unicodes[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                glyphs[i] = getGlyphFromCMAP(unicodes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (font.checkUseNatives() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                glyphs[i] < font.glyphToCharMap.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                font.glyphToCharMap[glyphs[i]] = (char)unicodes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public void charsToGlyphs(int count, char[] unicodes, int[] glyphs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            int code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (needsJAremapping) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                code = remapJAChar(unicodes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                code = unicodes[i]; // char is unsigned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if (code >= HI_SURROGATE_START &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                code <= HI_SURROGATE_END && i < count - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                char low = unicodes[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                if (low >= LO_SURROGATE_START &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    low <= LO_SURROGATE_END) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    code = (code - HI_SURROGATE_START) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                        0x400 + low - LO_SURROGATE_START + 0x10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    glyphs[i] = getGlyphFromCMAP(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    i += 1; // Empty glyph slot after surrogate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    glyphs[i] = INVISIBLE_GLYPH_ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            glyphs[i] = getGlyphFromCMAP(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if (font.checkUseNatives() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                glyphs[i] < font.glyphToCharMap.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                font.glyphToCharMap[glyphs[i]] = (char)code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /* This variant checks if shaping is needed and immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * returns true if it does. A caller of this method should be expecting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * to check the return type because it needs to know how to handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * the character data for display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public boolean charsToGlyphsNS(int count, char[] unicodes, int[] glyphs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            int code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if (needsJAremapping) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                code = remapJAChar(unicodes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                code = unicodes[i]; // char is unsigned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            if (code >= HI_SURROGATE_START &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                code <= HI_SURROGATE_END && i < count - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                char low = unicodes[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                if (low >= LO_SURROGATE_START &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    low <= LO_SURROGATE_END) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    code = (code - HI_SURROGATE_START) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        0x400 + low - LO_SURROGATE_START + 0x10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    glyphs[i + 1] = INVISIBLE_GLYPH_ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            glyphs[i] = getGlyphFromCMAP(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            if (font.checkUseNatives() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                glyphs[i] < font.glyphToCharMap.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                font.glyphToCharMap[glyphs[i]] = (char)code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   251
            if (code < FontUtilities.MIN_LAYOUT_CHARCODE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   254
            else if (FontUtilities.isComplexCharCode(code)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            else if (code >= 0x10000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                i += 1; // Empty glyph slot after surrogate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /* A pretty good heuristic is that the cmap we are using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * supports 32 bit character codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    boolean hasSupplementaryChars() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            cmap instanceof CMap.CMapFormat8 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            cmap instanceof CMap.CMapFormat10 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            cmap instanceof CMap.CMapFormat12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}