Path: blob/master/src/java.desktop/share/classes/sun/awt/FontDescriptor.java
41152 views
/*1* Copyright (c) 1996, 2021, 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.io.ByteArrayOutputStream;27import java.io.OutputStreamWriter;28import java.io.IOException;29import java.nio.charset.Charset;30import java.nio.charset.CharsetEncoder;31import java.nio.charset.StandardCharsets;3233public class FontDescriptor implements Cloneable {3435static {36NativeLibLoader.loadLibraries();37initIDs();38}3940String nativeName;41public CharsetEncoder encoder;42String charsetName;43private int[] exclusionRanges;4445public FontDescriptor(String nativeName, CharsetEncoder encoder,46int[] exclusionRanges){4748this.nativeName = nativeName;49this.encoder = encoder;50this.exclusionRanges = exclusionRanges;51this.useUnicode = false;52Charset cs = encoder.charset();53// The following looks odd but its the only public way to get the54// historical name if one exists and the canonical name otherwise.55try {56OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream(), cs);57this.charsetName = osw.getEncoding();58osw.close();59} catch (IOException ioe) {60}61}6263public String getNativeName() {64return nativeName;65}6667public CharsetEncoder getFontCharsetEncoder() {68return encoder;69}7071public String getFontCharsetName() {72return charsetName;73}7475public int[] getExclusionRanges() {76return exclusionRanges;77}7879/**80* Return true if the character is exclusion character.81*/82public boolean isExcluded(char ch){83for (int i = 0; i < exclusionRanges.length; ){8485int lo = (exclusionRanges[i++]);86int up = (exclusionRanges[i++]);8788if (ch >= lo && ch <= up){89return true;90}91}92return false;93}9495public String toString() {96return super.toString() + " [" + nativeName + "|" + encoder + "]";97}9899/**100* Initialize JNI field and method IDs101*/102private static native void initIDs();103104105public CharsetEncoder unicodeEncoder;106boolean useUnicode; // set to true from native code on Unicode-based systems107108public boolean useUnicode() {109if (useUnicode && unicodeEncoder == null) {110try {111this.unicodeEncoder = isLE?112StandardCharsets.UTF_16LE.newEncoder():113StandardCharsets.UTF_16BE.newEncoder();114} catch (IllegalArgumentException x) {}115}116return useUnicode;117}118static boolean isLE;119static {120@SuppressWarnings("removal")121String enc = java.security.AccessController.doPrivileged(122new sun.security.action.GetPropertyAction("sun.io.unicode.encoding",123"UnicodeBig"));124isLE = !"UnicodeBig".equals(enc);125}126}127128129