20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 package sun.awt.motif;
27
28 import java.awt.Font;
29 import java.io.BufferedReader;
30 import java.io.File;
31 import java.io.FileInputStream;
32 import java.io.InputStreamReader;
33 import java.util.HashMap;
34 import java.util.HashSet;
35 import java.util.Locale;
36 import java.util.logging.Logger;
37 import java.util.Properties;
38 import java.util.Scanner;
39 import sun.awt.FontConfiguration;
40 import sun.awt.X11GraphicsEnvironment;
41 import sun.java2d.SunGraphicsEnvironment;
42 import java.nio.charset.Charset;
43
44 public class MFontConfiguration extends FontConfiguration {
45
46 private static FontConfiguration fontConfig = null;
47 private static Logger logger;
48
49 public MFontConfiguration(SunGraphicsEnvironment environment) {
50 super(environment);
51 if (SunGraphicsEnvironment.debugFonts) {
52 logger = Logger.getLogger("sun.awt.FontConfiguration");
53 }
54 initTables();
55 }
56
57
58 public MFontConfiguration(SunGraphicsEnvironment environment,
59 boolean preferLocaleFonts,
60 boolean preferPropFonts) {
61 super(environment, preferLocaleFonts, preferPropFonts);
62 if (SunGraphicsEnvironment.debugFonts) {
63 logger = Logger.getLogger("sun.awt.FontConfiguration");
64 }
65 initTables();
66 }
67
68 /* Needs to be kept in sync with updates in the languages used in
69 * the fontconfig files.
70 */
71 protected void initReorderMap() {
72 reorderMap = new HashMap();
73 if (osName == null) { /* null means SunOS */
74 initReorderMapForSolaris();
75 } else {
76 initReorderMapForLinux();
77 }
78 }
79
80 private void initReorderMapForSolaris() {
81 /* Don't create a no-op entry, so we can optimize this case
82 * i.e. we don't need to do anything so can avoid slower paths in
83 * the code.
84 */
85 // reorderMap.put("UTF-8", "latin-1");
86 reorderMap.put("UTF-8.hi", "devanagari"); // NB is in Lucida.
87 reorderMap.put("UTF-8.ja",
88 split("japanese-x0201,japanese-x0208,japanese-x0212"));
89 reorderMap.put("UTF-8.ko", "korean-johab");
90 reorderMap.put("UTF-8.th", "thai");
91 reorderMap.put("UTF-8.zh.TW", "chinese-big5");
92 reorderMap.put("UTF-8.zh.HK", split("chinese-big5,chinese-hkscs"));
93 if (sun.font.FontManager.isSolaris8) {
94 reorderMap.put("UTF-8.zh.CN", split("chinese-gb2312,chinese-big5"));
95 } else {
96 reorderMap.put("UTF-8.zh.CN",
97 split("chinese-gb18030-0,chinese-gb18030-1"));
98 }
99 reorderMap.put("UTF-8.zh",
100 split("chinese-big5,chinese-hkscs,chinese-gb18030-0,chinese-gb18030-1"));
101 reorderMap.put("Big5", "chinese-big5");
102 reorderMap.put("Big5-HKSCS", split("chinese-big5,chinese-hkscs"));
103 if (! sun.font.FontManager.isSolaris8 && ! sun.font.FontManager.isSolaris9) {
104 reorderMap.put("GB2312", split("chinese-gbk,chinese-gb2312"));
105 } else {
106 reorderMap.put("GB2312","chinese-gb2312");
107 }
108 reorderMap.put("x-EUC-TW",
109 split("chinese-cns11643-1,chinese-cns11643-2,chinese-cns11643-3"));
110 reorderMap.put("GBK", "chinese-gbk");
111 reorderMap.put("GB18030",split("chinese-gb18030-0,chinese-gb18030-1"));
112
113 reorderMap.put("TIS-620", "thai");
114 reorderMap.put("x-PCK",
115 split("japanese-x0201,japanese-x0208,japanese-x0212"));
116 reorderMap.put("x-eucJP-Open",
117 split("japanese-x0201,japanese-x0208,japanese-x0212"));
118 reorderMap.put("EUC-KR", "korean");
119 /* Don't create a no-op entry, so we can optimize this case */
120 // reorderMap.put("ISO-8859-1", "latin-1");
121 reorderMap.put("ISO-8859-2", "latin-2");
122 reorderMap.put("ISO-8859-5", "cyrillic-iso8859-5");
123 reorderMap.put("windows-1251", "cyrillic-cp1251");
192 return;
193 }
194
195 /**
196 * Gets the OS version string from a Linux release-specific file.
197 */
198 private String getVersionString(File f){
199 try {
200 Scanner sc = new Scanner(f);
201 return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
202 }
203 catch (Exception e){
204 }
205 return null;
206 }
207
208 private static final String fontsDirPrefix = "$JRE_LIB_FONTS";
209
210 protected String mapFileName(String fileName) {
211 if (fileName != null && fileName.startsWith(fontsDirPrefix)) {
212 return SunGraphicsEnvironment.jreFontDirName
213 + fileName.substring(fontsDirPrefix.length());
214 }
215 return fileName;
216 }
217
218 // overrides FontConfiguration.getFallbackFamilyName
219 public String getFallbackFamilyName(String fontName, String defaultFallback) {
220 // maintain compatibility with old font.properties files, which
221 // either had aliases for TimesRoman & Co. or defined mappings for them.
222 String compatibilityName = getCompatibilityFamilyName(fontName);
223 if (compatibilityName != null) {
224 return compatibilityName;
225 }
226 return defaultFallback;
227 }
228
229 protected String getEncoding(String awtFontName,
230 String characterSubsetName) {
231 // extract encoding field from XLFD
232 int beginIndex = 0;
293 buffer.append(',');
294 }
295 buffer.append(name);
296 }
297 return buffer.toString();
298 }
299
300 protected String getFaceNameFromComponentFontName(String componentFontName) {
301 return null;
302 }
303
304 protected String getFileNameFromComponentFontName(String componentFontName) {
305 // for X11, component font name is XLFD
306 // if we have a file name already, just use it; otherwise let's see
307 // what the graphics environment can provide
308 String fileName = getFileNameFromPlatformName(componentFontName);
309 if (fileName != null && fileName.charAt(0) == '/' &&
310 !needToSearchForFile(fileName)) {
311 return fileName;
312 }
313 return ((X11GraphicsEnvironment) environment).getFileNameFromXLFD(componentFontName);
314 }
315
316 /**
317 * Get default font for Motif widgets to use, preventing them from
318 * wasting time accessing inappropriate X resources. This is called
319 * only from native code.
320 *
321 * This is part of a Motif specific performance enhancement. By
322 * default, when Motif widgets are created and initialized, Motif will
323 * set up default fonts for the widgets, which we ALWAYS override.
324 * This set up includes finding the default font in the widget's X
325 * resources and fairly expensive requests of the X server to identify
326 * the specific font or fontset. We avoid all of this overhead by
327 * providing a well known font to use at the creation of widgets, where
328 * possible.
329 *
330 * The X11 fonts are specified by XLFD strings which have %d as a
331 * marker to indicate where the fontsize should be substituted. [The
332 * libc function sprintf() is used to replace it.] The value 140
333 * specifies a font size of 14 points.
|
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 package sun.awt.motif;
27
28 import java.awt.Font;
29 import java.io.BufferedReader;
30 import java.io.File;
31 import java.io.FileInputStream;
32 import java.io.InputStreamReader;
33 import java.util.HashMap;
34 import java.util.HashSet;
35 import java.util.Locale;
36 import java.util.logging.Logger;
37 import java.util.Properties;
38 import java.util.Scanner;
39 import sun.awt.FontConfiguration;
40 import sun.awt.X11FontManager;
41 import sun.awt.X11GraphicsEnvironment;
42 import sun.font.FontManager;
43 import sun.font.SunFontManager;
44 import sun.font.FontManagerFactory;
45 import sun.font.FontUtilities;
46 import sun.java2d.SunGraphicsEnvironment;
47 import java.nio.charset.Charset;
48
49 public class MFontConfiguration extends FontConfiguration {
50
51 private static FontConfiguration fontConfig = null;
52 private static Logger logger;
53
54 public MFontConfiguration(SunFontManager fm) {
55 super(fm);
56 if (FontUtilities.debugFonts()) {
57 logger = Logger.getLogger("sun.awt.FontConfiguration");
58 }
59 initTables();
60 }
61
62
63 public MFontConfiguration(SunFontManager fm,
64 boolean preferLocaleFonts,
65 boolean preferPropFonts) {
66 super(fm, preferLocaleFonts, preferPropFonts);
67 if (FontUtilities.debugFonts()) {
68 logger = Logger.getLogger("sun.awt.FontConfiguration");
69 }
70 initTables();
71 }
72
73 /* Needs to be kept in sync with updates in the languages used in
74 * the fontconfig files.
75 */
76 protected void initReorderMap() {
77 reorderMap = new HashMap();
78 if (osName == null) { /* null means SunOS */
79 initReorderMapForSolaris();
80 } else {
81 initReorderMapForLinux();
82 }
83 }
84
85 private void initReorderMapForSolaris() {
86 /* Don't create a no-op entry, so we can optimize this case
87 * i.e. we don't need to do anything so can avoid slower paths in
88 * the code.
89 */
90 // reorderMap.put("UTF-8", "latin-1");
91 reorderMap.put("UTF-8.hi", "devanagari"); // NB is in Lucida.
92 reorderMap.put("UTF-8.ja",
93 split("japanese-x0201,japanese-x0208,japanese-x0212"));
94 reorderMap.put("UTF-8.ko", "korean-johab");
95 reorderMap.put("UTF-8.th", "thai");
96 reorderMap.put("UTF-8.zh.TW", "chinese-big5");
97 reorderMap.put("UTF-8.zh.HK", split("chinese-big5,chinese-hkscs"));
98 if (FontUtilities.isSolaris8) {
99 reorderMap.put("UTF-8.zh.CN", split("chinese-gb2312,chinese-big5"));
100 } else {
101 reorderMap.put("UTF-8.zh.CN",
102 split("chinese-gb18030-0,chinese-gb18030-1"));
103 }
104 reorderMap.put("UTF-8.zh",
105 split("chinese-big5,chinese-hkscs,chinese-gb18030-0,chinese-gb18030-1"));
106 reorderMap.put("Big5", "chinese-big5");
107 reorderMap.put("Big5-HKSCS", split("chinese-big5,chinese-hkscs"));
108 if (! FontUtilities.isSolaris8 && ! FontUtilities.isSolaris9) {
109 reorderMap.put("GB2312", split("chinese-gbk,chinese-gb2312"));
110 } else {
111 reorderMap.put("GB2312","chinese-gb2312");
112 }
113 reorderMap.put("x-EUC-TW",
114 split("chinese-cns11643-1,chinese-cns11643-2,chinese-cns11643-3"));
115 reorderMap.put("GBK", "chinese-gbk");
116 reorderMap.put("GB18030",split("chinese-gb18030-0,chinese-gb18030-1"));
117
118 reorderMap.put("TIS-620", "thai");
119 reorderMap.put("x-PCK",
120 split("japanese-x0201,japanese-x0208,japanese-x0212"));
121 reorderMap.put("x-eucJP-Open",
122 split("japanese-x0201,japanese-x0208,japanese-x0212"));
123 reorderMap.put("EUC-KR", "korean");
124 /* Don't create a no-op entry, so we can optimize this case */
125 // reorderMap.put("ISO-8859-1", "latin-1");
126 reorderMap.put("ISO-8859-2", "latin-2");
127 reorderMap.put("ISO-8859-5", "cyrillic-iso8859-5");
128 reorderMap.put("windows-1251", "cyrillic-cp1251");
197 return;
198 }
199
200 /**
201 * Gets the OS version string from a Linux release-specific file.
202 */
203 private String getVersionString(File f){
204 try {
205 Scanner sc = new Scanner(f);
206 return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
207 }
208 catch (Exception e){
209 }
210 return null;
211 }
212
213 private static final String fontsDirPrefix = "$JRE_LIB_FONTS";
214
215 protected String mapFileName(String fileName) {
216 if (fileName != null && fileName.startsWith(fontsDirPrefix)) {
217 return SunFontManager.jreFontDirName
218 + fileName.substring(fontsDirPrefix.length());
219 }
220 return fileName;
221 }
222
223 // overrides FontConfiguration.getFallbackFamilyName
224 public String getFallbackFamilyName(String fontName, String defaultFallback) {
225 // maintain compatibility with old font.properties files, which
226 // either had aliases for TimesRoman & Co. or defined mappings for them.
227 String compatibilityName = getCompatibilityFamilyName(fontName);
228 if (compatibilityName != null) {
229 return compatibilityName;
230 }
231 return defaultFallback;
232 }
233
234 protected String getEncoding(String awtFontName,
235 String characterSubsetName) {
236 // extract encoding field from XLFD
237 int beginIndex = 0;
298 buffer.append(',');
299 }
300 buffer.append(name);
301 }
302 return buffer.toString();
303 }
304
305 protected String getFaceNameFromComponentFontName(String componentFontName) {
306 return null;
307 }
308
309 protected String getFileNameFromComponentFontName(String componentFontName) {
310 // for X11, component font name is XLFD
311 // if we have a file name already, just use it; otherwise let's see
312 // what the graphics environment can provide
313 String fileName = getFileNameFromPlatformName(componentFontName);
314 if (fileName != null && fileName.charAt(0) == '/' &&
315 !needToSearchForFile(fileName)) {
316 return fileName;
317 }
318 return ((X11FontManager) fontManager).getFileNameFromXLFD(componentFontName);
319 }
320
321 /**
322 * Get default font for Motif widgets to use, preventing them from
323 * wasting time accessing inappropriate X resources. This is called
324 * only from native code.
325 *
326 * This is part of a Motif specific performance enhancement. By
327 * default, when Motif widgets are created and initialized, Motif will
328 * set up default fonts for the widgets, which we ALWAYS override.
329 * This set up includes finding the default font in the widget's X
330 * resources and fairly expensive requests of the X server to identify
331 * the specific font or fontset. We avoid all of this overhead by
332 * providing a well known font to use at the creation of widgets, where
333 * possible.
334 *
335 * The X11 fonts are specified by XLFD strings which have %d as a
336 * marker to indicate where the fontsize should be substituted. [The
337 * libc function sprintf() is used to replace it.] The value 140
338 * specifies a font size of 14 points.
|