PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/src/solaris/classes/sun/awt/motif/MFontConfiguration.java

https://bitbucket.org/adoptopenjdk/jdk8-jdk
Java | 332 lines | 249 code | 27 blank | 56 comment | 51 complexity | d1f59da18bb0b52ffa39db91a7edbfd9 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, BSD-3-Clause
  1. /*
  2. * Copyright (c) 2000, 2011, 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.motif;
  26. import sun.awt.FontConfiguration;
  27. import sun.awt.X11FontManager;
  28. import sun.font.FontUtilities;
  29. import sun.font.SunFontManager;
  30. import sun.util.logging.PlatformLogger;
  31. import java.io.File;
  32. import java.io.FileInputStream;
  33. import java.nio.charset.Charset;
  34. import java.util.HashMap;
  35. import java.util.HashSet;
  36. import java.util.Properties;
  37. import java.util.Scanner;
  38. public class MFontConfiguration extends FontConfiguration {
  39. private static FontConfiguration fontConfig = null;
  40. private static PlatformLogger logger;
  41. public MFontConfiguration(SunFontManager fm) {
  42. super(fm);
  43. if (FontUtilities.debugFonts()) {
  44. logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
  45. }
  46. initTables();
  47. }
  48. public MFontConfiguration(SunFontManager fm,
  49. boolean preferLocaleFonts,
  50. boolean preferPropFonts) {
  51. super(fm, preferLocaleFonts, preferPropFonts);
  52. if (FontUtilities.debugFonts()) {
  53. logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
  54. }
  55. initTables();
  56. }
  57. /* Needs to be kept in sync with updates in the languages used in
  58. * the fontconfig files.
  59. */
  60. protected void initReorderMap() {
  61. reorderMap = new HashMap();
  62. if (osName == null) { /* null means SunOS */
  63. initReorderMapForSolaris();
  64. } else {
  65. initReorderMapForLinux();
  66. }
  67. }
  68. private void initReorderMapForSolaris() {
  69. /* Don't create a no-op entry, so we can optimize this case
  70. * i.e. we don't need to do anything so can avoid slower paths in
  71. * the code.
  72. */
  73. // reorderMap.put("UTF-8", "latin-1");
  74. reorderMap.put("UTF-8.hi", "devanagari"); // NB is in Lucida.
  75. reorderMap.put("UTF-8.ja",
  76. split("japanese-x0201,japanese-x0208,japanese-x0212"));
  77. reorderMap.put("UTF-8.ko", "korean-johab");
  78. reorderMap.put("UTF-8.th", "thai");
  79. reorderMap.put("UTF-8.zh.TW", "chinese-big5");
  80. reorderMap.put("UTF-8.zh.HK", split("chinese-big5,chinese-hkscs"));
  81. if (FontUtilities.isSolaris8) {
  82. reorderMap.put("UTF-8.zh.CN", split("chinese-gb2312,chinese-big5"));
  83. } else {
  84. reorderMap.put("UTF-8.zh.CN",
  85. split("chinese-gb18030-0,chinese-gb18030-1"));
  86. }
  87. reorderMap.put("UTF-8.zh",
  88. split("chinese-big5,chinese-hkscs,chinese-gb18030-0,chinese-gb18030-1"));
  89. reorderMap.put("Big5", "chinese-big5");
  90. reorderMap.put("Big5-HKSCS", split("chinese-big5,chinese-hkscs"));
  91. if (! FontUtilities.isSolaris8 && ! FontUtilities.isSolaris9) {
  92. reorderMap.put("GB2312", split("chinese-gbk,chinese-gb2312"));
  93. } else {
  94. reorderMap.put("GB2312","chinese-gb2312");
  95. }
  96. reorderMap.put("x-EUC-TW",
  97. split("chinese-cns11643-1,chinese-cns11643-2,chinese-cns11643-3"));
  98. reorderMap.put("GBK", "chinese-gbk");
  99. reorderMap.put("GB18030",split("chinese-gb18030-0,chinese-gb18030-1"));
  100. reorderMap.put("TIS-620", "thai");
  101. reorderMap.put("x-PCK",
  102. split("japanese-x0201,japanese-x0208,japanese-x0212"));
  103. reorderMap.put("x-eucJP-Open",
  104. split("japanese-x0201,japanese-x0208,japanese-x0212"));
  105. reorderMap.put("EUC-KR", "korean");
  106. /* Don't create a no-op entry, so we can optimize this case */
  107. // reorderMap.put("ISO-8859-1", "latin-1");
  108. reorderMap.put("ISO-8859-2", "latin-2");
  109. reorderMap.put("ISO-8859-5", "cyrillic-iso8859-5");
  110. reorderMap.put("windows-1251", "cyrillic-cp1251");
  111. reorderMap.put("KOI8-R", "cyrillic-koi8-r");
  112. reorderMap.put("ISO-8859-6", "arabic");
  113. reorderMap.put("ISO-8859-7", "greek");
  114. reorderMap.put("ISO-8859-8", "hebrew");
  115. reorderMap.put("ISO-8859-9", "latin-5");
  116. reorderMap.put("ISO-8859-13", "latin-7");
  117. reorderMap.put("ISO-8859-15", "latin-9");
  118. }
  119. private void initReorderMapForLinux() {
  120. reorderMap.put("UTF-8.ja.JP", "japanese-iso10646");
  121. reorderMap.put("UTF-8.ko.KR", "korean-iso10646");
  122. reorderMap.put("UTF-8.zh.TW", "chinese-tw-iso10646");
  123. reorderMap.put("UTF-8.zh.HK", "chinese-tw-iso10646");
  124. reorderMap.put("UTF-8.zh.CN", "chinese-cn-iso10646");
  125. reorderMap.put("x-euc-jp-linux",
  126. split("japanese-x0201,japanese-x0208"));
  127. reorderMap.put("GB2312", "chinese-gb18030");
  128. reorderMap.put("Big5", "chinese-big5");
  129. reorderMap.put("EUC-KR", "korean");
  130. if (osName.equals("Sun")){
  131. reorderMap.put("GB18030", "chinese-cn-iso10646");
  132. }
  133. else {
  134. reorderMap.put("GB18030", "chinese-gb18030");
  135. }
  136. }
  137. /**
  138. * Sets the OS name and version from environment information.
  139. */
  140. protected void setOsNameAndVersion(){
  141. super.setOsNameAndVersion();
  142. if (osName.equals("SunOS")) {
  143. //don't care os name on Solaris
  144. osName = null;
  145. } else if (osName.equals("Linux")) {
  146. try {
  147. File f;
  148. if ((f = new File("/etc/fedora-release")).canRead()) {
  149. osName = "Fedora";
  150. osVersion = getVersionString(f);
  151. } else if ((f = new File("/etc/redhat-release")).canRead()) {
  152. osName = "RedHat";
  153. osVersion = getVersionString(f);
  154. } else if ((f = new File("/etc/turbolinux-release")).canRead()) {
  155. osName = "Turbo";
  156. osVersion = getVersionString(f);
  157. } else if ((f = new File("/etc/SuSE-release")).canRead()) {
  158. osName = "SuSE";
  159. osVersion = getVersionString(f);
  160. } else if ((f = new File("/etc/lsb-release")).canRead()) {
  161. /* Ubuntu and (perhaps others) use only lsb-release.
  162. * Syntax and encoding is compatible with java properties.
  163. * For Ubuntu the ID is "Ubuntu".
  164. */
  165. Properties props = new Properties();
  166. props.load(new FileInputStream(f));
  167. osName = props.getProperty("DISTRIB_ID");
  168. osVersion = props.getProperty("DISTRIB_RELEASE");
  169. }
  170. } catch (Exception e) {
  171. }
  172. }
  173. return;
  174. }
  175. /**
  176. * Gets the OS version string from a Linux release-specific file.
  177. */
  178. private String getVersionString(File f){
  179. try {
  180. Scanner sc = new Scanner(f);
  181. return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
  182. }
  183. catch (Exception e){
  184. }
  185. return null;
  186. }
  187. private static final String fontsDirPrefix = "$JRE_LIB_FONTS";
  188. protected String mapFileName(String fileName) {
  189. if (fileName != null && fileName.startsWith(fontsDirPrefix)) {
  190. return SunFontManager.jreFontDirName
  191. + fileName.substring(fontsDirPrefix.length());
  192. }
  193. return fileName;
  194. }
  195. // overrides FontConfiguration.getFallbackFamilyName
  196. public String getFallbackFamilyName(String fontName, String defaultFallback) {
  197. // maintain compatibility with old font.properties files, which
  198. // either had aliases for TimesRoman & Co. or defined mappings for them.
  199. String compatibilityName = getCompatibilityFamilyName(fontName);
  200. if (compatibilityName != null) {
  201. return compatibilityName;
  202. }
  203. return defaultFallback;
  204. }
  205. protected String getEncoding(String awtFontName,
  206. String characterSubsetName) {
  207. // extract encoding field from XLFD
  208. int beginIndex = 0;
  209. int fieldNum = 13; // charset registry field
  210. while (fieldNum-- > 0 && beginIndex >= 0) {
  211. beginIndex = awtFontName.indexOf("-", beginIndex) + 1;
  212. }
  213. if (beginIndex == -1) {
  214. return "default";
  215. }
  216. String xlfdEncoding = awtFontName.substring(beginIndex);
  217. if (xlfdEncoding.indexOf("fontspecific") > 0) {
  218. if (awtFontName.indexOf("dingbats") > 0) {
  219. return "sun.awt.motif.X11Dingbats";
  220. } else if (awtFontName.indexOf("symbol") > 0) {
  221. return "sun.awt.Symbol";
  222. }
  223. }
  224. String encoding = (String) encodingMap.get(xlfdEncoding);
  225. if (encoding == null) {
  226. encoding = "default";
  227. }
  228. return encoding;
  229. }
  230. protected Charset getDefaultFontCharset(String fontName) {
  231. return Charset.forName("ISO8859_1");
  232. }
  233. protected String getFaceNameFromComponentFontName(String componentFontName) {
  234. return null;
  235. }
  236. protected String getFileNameFromComponentFontName(String componentFontName) {
  237. // for X11, component font name is XLFD
  238. // if we have a file name already, just use it; otherwise let's see
  239. // what the graphics environment can provide
  240. String fileName = getFileNameFromPlatformName(componentFontName);
  241. if (fileName != null && fileName.charAt(0) == '/' &&
  242. !needToSearchForFile(fileName)) {
  243. return fileName;
  244. }
  245. return ((X11FontManager) fontManager).getFileNameFromXLFD(componentFontName);
  246. }
  247. public HashSet<String> getAWTFontPathSet() {
  248. HashSet<String> fontDirs = new HashSet<String>();
  249. short[] scripts = getCoreScripts(0);
  250. for (int i = 0; i< scripts.length; i++) {
  251. String path = getString(table_awtfontpaths[scripts[i]]);
  252. if (path != null) {
  253. int start = 0;
  254. int colon = path.indexOf(':');
  255. while (colon >= 0) {
  256. fontDirs.add(path.substring(start, colon));
  257. start = colon + 1;
  258. colon = path.indexOf(':', start);
  259. }
  260. fontDirs.add((start == 0) ? path : path.substring(start));
  261. }
  262. }
  263. return fontDirs;
  264. }
  265. /* methods for table setup ***********************************************/
  266. private static HashMap encodingMap = new HashMap();
  267. private void initTables() {
  268. // encodingMap maps XLFD encoding component to
  269. // name of corresponding java.nio charset
  270. encodingMap.put("iso8859-1", "ISO-8859-1");
  271. encodingMap.put("iso8859-2", "ISO-8859-2");
  272. encodingMap.put("iso8859-4", "ISO-8859-4");
  273. encodingMap.put("iso8859-5", "ISO-8859-5");
  274. encodingMap.put("iso8859-6", "ISO-8859-6");
  275. encodingMap.put("iso8859-7", "ISO-8859-7");
  276. encodingMap.put("iso8859-8", "ISO-8859-8");
  277. encodingMap.put("iso8859-9", "ISO-8859-9");
  278. encodingMap.put("iso8859-13", "ISO-8859-13");
  279. encodingMap.put("iso8859-15", "ISO-8859-15");
  280. encodingMap.put("gb2312.1980-0", "sun.awt.motif.X11GB2312");
  281. if (osName == null) {
  282. // use standard converter on Solaris
  283. encodingMap.put("gbk-0", "GBK");
  284. } else {
  285. encodingMap.put("gbk-0", "sun.awt.motif.X11GBK");
  286. }
  287. encodingMap.put("gb18030.2000-0", "sun.awt.motif.X11GB18030_0");
  288. encodingMap.put("gb18030.2000-1", "sun.awt.motif.X11GB18030_1");
  289. encodingMap.put("cns11643-1", "sun.awt.motif.X11CNS11643P1");
  290. encodingMap.put("cns11643-2", "sun.awt.motif.X11CNS11643P2");
  291. encodingMap.put("cns11643-3", "sun.awt.motif.X11CNS11643P3");
  292. encodingMap.put("big5-1", "Big5");
  293. encodingMap.put("big5-0", "Big5");
  294. encodingMap.put("hkscs-1", "Big5-HKSCS");
  295. encodingMap.put("ansi-1251", "windows-1251");
  296. encodingMap.put("koi8-r", "KOI8-R");
  297. encodingMap.put("jisx0201.1976-0", "sun.awt.motif.X11JIS0201");
  298. encodingMap.put("jisx0208.1983-0", "sun.awt.motif.X11JIS0208");
  299. encodingMap.put("jisx0212.1990-0", "sun.awt.motif.X11JIS0212");
  300. encodingMap.put("ksc5601.1987-0", "sun.awt.motif.X11KSC5601");
  301. encodingMap.put("ksc5601.1992-3", "sun.awt.motif.X11Johab");
  302. encodingMap.put("tis620.2533-0", "TIS-620");
  303. encodingMap.put("iso10646-1", "UTF-16BE");
  304. }
  305. }