Path: blob/master/src/java.desktop/share/classes/sun/awt/Symbol.java
41152 views
/*1* Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt;2627import java.nio.ByteBuffer;28import java.nio.CharBuffer;29import java.nio.charset.*;3031public class Symbol extends Charset {32public Symbol () {33super("Symbol", null);34}35public CharsetEncoder newEncoder() {36return new Encoder(this);37}3839/* Seems like supporting a decoder is required, but we aren't going40* to be publically exposing this class, so no need to waste work41*/42public CharsetDecoder newDecoder() {43throw new Error("Decoder is not implemented for Symbol Charset");44}4546public boolean contains(Charset cs) {47return cs instanceof Symbol;48}4950private static class Encoder extends CharsetEncoder {51public Encoder(Charset cs) {52super(cs, 1.0f, 1.0f);53}5455public boolean canEncode(char c) {56if (c >= 0x2200 && c <= 0x22ef) {57if (table_math[c - 0x2200] != 0x00) {58return true;59}60} else if (c >= 0x0391 && c <= 0x03d6) {61if (table_greek[c - 0x0391] != 0x00) {62return true;63}64}65return false;66}6768protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {69char[] sa = src.array();70int sp = src.arrayOffset() + src.position();71int sl = src.arrayOffset() + src.limit();72assert (sp <= sl);73sp = (sp <= sl ? sp : sl);74byte[] da = dst.array();75int dp = dst.arrayOffset() + dst.position();76int dl = dst.arrayOffset() + dst.limit();77assert (dp <= dl);78dp = (dp <= dl ? dp : dl);7980try {81while (sp < sl) {82char c = sa[sp];83if (dl - dp < 1)84return CoderResult.OVERFLOW;85if (!canEncode(c))86return CoderResult.unmappableForLength(1);87sp++;88if (c >= 0x2200 && c <= 0x22ef){89da[dp++] = table_math[c - 0x2200];90} else if (c >= 0x0391 && c <= 0x03d6) {91da[dp++]= table_greek[c - 0x0391];92}93}94return CoderResult.UNDERFLOW;95} finally {96src.position(sp - src.arrayOffset());97dst.position(dp - dst.arrayOffset());98}99}100101private static byte[] table_math = {102(byte)0042, (byte)0000, (byte)0144, (byte)0044,103(byte)0000, (byte)0306, (byte)0104, (byte)0321, // 00104(byte)0316, (byte)0317, (byte)0000, (byte)0000,105(byte)0000, (byte)0047, (byte)0000, (byte)0120,106(byte)0000, (byte)0345, (byte)0055, (byte)0000,107(byte)0000, (byte)0244, (byte)0000, (byte)0052, // 10108(byte)0260, (byte)0267, (byte)0326, (byte)0000,109(byte)0000, (byte)0265, (byte)0245, (byte)0000,110(byte)0000, (byte)0000, (byte)0000, (byte)0275,111(byte)0000, (byte)0000, (byte)0000, (byte)0331, // 20112(byte)0332, (byte)0307, (byte)0310, (byte)0362,113(byte)0000, (byte)0000, (byte)0000, (byte)0000,114(byte)0000, (byte)0000, (byte)0000, (byte)0000,115(byte)0134, (byte)0000, (byte)0000, (byte)0000, // 30116(byte)0000, (byte)0000, (byte)0000, (byte)0000,117(byte)0176, (byte)0000, (byte)0000, (byte)0000,118(byte)0000, (byte)0000, (byte)0000, (byte)0000,119(byte)0000, (byte)0100, (byte)0000, (byte)0000, // 40120(byte)0273, (byte)0000, (byte)0000, (byte)0000,121(byte)0000, (byte)0000, (byte)0000, (byte)0000,122(byte)0000, (byte)0000, (byte)0000, (byte)0000,123(byte)0000, (byte)0000, (byte)0000, (byte)0000, // 50124(byte)0000, (byte)0000, (byte)0000, (byte)0000,125(byte)0000, (byte)0000, (byte)0000, (byte)0000,126(byte)0271, (byte)0272, (byte)0000, (byte)0000,127(byte)0243, (byte)0263, (byte)0000, (byte)0000, // 60128(byte)0000, (byte)0000, (byte)0000, (byte)0000,129(byte)0000, (byte)0000, (byte)0000, (byte)0000,130(byte)0000, (byte)0000, (byte)0000, (byte)0000,131(byte)0000, (byte)0000, (byte)0000, (byte)0000, // 70132(byte)0000, (byte)0000, (byte)0000, (byte)0000,133(byte)0000, (byte)0000, (byte)0000, (byte)0000,134(byte)0000, (byte)0000, (byte)0314, (byte)0311,135(byte)0313, (byte)0000, (byte)0315, (byte)0312, // 80136(byte)0000, (byte)0000, (byte)0000, (byte)0000,137(byte)0000, (byte)0000, (byte)0000, (byte)0000,138(byte)0000, (byte)0000, (byte)0000, (byte)0000,139(byte)0000, (byte)0305, (byte)0000, (byte)0304, // 90140(byte)0000, (byte)0000, (byte)0000, (byte)0000,141(byte)0000, (byte)0000, (byte)0000, (byte)0000,142(byte)0000, (byte)0000, (byte)0000, (byte)0000,143(byte)0000, (byte)0136, (byte)0000, (byte)0000, // a0144(byte)0000, (byte)0000, (byte)0000, (byte)0000,145(byte)0000, (byte)0000, (byte)0000, (byte)0000,146(byte)0000, (byte)0000, (byte)0000, (byte)0000,147(byte)0000, (byte)0000, (byte)0000, (byte)0000, // b0148(byte)0000, (byte)0000, (byte)0000, (byte)0000,149(byte)0000, (byte)0000, (byte)0000, (byte)0000,150(byte)0000, (byte)0000, (byte)0000, (byte)0000,151(byte)0340, (byte)0327, (byte)0000, (byte)0000, // c0152(byte)0000, (byte)0000, (byte)0000, (byte)0000,153(byte)0000, (byte)0000, (byte)0000, (byte)0000,154(byte)0000, (byte)0000, (byte)0000, (byte)0000,155(byte)0000, (byte)0000, (byte)0000, (byte)0000, // d0156(byte)0000, (byte)0000, (byte)0000, (byte)0000,157(byte)0000, (byte)0000, (byte)0000, (byte)0000,158(byte)0000, (byte)0000, (byte)0000, (byte)0000,159(byte)0000, (byte)0000, (byte)0000, (byte)0000, // e0160(byte)0000, (byte)0000, (byte)0000, (byte)0000,161(byte)0000, (byte)0000, (byte)0000, (byte)0274,162};163164private static byte[] table_greek = {165(byte)0101, (byte)0102, (byte)0107,166(byte)0104, (byte)0105, (byte)0132, (byte)0110, // 90167(byte)0121, (byte)0111, (byte)0113, (byte)0114,168(byte)0115, (byte)0116, (byte)0130, (byte)0117,169(byte)0120, (byte)0122, (byte)0000, (byte)0123,170(byte)0124, (byte)0125, (byte)0106, (byte)0103, // a0171(byte)0131, (byte)0127, (byte)0000, (byte)0000,172(byte)0000, (byte)0000, (byte)0000, (byte)0000,173(byte)0000, (byte)0141, (byte)0142, (byte)0147,174(byte)0144, (byte)0145, (byte)0172, (byte)0150, // b0175(byte)0161, (byte)0151, (byte)0153, (byte)0154,176(byte)0155, (byte)0156, (byte)0170, (byte)0157,177(byte)0160, (byte)0162, (byte)0126, (byte)0163,178(byte)0164, (byte)0165, (byte)0146, (byte)0143, // c0179(byte)0171, (byte)0167, (byte)0000, (byte)0000,180(byte)0000, (byte)0000, (byte)0000, (byte)0000,181(byte)0000, (byte)0112, (byte)0241, (byte)0000,182(byte)0000, (byte)0152, (byte)0166, // d0183};184185/* The default implementation creates a decoder and we don't have one */186public boolean isLegalReplacement(byte[] repl) {187return true;188}189}190}191192193