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