jdk/src/solaris/classes/sun/font/XMap.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
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: 2
diff changeset
     2
 * Copyright (c) 2003, 2005, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.awt.FontFormatException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.font.FontRenderContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.GeneralPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.nio.charset.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.nio.CharBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
class XMap {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static HashMap xMappers = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /* ConvertedGlyphs has unicode code points as indexes and values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * are platform-encoded multi-bytes chars packed into java chars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * These platform-encoded characters are equated to glyph ids, although
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * that's not strictly true, as X11 only supports using chars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * The assumption carried over from the native implementation that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * a char is big enough to hold an X11 glyph id (ie platform char).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    char[] convertedGlyphs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static synchronized XMap getXMapper(String encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        XMap mapper = (XMap)xMappers.get(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        if (mapper == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            mapper = getXMapperInternal(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            xMappers.put(encoding, mapper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return mapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static final int SINGLE_BYTE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static final int DOUBLE_BYTE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static XMap getXMapperInternal(String encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        String jclass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        int nBytes = SINGLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        int maxU = 0xffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        int minU = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        boolean addAscii = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        boolean lowPartOnly = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        if (encoding.equals("dingbats")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            jclass = "sun.awt.motif.X11Dingbats";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            minU = 0x2701;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            maxU = 0x27be;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        } else if (encoding.equals("symbol")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            jclass = "sun.awt.Symbol";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            minU = 0x0391;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            maxU = 0x22ef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        } else if (encoding.equals("iso8859-1")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            maxU = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        } else if (encoding.equals("iso8859-2")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            jclass = "ISO8859_2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        } else if (encoding.equals("jisx0208.1983-0")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            jclass = "sun.awt.motif.X11JIS0208";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        } else if (encoding.equals("jisx0201.1976-0")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            jclass = "sun.awt.motif.X11JIS0201";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            // this is mapping the latin supplement range 128->255 which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            // doesn't exist in JIS0201. This needs examination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            // it was also overwriting a couple of the mappings of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            // 7E and A5 which in JIS201 are different chars than in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            // Latin 1. I have revised AddAscii to not overwrite chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            // which are already converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            addAscii = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            lowPartOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        } else if (encoding.equals("jisx0212.1990-0")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            jclass = "sun.awt.motif.X11JIS0212";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        } else if (encoding.equals("iso8859-4")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            jclass = "ISO8859_4";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        } else if (encoding.equals("iso8859-5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            jclass = "ISO8859_5";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        } else if (encoding.equals("koi8-r")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            jclass = "KOI8_R";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        } else if (encoding.equals("ansi-1251")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            jclass = "windows-1251";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } else if (encoding.equals("iso8859-6")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            jclass = "ISO8859_6";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        } else if (encoding.equals("iso8859-7")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            jclass = "ISO8859_7";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        } else if (encoding.equals("iso8859-8")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            jclass = "ISO8859_8";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } else if (encoding.equals("iso8859-9")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            jclass = "ISO8859_9";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } else if (encoding.equals("iso8859-13")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            jclass = "ISO8859_13";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        } else if (encoding.equals("iso8859-15")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            jclass = "ISO8859_15";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        } else if (encoding.equals("ksc5601.1987-0")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            jclass ="sun.awt.motif.X11KSC5601";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        } else if (encoding.equals( "ksc5601.1992-3")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            jclass ="sun.awt.motif.X11Johab";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        } else if (encoding.equals( "ksc5601.1987-1")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            jclass ="EUC_KR";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } else if (encoding.equals( "cns11643-1")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            jclass = "sun.awt.motif.X11CNS11643P1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } else if (encoding.equals("cns11643-2")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            jclass = "sun.awt.motif.X11CNS11643P2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } else if (encoding.equals("cns11643-3")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            jclass = "sun.awt.motif.X11CNS11643P3";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        } else if (encoding.equals("gb2312.1980-0")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            jclass = "sun.awt.motif.X11GB2312";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        } else if (encoding.indexOf("big5") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            jclass = "Big5";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            addAscii = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        } else if (encoding.equals("tis620.2533-0")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            jclass = "TIS620";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } else if (encoding.equals("gbk-0")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            jclass = "sun.awt.motif.X11GBK";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        } else if (encoding.indexOf("sun.unicode-0") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            jclass = "sun.awt.motif.X11SunUnicode_0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } else if (encoding.indexOf("gb18030.2000-1") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            jclass = "sun.awt.motif.X11GB18030_1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        } else if (encoding.indexOf( "gb18030.2000-0") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            jclass = "sun.awt.motif.X11GB18030_0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        } else if (encoding.indexOf("hkscs") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            jclass = "sun.awt.HKSCS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            nBytes = DOUBLE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return new XMap(jclass, minU, maxU, nBytes, addAscii, lowPartOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private static final char SURR_MIN = '\uD800';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private static final char SURR_MAX = '\uDFFF';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private XMap(String className, int minU, int maxU, int nBytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                 boolean addAscii, boolean lowPartOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        CharsetEncoder enc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (className != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                if (className.startsWith("sun.awt")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    enc = ((Charset)Class.forName(className).newInstance()).newEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    enc = Charset.forName(className).newEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            } catch (Exception x) {x.printStackTrace();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (enc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            convertedGlyphs = new char[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            for (int i=0; i<256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                convertedGlyphs[i] = (char)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            /* chars is set to the unicode values to convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
             * bytes is where the X11 character codes will be output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
             * Finally we pack the byte pairs into chars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            int count = maxU - minU + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            byte[] bytes = new byte[count*nBytes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            char[] chars  = new char[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                chars[i] = (char)(minU+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            int startCharIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            /* For multi-byte encodings, single byte chars should be skipped */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            if (nBytes > SINGLE_BYTE && minU < 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                startCharIndex = 256-minU;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            byte[] rbytes = new byte[nBytes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                int cbLen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                int bbLen = 0;
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   207
                // Since we don't support surrogates in any X11 encoding, skip
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                // the surrogate area, otherwise the sequence of "Oxdbff0xdc00"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                // will accidently cause the surrogate-aware nio charset to treat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                // them as a legal pair and then undesirablly skip 2 "chars"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                // for one "unmappable character"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                if (startCharIndex < SURR_MIN && startCharIndex + count >SURR_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    cbLen = SURR_MIN - startCharIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    bbLen = cbLen * nBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    enc.onMalformedInput(CodingErrorAction.REPLACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                        .onUnmappableCharacter(CodingErrorAction.REPLACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        .replaceWith(rbytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                        .encode(CharBuffer.wrap(chars, startCharIndex, cbLen),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                ByteBuffer.wrap(bytes, startCharIndex * nBytes, bbLen),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    startCharIndex = SURR_MAX + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                cbLen = count - startCharIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                bbLen = cbLen * nBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                enc.onMalformedInput(CodingErrorAction.REPLACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    .onUnmappableCharacter(CodingErrorAction.REPLACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    .replaceWith(rbytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    .encode(CharBuffer.wrap(chars, startCharIndex, cbLen),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                            ByteBuffer.wrap(bytes, startCharIndex * nBytes, bbLen),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                            true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            } catch (Exception e) { e.printStackTrace();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            convertedGlyphs = new char[65536];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                if (nBytes == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    convertedGlyphs[i+minU] = (char)(bytes[i]&0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    convertedGlyphs[i+minU] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        (char)(((bytes[i*2]&0xff) << 8) + (bytes[i*2+1]&0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        int max = (lowPartOnly) ? 128 : 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (addAscii && convertedGlyphs.length >= 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            for (int i=0;i<max;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                if (convertedGlyphs[i] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    convertedGlyphs[i] = (char)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
}