jdk/src/share/classes/sun/font/CompositeGlyphMapper.java
author mchung
Tue, 29 Sep 2009 16:03:03 -0700
changeset 3938 ef327bd847c0
parent 3928 be186a33df9b
child 5506 202f599c92aa
permissions -rw-r--r--
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes Summary: Replace calls to Logger with sun.util.logging.PlatformLogger Reviewed-by: prr, art, alexp, dcherepanov, igor, dav, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
/* remember that the API requires a Font use a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * consistent glyph id. for a code point, and this is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * problem if a particular strike uses native scaler sometimes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * and T2K others. That needs to be dealt with somewhere, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * here we can just always get the same glyph code without
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * needing a strike.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * The C implementation would cache the results of anything up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * to the maximum surrogate pair code point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This implementation will not cache as much, since the storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * requirements are not justifiable. Even so it still can use up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * to 216*256*4 bytes of storage per composite font. If an app
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * calls canDisplay on this range for all 20 composite fonts that's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * over 1Mb of cached data. May need to employ WeakReferences if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * this appears to cause problems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public final class CompositeGlyphMapper extends CharToGlyphMapper {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static final int SLOTMASK =  0xff000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final int GLYPHMASK = 0x00ffffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static final int NBLOCKS = 216;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static final int BLOCKSZ = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final int MAXUNICODE = NBLOCKS*BLOCKSZ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    CompositeFont font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    CharToGlyphMapper slotMappers[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    int[][] glyphMaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private boolean hasExcludes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public CompositeGlyphMapper(CompositeFont compFont) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        font = compFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        initMapper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        /* This is often false which saves the overhead of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
         * per-mapped char method call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        hasExcludes = compFont.exclusionRanges != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                      compFont.maxIndices != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public final int compositeGlyphCode(int slot, int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return (slot << 24 | (glyphCode & GLYPHMASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private final void initMapper() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (missingGlyph == CharToGlyphMapper.UNINITIALIZED_GLYPH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            if (glyphMaps == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                glyphMaps = new int[NBLOCKS][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            slotMappers = new CharToGlyphMapper[font.numSlots];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            /* This requires that slot 0 is never empty. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            missingGlyph = font.getSlotFont(0).getMissingGlyphCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            missingGlyph = compositeGlyphCode(0, missingGlyph);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private int getCachedGlyphCode(int unicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (unicode >= MAXUNICODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return UNINITIALIZED_GLYPH; // don't cache surrogates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        int[] gmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if ((gmap = glyphMaps[unicode >> 8]) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            return UNINITIALIZED_GLYPH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return gmap[unicode & 0xff];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private void setCachedGlyphCode(int unicode, int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (unicode >= MAXUNICODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            return;     // don't cache surrogates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        int index0 = unicode >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (glyphMaps[index0] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            glyphMaps[index0] = new int[BLOCKSZ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            for (int i=0;i<BLOCKSZ;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                glyphMaps[index0][i] = UNINITIALIZED_GLYPH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        glyphMaps[index0][unicode & 0xff] = glyphCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private final CharToGlyphMapper getSlotMapper(int slot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        CharToGlyphMapper mapper = slotMappers[slot];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (mapper == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            mapper = font.getSlotFont(slot).getMapper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            slotMappers[slot] = mapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return mapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private final int convertToGlyph(int unicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        for (int slot = 0; slot < font.numSlots; slot++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (!hasExcludes || !font.isExcludedChar(slot, unicode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                CharToGlyphMapper mapper = getSlotMapper(slot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                int glyphCode = mapper.charToGlyph(unicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                if (glyphCode != mapper.getMissingGlyphCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    glyphCode = compositeGlyphCode(slot, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    setCachedGlyphCode(unicode, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    return glyphCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return missingGlyph;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public int getNumGlyphs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        int numGlyphs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        /* The number of glyphs in a composite is affected by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         * exclusion ranges and duplicates (ie the same code point is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         * mapped by two different fonts) and also whether or not to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         * count fallback fonts. A nearly correct answer would be very
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         * expensive to generate. A rough ballpark answer would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         * just count the glyphs in all the slots. However this would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * initialize mappers for all slots when they aren't necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         * needed. For now just use the first slot as JDK 1.4 did.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        for (int slot=0; slot<1 /*font.numSlots*/; slot++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
           CharToGlyphMapper mapper = slotMappers[slot];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
           if (mapper == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
               mapper = font.getSlotFont(slot).getMapper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
               slotMappers[slot] = mapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
           numGlyphs += mapper.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return numGlyphs;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        int glyphCode = getCachedGlyphCode(unicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (glyphCode == UNINITIALIZED_GLYPH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            glyphCode = convertToGlyph(unicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return glyphCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public int charToGlyph(int unicode, int prefSlot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (prefSlot >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            CharToGlyphMapper mapper = getSlotMapper(prefSlot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            int glyphCode = mapper.charToGlyph(unicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (glyphCode != mapper.getMissingGlyphCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                return compositeGlyphCode(prefSlot, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return charToGlyph(unicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public int charToGlyph(char unicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        int glyphCode  = getCachedGlyphCode(unicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (glyphCode == UNINITIALIZED_GLYPH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            glyphCode = convertToGlyph(unicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return glyphCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /* This variant checks if shaping is needed and immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * returns true if it does. A caller of this method should be expecting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * to check the return type because it needs to know how to handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * the character data for display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public boolean charsToGlyphsNS(int count, char[] unicodes, int[] glyphs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            int code = unicodes[i]; // char is unsigned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            if (code >= HI_SURROGATE_START &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                code <= HI_SURROGATE_END && i < count - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                char low = unicodes[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                if (low >= LO_SURROGATE_START &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    low <= LO_SURROGATE_END) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    code = (code - HI_SURROGATE_START) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                        0x400 + low - LO_SURROGATE_START + 0x10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    glyphs[i + 1] = INVISIBLE_GLYPH_ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            int gc = glyphs[i] = getCachedGlyphCode(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if (gc == UNINITIALIZED_GLYPH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                glyphs[i] = convertToGlyph(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   214
            if (code < FontUtilities.MIN_LAYOUT_CHARCODE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   217
            else if (FontUtilities.isComplexCharCode(code)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            else if (code >= 0x10000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                i += 1; // Empty glyph slot after surrogate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /* The conversion is not very efficient - looping as it does, converting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * one char at a time. However the cache should fill very rapidly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public void charsToGlyphs(int count, char[] unicodes, int[] glyphs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            int code = unicodes[i]; // char is unsigned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (code >= HI_SURROGATE_START &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                code <= HI_SURROGATE_END && i < count - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                char low = unicodes[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                if (low >= LO_SURROGATE_START &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    low <= LO_SURROGATE_END) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    code = (code - HI_SURROGATE_START) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                        0x400 + low - LO_SURROGATE_START + 0x10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    int gc = glyphs[i] = getCachedGlyphCode(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    if (gc == UNINITIALIZED_GLYPH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        glyphs[i] = convertToGlyph(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    i += 1; // Empty glyph slot after surrogate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    glyphs[i] = INVISIBLE_GLYPH_ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            int gc = glyphs[i] = getCachedGlyphCode(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            if (gc == UNINITIALIZED_GLYPH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                glyphs[i] = convertToGlyph(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public void charsToGlyphs(int count, int[] unicodes, int[] glyphs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            int code = unicodes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            glyphs[i] = getCachedGlyphCode(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            if (glyphs[i] == UNINITIALIZED_GLYPH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                glyphs[i] = convertToGlyph(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
}