Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/motif/MFontConfiguration.java
32288 views
/*1* Copyright (c) 2000, 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*/2425package sun.awt.motif;2627import sun.awt.FontConfiguration;28import sun.awt.X11FontManager;29import sun.font.FontUtilities;30import sun.font.SunFontManager;31import sun.util.logging.PlatformLogger;3233import java.io.File;34import java.io.FileInputStream;35import java.nio.charset.Charset;36import java.util.HashMap;37import java.util.HashSet;38import java.util.Properties;39import java.util.Scanner;4041public class MFontConfiguration extends FontConfiguration {4243private static FontConfiguration fontConfig = null;44private static PlatformLogger logger;4546public MFontConfiguration(SunFontManager fm) {47super(fm);48if (FontUtilities.debugFonts()) {49logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");50}51initTables();52}535455public MFontConfiguration(SunFontManager fm,56boolean preferLocaleFonts,57boolean preferPropFonts) {58super(fm, preferLocaleFonts, preferPropFonts);59if (FontUtilities.debugFonts()) {60logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");61}62initTables();63}6465/* Needs to be kept in sync with updates in the languages used in66* the fontconfig files.67*/68protected void initReorderMap() {69reorderMap = new HashMap();70if (osName == null) { /* null means SunOS */71initReorderMapForSolaris();72} else {73initReorderMapForLinux();74}75}7677private void initReorderMapForSolaris() {78/* Don't create a no-op entry, so we can optimize this case79* i.e. we don't need to do anything so can avoid slower paths in80* the code.81*/82// reorderMap.put("UTF-8", "latin-1");83reorderMap.put("UTF-8.hi", "devanagari"); // NB is in Lucida.84reorderMap.put("UTF-8.ja",85split("japanese-x0201,japanese-x0208,japanese-x0212"));86reorderMap.put("UTF-8.ko", "korean-johab");87reorderMap.put("UTF-8.th", "thai");88reorderMap.put("UTF-8.zh.TW", "chinese-big5");89reorderMap.put("UTF-8.zh.HK", split("chinese-big5,chinese-hkscs"));90if (FontUtilities.isSolaris8) {91reorderMap.put("UTF-8.zh.CN", split("chinese-gb2312,chinese-big5"));92} else {93reorderMap.put("UTF-8.zh.CN",94split("chinese-gb18030-0,chinese-gb18030-1"));95}96reorderMap.put("UTF-8.zh",97split("chinese-big5,chinese-hkscs,chinese-gb18030-0,chinese-gb18030-1"));98reorderMap.put("Big5", "chinese-big5");99reorderMap.put("Big5-HKSCS", split("chinese-big5,chinese-hkscs"));100if (! FontUtilities.isSolaris8 && ! FontUtilities.isSolaris9) {101reorderMap.put("GB2312", split("chinese-gbk,chinese-gb2312"));102} else {103reorderMap.put("GB2312","chinese-gb2312");104}105reorderMap.put("x-EUC-TW",106split("chinese-cns11643-1,chinese-cns11643-2,chinese-cns11643-3"));107reorderMap.put("GBK", "chinese-gbk");108reorderMap.put("GB18030",split("chinese-gb18030-0,chinese-gb18030-1"));109110reorderMap.put("TIS-620", "thai");111reorderMap.put("x-PCK",112split("japanese-x0201,japanese-x0208,japanese-x0212"));113reorderMap.put("x-eucJP-Open",114split("japanese-x0201,japanese-x0208,japanese-x0212"));115reorderMap.put("EUC-KR", "korean");116/* Don't create a no-op entry, so we can optimize this case */117// reorderMap.put("ISO-8859-1", "latin-1");118reorderMap.put("ISO-8859-2", "latin-2");119reorderMap.put("ISO-8859-5", "cyrillic-iso8859-5");120reorderMap.put("windows-1251", "cyrillic-cp1251");121reorderMap.put("KOI8-R", "cyrillic-koi8-r");122reorderMap.put("ISO-8859-6", "arabic");123reorderMap.put("ISO-8859-7", "greek");124reorderMap.put("ISO-8859-8", "hebrew");125reorderMap.put("ISO-8859-9", "latin-5");126reorderMap.put("ISO-8859-13", "latin-7");127reorderMap.put("ISO-8859-15", "latin-9");128}129130private void initReorderMapForLinux() {131reorderMap.put("UTF-8.ja.JP", "japanese-iso10646");132reorderMap.put("UTF-8.ko.KR", "korean-iso10646");133reorderMap.put("UTF-8.zh.TW", "chinese-tw-iso10646");134reorderMap.put("UTF-8.zh.HK", "chinese-tw-iso10646");135reorderMap.put("UTF-8.zh.CN", "chinese-cn-iso10646");136reorderMap.put("x-euc-jp-linux",137split("japanese-x0201,japanese-x0208"));138reorderMap.put("GB2312", "chinese-gb18030");139reorderMap.put("Big5", "chinese-big5");140reorderMap.put("EUC-KR", "korean");141if (osName.equals("Sun")){142reorderMap.put("GB18030", "chinese-cn-iso10646");143}144else {145reorderMap.put("GB18030", "chinese-gb18030");146}147}148149/**150* Sets the OS name and version from environment information.151*/152protected void setOsNameAndVersion(){153super.setOsNameAndVersion();154155if (osName.equals("SunOS")) {156//don't care os name on Solaris157osName = null;158} else if (osName.equals("Linux")) {159try {160File f;161if ((f = new File("/etc/fedora-release")).canRead()) {162osName = "Fedora";163osVersion = getVersionString(f);164} else if ((f = new File("/etc/redhat-release")).canRead()) {165osName = "RedHat";166osVersion = getVersionString(f);167} else if ((f = new File("/etc/turbolinux-release")).canRead()) {168osName = "Turbo";169osVersion = getVersionString(f);170} else if ((f = new File("/etc/SuSE-release")).canRead()) {171osName = "SuSE";172osVersion = getVersionString(f);173} else if ((f = new File("/etc/lsb-release")).canRead()) {174/* Ubuntu and (perhaps others) use only lsb-release.175* Syntax and encoding is compatible with java properties.176* For Ubuntu the ID is "Ubuntu".177*/178Properties props = new Properties();179props.load(new FileInputStream(f));180osName = props.getProperty("DISTRIB_ID");181osVersion = props.getProperty("DISTRIB_RELEASE");182}183} catch (Exception e) {184}185}186return;187}188189/**190* Gets the OS version string from a Linux release-specific file.191*/192private String getVersionString(File f){193try {194Scanner sc = new Scanner(f);195return sc.findInLine("(\\d)+((\\.)(\\d)+)*");196}197catch (Exception e){198}199return null;200}201202private static final String fontsDirPrefix = "$JRE_LIB_FONTS";203204protected String mapFileName(String fileName) {205if (fileName != null && fileName.startsWith(fontsDirPrefix)) {206return SunFontManager.jreFontDirName207+ fileName.substring(fontsDirPrefix.length());208}209return fileName;210}211212// overrides FontConfiguration.getFallbackFamilyName213public String getFallbackFamilyName(String fontName, String defaultFallback) {214// maintain compatibility with old font.properties files, which215// either had aliases for TimesRoman & Co. or defined mappings for them.216String compatibilityName = getCompatibilityFamilyName(fontName);217if (compatibilityName != null) {218return compatibilityName;219}220return defaultFallback;221}222223protected String getEncoding(String awtFontName,224String characterSubsetName) {225// extract encoding field from XLFD226int beginIndex = 0;227int fieldNum = 13; // charset registry field228while (fieldNum-- > 0 && beginIndex >= 0) {229beginIndex = awtFontName.indexOf("-", beginIndex) + 1;230}231if (beginIndex == -1) {232return "default";233}234String xlfdEncoding = awtFontName.substring(beginIndex);235if (xlfdEncoding.indexOf("fontspecific") > 0) {236if (awtFontName.indexOf("dingbats") > 0) {237return "sun.awt.motif.X11Dingbats";238} else if (awtFontName.indexOf("symbol") > 0) {239return "sun.awt.Symbol";240}241}242String encoding = (String) encodingMap.get(xlfdEncoding);243if (encoding == null) {244encoding = "default";245}246return encoding;247}248249protected Charset getDefaultFontCharset(String fontName) {250return Charset.forName("ISO8859_1");251}252253protected String getFaceNameFromComponentFontName(String componentFontName) {254return null;255}256257protected String getFileNameFromComponentFontName(String componentFontName) {258// for X11, component font name is XLFD259// if we have a file name already, just use it; otherwise let's see260// what the graphics environment can provide261String fileName = getFileNameFromPlatformName(componentFontName);262if (fileName != null && fileName.charAt(0) == '/' &&263!needToSearchForFile(fileName)) {264return fileName;265}266return ((X11FontManager) fontManager).getFileNameFromXLFD(componentFontName);267}268269public HashSet<String> getAWTFontPathSet() {270HashSet<String> fontDirs = new HashSet<String>();271short[] scripts = getCoreScripts(0);272for (int i = 0; i< scripts.length; i++) {273String path = getString(table_awtfontpaths[scripts[i]]);274if (path != null) {275int start = 0;276int colon = path.indexOf(':');277while (colon >= 0) {278fontDirs.add(path.substring(start, colon));279start = colon + 1;280colon = path.indexOf(':', start);281}282fontDirs.add((start == 0) ? path : path.substring(start));283}284}285return fontDirs;286}287288/* methods for table setup ***********************************************/289290private static HashMap encodingMap = new HashMap();291292private void initTables() {293// encodingMap maps XLFD encoding component to294// name of corresponding java.nio charset295encodingMap.put("iso8859-1", "ISO-8859-1");296encodingMap.put("iso8859-2", "ISO-8859-2");297encodingMap.put("iso8859-4", "ISO-8859-4");298encodingMap.put("iso8859-5", "ISO-8859-5");299encodingMap.put("iso8859-6", "ISO-8859-6");300encodingMap.put("iso8859-7", "ISO-8859-7");301encodingMap.put("iso8859-8", "ISO-8859-8");302encodingMap.put("iso8859-9", "ISO-8859-9");303encodingMap.put("iso8859-13", "ISO-8859-13");304encodingMap.put("iso8859-15", "ISO-8859-15");305encodingMap.put("gb2312.1980-0", "sun.awt.motif.X11GB2312");306if (osName == null) {307// use standard converter on Solaris308encodingMap.put("gbk-0", "GBK");309} else {310encodingMap.put("gbk-0", "sun.awt.motif.X11GBK");311}312encodingMap.put("gb18030.2000-0", "sun.awt.motif.X11GB18030_0");313encodingMap.put("gb18030.2000-1", "sun.awt.motif.X11GB18030_1");314encodingMap.put("cns11643-1", "sun.awt.motif.X11CNS11643P1");315encodingMap.put("cns11643-2", "sun.awt.motif.X11CNS11643P2");316encodingMap.put("cns11643-3", "sun.awt.motif.X11CNS11643P3");317encodingMap.put("big5-1", "Big5");318encodingMap.put("big5-0", "Big5");319encodingMap.put("hkscs-1", "Big5-HKSCS");320encodingMap.put("ansi-1251", "windows-1251");321encodingMap.put("koi8-r", "KOI8-R");322encodingMap.put("jisx0201.1976-0", "sun.awt.motif.X11JIS0201");323encodingMap.put("jisx0208.1983-0", "sun.awt.motif.X11JIS0208");324encodingMap.put("jisx0212.1990-0", "sun.awt.motif.X11JIS0212");325encodingMap.put("ksc5601.1987-0", "sun.awt.motif.X11KSC5601");326encodingMap.put("ksc5601.1992-3", "sun.awt.motif.X11Johab");327encodingMap.put("tis620.2533-0", "TIS-620");328encodingMap.put("iso10646-1", "UTF-16BE");329}330331}332333334