Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/unix/classes/sun/font/MFontConfiguration.java
41153 views
1
/*
2
* Copyright (c) 2000, 2020, 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
}
116
} catch (Exception e) {
117
}
118
}
119
return;
120
}
121
122
/**
123
* Gets the OS version string from a Linux release-specific file.
124
*/
125
private String getVersionString(File f){
126
try {
127
Scanner sc = new Scanner(f);
128
return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
129
}
130
catch (Exception e){
131
}
132
return null;
133
}
134
135
private static final String fontsDirPrefix = "$JRE_LIB_FONTS";
136
137
protected String mapFileName(String fileName) {
138
if (fileName != null && fileName.startsWith(fontsDirPrefix)) {
139
return SunFontManager.jreFontDirName
140
+ fileName.substring(fontsDirPrefix.length());
141
}
142
return fileName;
143
}
144
145
// overrides FontConfiguration.getFallbackFamilyName
146
public String getFallbackFamilyName(String fontName, String defaultFallback) {
147
// maintain compatibility with old font.properties files, which
148
// either had aliases for TimesRoman & Co. or defined mappings for them.
149
String compatibilityName = getCompatibilityFamilyName(fontName);
150
if (compatibilityName != null) {
151
return compatibilityName;
152
}
153
return defaultFallback;
154
}
155
156
protected String getEncoding(String awtFontName,
157
String characterSubsetName) {
158
// extract encoding field from XLFD
159
int beginIndex = 0;
160
int fieldNum = 13; // charset registry field
161
while (fieldNum-- > 0 && beginIndex >= 0) {
162
beginIndex = awtFontName.indexOf("-", beginIndex) + 1;
163
}
164
if (beginIndex == -1) {
165
return "default";
166
}
167
String xlfdEncoding = awtFontName.substring(beginIndex);
168
if (xlfdEncoding.indexOf("fontspecific") > 0) {
169
if (awtFontName.indexOf("dingbats") > 0) {
170
return "sun.font.X11Dingbats";
171
} else if (awtFontName.indexOf("symbol") > 0) {
172
return "sun.awt.Symbol";
173
}
174
}
175
String encoding = encodingMap.get(xlfdEncoding);
176
if (encoding == null) {
177
encoding = "default";
178
}
179
return encoding;
180
}
181
182
protected Charset getDefaultFontCharset(String fontName) {
183
return Charset.forName("ISO8859_1");
184
}
185
186
protected String getFaceNameFromComponentFontName(String componentFontName) {
187
return null;
188
}
189
190
protected String getFileNameFromComponentFontName(String componentFontName) {
191
// for X11, component font name is XLFD
192
// if we have a file name already, just use it; otherwise let's see
193
// what the graphics environment can provide
194
String fileName = getFileNameFromPlatformName(componentFontName);
195
if (fileName != null && fileName.charAt(0) == '/' &&
196
!needToSearchForFile(fileName)) {
197
return fileName;
198
}
199
return ((X11FontManager) fontManager).getFileNameFromXLFD(componentFontName);
200
}
201
202
public HashSet<String> getAWTFontPathSet() {
203
HashSet<String> fontDirs = new HashSet<String>();
204
short[] scripts = getCoreScripts(0);
205
for (int i = 0; i< scripts.length; i++) {
206
String path = getString(table_awtfontpaths[scripts[i]]);
207
if (path != null) {
208
int start = 0;
209
int colon = path.indexOf(':');
210
while (colon >= 0) {
211
fontDirs.add(path.substring(start, colon));
212
start = colon + 1;
213
colon = path.indexOf(':', start);
214
}
215
fontDirs.add((start == 0) ? path : path.substring(start));
216
}
217
}
218
return fontDirs;
219
}
220
221
/* methods for table setup ***********************************************/
222
223
private static HashMap<String, String> encodingMap = new HashMap<>();
224
225
private void initTables() {
226
// encodingMap maps XLFD encoding component to
227
// name of corresponding java.nio charset
228
encodingMap.put("iso8859-1", "ISO-8859-1");
229
encodingMap.put("iso8859-2", "ISO-8859-2");
230
encodingMap.put("iso8859-4", "ISO-8859-4");
231
encodingMap.put("iso8859-5", "ISO-8859-5");
232
encodingMap.put("iso8859-6", "ISO-8859-6");
233
encodingMap.put("iso8859-7", "ISO-8859-7");
234
encodingMap.put("iso8859-8", "ISO-8859-8");
235
encodingMap.put("iso8859-9", "ISO-8859-9");
236
encodingMap.put("iso8859-13", "ISO-8859-13");
237
encodingMap.put("iso8859-15", "ISO-8859-15");
238
encodingMap.put("gb2312.1980-0", "sun.font.X11GB2312");
239
if (osName == null) {
240
// use standard converter on Solaris
241
encodingMap.put("gbk-0", "GBK");
242
} else {
243
encodingMap.put("gbk-0", "sun.font.X11GBK");
244
}
245
encodingMap.put("gb18030.2000-0", "sun.font.X11GB18030_0");
246
encodingMap.put("gb18030.2000-1", "sun.font.X11GB18030_1");
247
encodingMap.put("cns11643-1", "sun.font.X11CNS11643P1");
248
encodingMap.put("cns11643-2", "sun.font.X11CNS11643P2");
249
encodingMap.put("cns11643-3", "sun.font.X11CNS11643P3");
250
encodingMap.put("big5-1", "Big5");
251
encodingMap.put("big5-0", "Big5");
252
encodingMap.put("hkscs-1", "Big5-HKSCS");
253
encodingMap.put("ansi-1251", "windows-1251");
254
encodingMap.put("koi8-r", "KOI8-R");
255
encodingMap.put("jisx0201.1976-0", "JIS0201");
256
encodingMap.put("jisx0208.1983-0", "JIS0208");
257
encodingMap.put("jisx0212.1990-0", "JIS0212");
258
encodingMap.put("ksc5601.1987-0", "sun.font.X11KSC5601");
259
encodingMap.put("ksc5601.1992-3", "sun.font.X11Johab");
260
encodingMap.put("tis620.2533-0", "TIS-620");
261
encodingMap.put("iso10646-1", "UTF-16BE");
262
}
263
264
}
265
266