Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/awt/FontDescriptor.java
38827 views
/*1* Copyright (c) 1996, 2011, 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*/24package sun.awt;2526import java.nio.charset.Charset;27import java.nio.charset.CharsetEncoder;28import java.nio.charset.StandardCharsets;29import sun.nio.cs.HistoricallyNamedCharset;3031public class FontDescriptor implements Cloneable {3233static {34NativeLibLoader.loadLibraries();35initIDs();36}3738String nativeName;39public CharsetEncoder encoder;40String charsetName;41private int[] exclusionRanges;4243public FontDescriptor(String nativeName, CharsetEncoder encoder,44int[] exclusionRanges){4546this.nativeName = nativeName;47this.encoder = encoder;48this.exclusionRanges = exclusionRanges;49this.useUnicode = false;50Charset cs = encoder.charset();51if (cs instanceof HistoricallyNamedCharset)52this.charsetName = ((HistoricallyNamedCharset)cs).historicalName();53else54this.charsetName = cs.name();5556}5758public String getNativeName() {59return nativeName;60}6162public CharsetEncoder getFontCharsetEncoder() {63return encoder;64}6566public String getFontCharsetName() {67return charsetName;68}6970public int[] getExclusionRanges() {71return exclusionRanges;72}7374/**75* Return true if the character is exclusion character.76*/77public boolean isExcluded(char ch){78for (int i = 0; i < exclusionRanges.length; ){7980int lo = (exclusionRanges[i++]);81int up = (exclusionRanges[i++]);8283if (ch >= lo && ch <= up){84return true;85}86}87return false;88}8990public String toString() {91return super.toString() + " [" + nativeName + "|" + encoder + "]";92}9394/**95* Initialize JNI field and method IDs96*/97private static native void initIDs();9899100public CharsetEncoder unicodeEncoder;101boolean useUnicode; // set to true from native code on Unicode-based systems102103public boolean useUnicode() {104if (useUnicode && unicodeEncoder == null) {105try {106this.unicodeEncoder = isLE?107StandardCharsets.UTF_16LE.newEncoder():108StandardCharsets.UTF_16BE.newEncoder();109} catch (IllegalArgumentException x) {}110}111return useUnicode;112}113static boolean isLE;114static {115String enc = (String) java.security.AccessController.doPrivileged(116new sun.security.action.GetPropertyAction("sun.io.unicode.encoding",117"UnicodeBig"));118isLE = !"UnicodeBig".equals(enc);119}120}121122123