1 /* 2 * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package sun.awt; 26 27 import java.nio.charset.Charset; 28 import java.nio.charset.CharsetEncoder; 29 import sun.nio.cs.HistoricallyNamedCharset; 30 31 public class FontDescriptor implements Cloneable { 32 33 static { 34 NativeLibLoader.loadLibraries(); 35 initIDs(); 36 } 37 38 String nativeName; 39 public CharsetEncoder encoder; 40 String charsetName; 41 private int[] exclusionRanges; 42 43 public FontDescriptor(String nativeName, CharsetEncoder encoder, 44 int[] exclusionRanges){ 45 46 this.nativeName = nativeName; 47 this.encoder = encoder; 48 this.exclusionRanges = exclusionRanges; 49 this.useUnicode = false; 50 Charset cs = encoder.charset(); 51 if (cs instanceof HistoricallyNamedCharset) 52 this.charsetName = ((HistoricallyNamedCharset)cs).historicalName(); 53 else 54 this.charsetName = cs.name(); 55 56 } 57 58 public String getNativeName() { 59 return nativeName; 60 } 61 62 public CharsetEncoder getFontCharsetEncoder() { 63 return encoder; 64 } 65 66 public String getFontCharsetName() { 67 return charsetName; 68 } 69 70 public int[] getExclusionRanges() { 71 return exclusionRanges; 72 } 73 74 /** 75 * Return true if the character is exclusion character. 76 */ 77 public boolean isExcluded(char ch){ 78 for (int i = 0; i < exclusionRanges.length; ){ 79 80 int lo = (exclusionRanges[i++]); 81 int up = (exclusionRanges[i++]); 82 83 if (ch >= lo && ch <= up){ 84 return true; 85 } 86 } 87 return false; 88 } 89 90 public String toString() { 91 return super.toString() + " [" + nativeName + "|" + encoder + "]"; 92 } 93 94 /** 95 * Initialize JNI field and method IDs 96 */ 97 private static native void initIDs(); 98 99 100 public CharsetEncoder unicodeEncoder; 101 boolean useUnicode; // set to true from native code on Unicode-based systems 102 103 public boolean useUnicode() { 104 if (useUnicode && unicodeEncoder == null) { 105 try { 106 this.unicodeEncoder = isLE? 107 Charset.forName("UTF_16LE").newEncoder(): 108 Charset.forName("UTF_16BE").newEncoder(); 109 } catch (IllegalArgumentException x) {} 110 } 111 return useUnicode; 112 } 113 static boolean isLE; 114 static { 115 String enc = (String) java.security.AccessController.doPrivileged( 116 new sun.security.action.GetPropertyAction("sun.io.unicode.encoding", 117 "UnicodeBig")); 118 isLE = !"UnicodeBig".equals(enc); 119 } 120 }