Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/sun/awt/Win32FontManager.java
32287 views
1
/*
2
* Copyright (c) 2008, 2014, 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
27
package sun.awt;
28
29
import java.awt.FontFormatException;
30
import java.awt.GraphicsEnvironment;
31
import java.io.File;
32
import java.security.AccessController;
33
import java.security.PrivilegedAction;
34
import java.util.ArrayList;
35
import java.util.HashMap;
36
import java.util.Locale;
37
import java.util.NoSuchElementException;
38
import java.util.StringTokenizer;
39
40
import sun.awt.windows.WFontConfiguration;
41
import sun.font.FontManager;
42
import sun.font.SunFontManager;
43
import sun.font.TrueTypeFont;
44
import sun.java2d.HeadlessGraphicsEnvironment;
45
import sun.java2d.SunGraphicsEnvironment;
46
47
/**
48
* The X11 implementation of {@link FontManager}.
49
*/
50
public final class Win32FontManager extends SunFontManager {
51
52
private static TrueTypeFont eudcFont;
53
54
static {
55
56
AccessController.doPrivileged(new PrivilegedAction() {
57
58
public Object run() {
59
String eudcFile = getEUDCFontFile();
60
if (eudcFile != null) {
61
try {
62
/* Must use Java rasteriser since GDI doesn't
63
* enumerate (allow direct use) of EUDC fonts.
64
*/
65
eudcFont = new TrueTypeFont(eudcFile, null, 0,
66
true, false);
67
} catch (FontFormatException e) {
68
}
69
}
70
return null;
71
}
72
73
});
74
}
75
76
/* Used on Windows to obtain from the windows registry the name
77
* of a file containing the system EUFC font. If running in one of
78
* the locales for which this applies, and one is defined, the font
79
* defined by this file is appended to all composite fonts as a
80
* fallback component.
81
*/
82
private static native String getEUDCFontFile();
83
84
public TrueTypeFont getEUDCFont() {
85
return eudcFont;
86
}
87
88
public Win32FontManager() {
89
super();
90
AccessController.doPrivileged(new PrivilegedAction() {
91
public Object run() {
92
93
/* Register the JRE fonts so that the native platform can
94
* access them. This is used only on Windows so that when
95
* printing the printer driver can access the fonts.
96
*/
97
registerJREFontsWithPlatform(jreFontDirName);
98
return null;
99
}
100
});
101
}
102
103
/**
104
* Whether registerFontFile expects absolute or relative
105
* font file names.
106
*/
107
protected boolean useAbsoluteFontFileNames() {
108
return false;
109
}
110
111
/* Unlike the shared code version, this expects a base file name -
112
* not a full path name.
113
* The font configuration file has base file names and the FontConfiguration
114
* class reports these back to the GraphicsEnvironment, so these
115
* are the componentFileNames of CompositeFonts.
116
*/
117
protected void registerFontFile(String fontFileName, String[] nativeNames,
118
int fontRank, boolean defer) {
119
120
// REMIND: case compare depends on platform
121
if (registeredFontFiles.contains(fontFileName)) {
122
return;
123
}
124
registeredFontFiles.add(fontFileName);
125
126
int fontFormat;
127
if (getTrueTypeFilter().accept(null, fontFileName)) {
128
fontFormat = SunFontManager.FONTFORMAT_TRUETYPE;
129
} else if (getType1Filter().accept(null, fontFileName)) {
130
fontFormat = SunFontManager.FONTFORMAT_TYPE1;
131
} else {
132
/* on windows we don't use/register native fonts */
133
return;
134
}
135
136
if (fontPath == null) {
137
fontPath = getPlatformFontPath(noType1Font);
138
}
139
140
/* Look in the JRE font directory first.
141
* This is playing it safe as we would want to find fonts in the
142
* JRE font directory ahead of those in the system directory
143
*/
144
String tmpFontPath = jreFontDirName+File.pathSeparator+fontPath;
145
StringTokenizer parser = new StringTokenizer(tmpFontPath,
146
File.pathSeparator);
147
148
boolean found = false;
149
try {
150
while (!found && parser.hasMoreTokens()) {
151
String newPath = parser.nextToken();
152
boolean isJREFont = newPath.equals(jreFontDirName);
153
File theFile = new File(newPath, fontFileName);
154
if (theFile.canRead()) {
155
found = true;
156
String path = theFile.getAbsolutePath();
157
if (defer) {
158
registerDeferredFont(fontFileName, path,
159
nativeNames,
160
fontFormat, isJREFont,
161
fontRank);
162
} else {
163
registerFontFile(path, nativeNames,
164
fontFormat, isJREFont,
165
fontRank);
166
}
167
break;
168
}
169
}
170
} catch (NoSuchElementException e) {
171
System.err.println(e);
172
}
173
if (!found) {
174
addToMissingFontFileList(fontFileName);
175
}
176
}
177
178
@Override
179
protected FontConfiguration createFontConfiguration() {
180
181
FontConfiguration fc = new WFontConfiguration(this);
182
fc.init();
183
return fc;
184
}
185
186
@Override
187
public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
188
boolean preferPropFonts) {
189
190
return new WFontConfiguration(this,
191
preferLocaleFonts,preferPropFonts);
192
}
193
194
protected void
195
populateFontFileNameMap(HashMap<String,String> fontToFileMap,
196
HashMap<String,String> fontToFamilyNameMap,
197
HashMap<String,ArrayList<String>>
198
familyToFontListMap,
199
Locale locale) {
200
201
populateFontFileNameMap0(fontToFileMap, fontToFamilyNameMap,
202
familyToFontListMap, locale);
203
204
}
205
206
private static native void
207
populateFontFileNameMap0(HashMap<String,String> fontToFileMap,
208
HashMap<String,String> fontToFamilyNameMap,
209
HashMap<String,ArrayList<String>>
210
familyToFontListMap,
211
Locale locale);
212
213
protected synchronized native String getFontPath(boolean noType1Fonts);
214
215
@Override
216
protected String[] getDefaultPlatformFont() {
217
String[] info = new String[2];
218
info[0] = "Arial";
219
info[1] = "c:\\windows\\fonts";
220
final String[] dirs = getPlatformFontDirs(true);
221
if (dirs.length > 1) {
222
String dir = (String)
223
AccessController.doPrivileged(new PrivilegedAction() {
224
public Object run() {
225
for (int i=0; i<dirs.length; i++) {
226
String path =
227
dirs[i] + File.separator + "arial.ttf";
228
File file = new File(path);
229
if (file.exists()) {
230
return dirs[i];
231
}
232
}
233
return null;
234
}
235
});
236
if (dir != null) {
237
info[1] = dir;
238
}
239
} else {
240
info[1] = dirs[0];
241
}
242
info[1] = info[1] + File.separator + "arial.ttf";
243
return info;
244
}
245
246
/* register only TrueType/OpenType fonts
247
* Because these need to be registed just for use when printing,
248
* we defer the actual registration and the static initialiser
249
* for the printing class makes the call to registerJREFontsForPrinting()
250
*/
251
static String fontsForPrinting = null;
252
protected void registerJREFontsWithPlatform(String pathName) {
253
fontsForPrinting = pathName;
254
}
255
256
public static void registerJREFontsForPrinting() {
257
final String pathName;
258
synchronized (Win32GraphicsEnvironment.class) {
259
GraphicsEnvironment.getLocalGraphicsEnvironment();
260
if (fontsForPrinting == null) {
261
return;
262
}
263
pathName = fontsForPrinting;
264
fontsForPrinting = null;
265
}
266
java.security.AccessController.doPrivileged(
267
new java.security.PrivilegedAction() {
268
public Object run() {
269
File f1 = new File(pathName);
270
String[] ls = f1.list(SunFontManager.getInstance().
271
getTrueTypeFilter());
272
if (ls == null) {
273
return null;
274
}
275
for (int i=0; i <ls.length; i++ ) {
276
File fontFile = new File(f1, ls[i]);
277
registerFontWithPlatform(fontFile.getAbsolutePath());
278
}
279
return null;
280
}
281
});
282
}
283
284
protected static native void registerFontWithPlatform(String fontName);
285
286
protected static native void deRegisterFontWithPlatform(String fontName);
287
288
/**
289
* populate the map with the most common windows fonts.
290
*/
291
@Override
292
public HashMap<String, FamilyDescription> populateHardcodedFileNameMap() {
293
HashMap<String, FamilyDescription> platformFontMap
294
= new HashMap<String, FamilyDescription>();
295
FamilyDescription fd;
296
297
/* Segoe UI is the default UI font for Vista and later, and
298
* is used by the Win L&F which is used by FX too.
299
* Tahoma is used for the Win L&F on XP.
300
* Verdana is used in some FX UI controls.
301
*/
302
fd = new FamilyDescription();
303
fd.familyName = "Segoe UI";
304
fd.plainFullName = "Segoe UI";
305
fd.plainFileName = "segoeui.ttf";
306
fd.boldFullName = "Segoe UI Bold";
307
fd.boldFileName = "segoeuib.ttf";
308
fd.italicFullName = "Segoe UI Italic";
309
fd.italicFileName = "segoeuii.ttf";
310
fd.boldItalicFullName = "Segoe UI Bold Italic";
311
fd.boldItalicFileName = "segoeuiz.ttf";
312
platformFontMap.put("segoe", fd);
313
314
fd = new FamilyDescription();
315
fd.familyName = "Tahoma";
316
fd.plainFullName = "Tahoma";
317
fd.plainFileName = "tahoma.ttf";
318
fd.boldFullName = "Tahoma Bold";
319
fd.boldFileName = "tahomabd.ttf";
320
platformFontMap.put("tahoma", fd);
321
322
fd = new FamilyDescription();
323
fd.familyName = "Verdana";
324
fd.plainFullName = "Verdana";
325
fd.plainFileName = "verdana.TTF";
326
fd.boldFullName = "Verdana Bold";
327
fd.boldFileName = "verdanab.TTF";
328
fd.italicFullName = "Verdana Italic";
329
fd.italicFileName = "verdanai.TTF";
330
fd.boldItalicFullName = "Verdana Bold Italic";
331
fd.boldItalicFileName = "verdanaz.TTF";
332
platformFontMap.put("verdana", fd);
333
334
/* The following are important because they are the core
335
* members of the default "Dialog" font.
336
*/
337
fd = new FamilyDescription();
338
fd.familyName = "Arial";
339
fd.plainFullName = "Arial";
340
fd.plainFileName = "ARIAL.TTF";
341
fd.boldFullName = "Arial Bold";
342
fd.boldFileName = "ARIALBD.TTF";
343
fd.italicFullName = "Arial Italic";
344
fd.italicFileName = "ARIALI.TTF";
345
fd.boldItalicFullName = "Arial Bold Italic";
346
fd.boldItalicFileName = "ARIALBI.TTF";
347
platformFontMap.put("arial", fd);
348
349
fd = new FamilyDescription();
350
fd.familyName = "Symbol";
351
fd.plainFullName = "Symbol";
352
fd.plainFileName = "Symbol.TTF";
353
platformFontMap.put("symbol", fd);
354
355
fd = new FamilyDescription();
356
fd.familyName = "WingDings";
357
fd.plainFullName = "WingDings";
358
fd.plainFileName = "WINGDING.TTF";
359
platformFontMap.put("wingdings", fd);
360
361
return platformFontMap;
362
}
363
}
364
365