Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/motif/X11Dingbats.java
32288 views
/*1* Copyright (c) 1996, 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.motif;2627import java.nio.ByteBuffer;28import java.nio.CharBuffer;29import java.nio.charset.*;3031public class X11Dingbats extends Charset {32public X11Dingbats () {33super("X11Dingbats", null);34}3536public CharsetEncoder newEncoder() {37return new Encoder(this);38}3940/* Seems like supporting a decoder is required, but we aren't going41* to be publically exposing this class, so no need to waste work42*/43public CharsetDecoder newDecoder() {44throw new Error("Decoder is not supported by X11Dingbats Charset");45}4647public boolean contains(Charset cs) {48return cs instanceof X11Dingbats;49}5051private static class Encoder extends CharsetEncoder {52public Encoder(Charset cs) {53super(cs, 1.0f, 1.0f);54}5556public boolean canEncode(char ch) {57if (ch >= 0x2701 && ch <= 0x275e) { // direct map58return true;59}60if (ch >= 0x2761 && ch <= 0x27be) {61return (table[ch - 0x2761] != 0x00);62}63return false;64}6566protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {67char[] sa = src.array();68int sp = src.arrayOffset() + src.position();69int sl = src.arrayOffset() + src.limit();70assert (sp <= sl);71sp = (sp <= sl ? sp : sl);72byte[] da = dst.array();73int dp = dst.arrayOffset() + dst.position();74int dl = dst.arrayOffset() + dst.limit();75assert (dp <= dl);76dp = (dp <= dl ? dp : dl);7778try {79while (sp < sl) {80char c = sa[sp];81if (dl - dp < 1)82return CoderResult.OVERFLOW;8384if (!canEncode(c))85return CoderResult.unmappableForLength(1);86sp++;87if (c >= 0x2761){88da[dp++] = table[c - 0x2761]; // table lookup89} else {90da[dp++] = (byte)(c + 0x20 - 0x2700); // direct map91}92}93return CoderResult.UNDERFLOW;94} finally {95src.position(sp - src.arrayOffset());96dst.position(dp - dst.arrayOffset());97}98}99100private static byte[] table = {101(byte)0xa1, (byte)0xa2, (byte)0xa3, (byte)0xa4,102(byte)0xa5, (byte)0xa6, (byte)0xa7,103(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,104(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,105(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,106(byte)0x00, (byte)0x00, (byte)0xb6, (byte)0xb7,107(byte)0xb8, (byte)0xb9, (byte)0xba, (byte)0xbb,108(byte)0xbc, (byte)0xbd, (byte)0xbe, (byte)0xbf,109(byte)0xc0, (byte)0xc1, (byte)0xc2, (byte)0xc3,110(byte)0xc4, (byte)0xc5, (byte)0xc6, (byte)0xc7,111(byte)0xc8, (byte)0xc9, (byte)0xca, (byte)0xcb,112(byte)0xcc, (byte)0xcd, (byte)0xce, (byte)0xcf,113(byte)0xd0, (byte)0xd1, (byte)0xd2, (byte)0xd3,114(byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00,115(byte)0xd8, (byte)0xd9, (byte)0xda, (byte)0xdb,116(byte)0xdc, (byte)0xdd, (byte)0xde, (byte)0x00,117(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,118(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,119(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,120(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,121(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,122(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,123(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,124(byte)0x00, (byte)0x00, (byte)0x00};125126/* The default implementation creates a decoder and we don't have one */127public boolean isLegalReplacement(byte[] repl) {128return true;129}130}131}132133134