001: /*
002: * Copyright 1996-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package sun.awt;
026:
027: import java.nio.charset.Charset;
028: import java.nio.charset.CharsetEncoder;
029: import sun.nio.cs.HistoricallyNamedCharset;
030:
031: public class FontDescriptor implements Cloneable {
032:
033: static {
034: NativeLibLoader.loadLibraries();
035: initIDs();
036: }
037:
038: String nativeName;
039: public CharsetEncoder encoder;
040: String charsetName;
041: private int[] exclusionRanges;
042:
043: public FontDescriptor(String nativeName, CharsetEncoder encoder,
044: int[] exclusionRanges) {
045:
046: this .nativeName = nativeName;
047: this .encoder = encoder;
048: this .exclusionRanges = exclusionRanges;
049: this .useUnicode = false;
050: Charset cs = encoder.charset();
051: if (cs instanceof HistoricallyNamedCharset)
052: this .charsetName = ((HistoricallyNamedCharset) cs)
053: .historicalName();
054: else
055: this .charsetName = cs.name();
056:
057: }
058:
059: public String getNativeName() {
060: return nativeName;
061: }
062:
063: public CharsetEncoder getFontCharsetEncoder() {
064: return encoder;
065: }
066:
067: public String getFontCharsetName() {
068: return charsetName;
069: }
070:
071: public int[] getExclusionRanges() {
072: return exclusionRanges;
073: }
074:
075: /**
076: * Return true if the character is exclusion character.
077: */
078: public boolean isExcluded(char ch) {
079: for (int i = 0; i < exclusionRanges.length;) {
080:
081: int lo = (exclusionRanges[i++]);
082: int up = (exclusionRanges[i++]);
083:
084: if (ch >= lo && ch <= up) {
085: return true;
086: }
087: }
088: return false;
089: }
090:
091: public String toString() {
092: return super .toString() + " [" + nativeName + "|" + encoder
093: + "]";
094: }
095:
096: /**
097: * Initialize JNI field and method IDs
098: */
099: private static native void initIDs();
100:
101: public CharsetEncoder unicodeEncoder;
102: boolean useUnicode; // set to true from native code on Unicode-based systems
103:
104: public boolean useUnicode() {
105: if (useUnicode && unicodeEncoder == null) {
106: try {
107: this .unicodeEncoder = isLE ? Charset
108: .forName("UTF_16LE").newEncoder() : Charset
109: .forName("UTF_16BE").newEncoder();
110: } catch (IllegalArgumentException x) {
111: }
112: }
113: return useUnicode;
114: }
115:
116: static boolean isLE;
117: static {
118: String enc = (String) java.security.AccessController
119: .doPrivileged(new sun.security.action.GetPropertyAction(
120: "sun.io.unicode.encoding", "UnicodeBig"));
121: isLE = !"UnicodeBig".equals(enc);
122: }
123: }
|