2
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
29
import java.awt.FontFormatException;
30
import java.awt.GraphicsEnvironment;
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;
40
import sun.awt.windows.WFontConfiguration;
41
import sun.font.FontManager;
42
import sun.font.SunFontManager;
43
import sun.font.TrueTypeFont;
46
* The X11 implementation of {@link FontManager}.
48
public final class Win32FontManager extends SunFontManager {
50
@SuppressWarnings("removal")
51
private static final TrueTypeFont eudcFont =
52
AccessController.doPrivileged(new PrivilegedAction<TrueTypeFont>() {
53
public TrueTypeFont run() {
54
String eudcFile = getEUDCFontFile();
55
if (eudcFile != null) {
57
/* Must use Java rasteriser since GDI doesn't
58
* enumerate (allow direct use) of EUDC fonts.
60
return new TrueTypeFont(eudcFile, null, 0,
62
} catch (FontFormatException e) {
69
/* Used on Windows to obtain from the windows registry the name
70
* of a file containing the system EUFC font. If running in one of
71
* the locales for which this applies, and one is defined, the font
72
* defined by this file is appended to all composite fonts as a
75
private static native String getEUDCFontFile();
77
public TrueTypeFont getEUDCFont() {
81
@SuppressWarnings("removal")
82
public Win32FontManager() {
84
AccessController.doPrivileged(new PrivilegedAction<Object>() {
87
/* Register the JRE fonts so that the native platform can
88
* access them. This is used only on Windows so that when
89
* printing the printer driver can access the fonts.
91
registerJREFontsWithPlatform(jreFontDirName);
98
* Whether registerFontFile expects absolute or relative
101
protected boolean useAbsoluteFontFileNames() {
105
/* Unlike the shared code version, this expects a base file name -
106
* not a full path name.
107
* The font configuration file has base file names and the FontConfiguration
108
* class reports these back to the GraphicsEnvironment, so these
109
* are the componentFileNames of CompositeFonts.
111
protected void registerFontFile(String fontFileName, String[] nativeNames,
112
int fontRank, boolean defer) {
114
// REMIND: case compare depends on platform
115
if (registeredFontFiles.contains(fontFileName)) {
118
registeredFontFiles.add(fontFileName);
121
if (getTrueTypeFilter().accept(null, fontFileName)) {
122
fontFormat = SunFontManager.FONTFORMAT_TRUETYPE;
123
} else if (getType1Filter().accept(null, fontFileName)) {
124
fontFormat = SunFontManager.FONTFORMAT_TYPE1;
126
/* on windows we don't use/register native fonts */
130
if (fontPath == null) {
131
fontPath = getPlatformFontPath(noType1Font);
134
/* Look in the JRE font directory first.
135
* This is playing it safe as we would want to find fonts in the
136
* JRE font directory ahead of those in the system directory
138
String tmpFontPath = jreFontDirName+File.pathSeparator+fontPath;
139
StringTokenizer parser = new StringTokenizer(tmpFontPath,
142
boolean found = false;
144
while (!found && parser.hasMoreTokens()) {
145
String newPath = parser.nextToken();
146
boolean isJREFont = newPath.equals(jreFontDirName);
147
File theFile = new File(newPath, fontFileName);
148
if (theFile.canRead()) {
150
String path = theFile.getAbsolutePath();
152
registerDeferredFont(fontFileName, path,
154
fontFormat, isJREFont,
157
registerFontFile(path, nativeNames,
158
fontFormat, isJREFont,
164
} catch (NoSuchElementException e) {
165
System.err.println(e);
168
addToMissingFontFileList(fontFileName);
173
protected FontConfiguration createFontConfiguration() {
175
FontConfiguration fc = new WFontConfiguration(this);
181
public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
182
boolean preferPropFonts) {
184
return new WFontConfiguration(this,
185
preferLocaleFonts,preferPropFonts);
189
populateFontFileNameMap(HashMap<String,String> fontToFileMap,
190
HashMap<String,String> fontToFamilyNameMap,
191
HashMap<String,ArrayList<String>>
195
populateFontFileNameMap0(fontToFileMap, fontToFamilyNameMap,
196
familyToFontListMap, locale);
200
private static native void
201
populateFontFileNameMap0(HashMap<String,String> fontToFileMap,
202
HashMap<String,String> fontToFamilyNameMap,
203
HashMap<String,ArrayList<String>>
207
protected synchronized native String getFontPath(boolean noType1Fonts);
210
protected String[] getDefaultPlatformFont() {
211
String[] info = new String[2];
213
info[1] = "c:\\windows\\fonts";
214
final String[] dirs = getPlatformFontDirs(true);
215
if (dirs.length > 1) {
216
@SuppressWarnings("removal")
217
String dir = (String)
218
AccessController.doPrivileged(new PrivilegedAction<Object>() {
219
public Object run() {
220
for (int i=0; i<dirs.length; i++) {
222
dirs[i] + File.separator + "arial.ttf";
223
File file = new File(path);
237
info[1] = info[1] + File.separator + "arial.ttf";
241
/* register only TrueType/OpenType fonts
242
* Because these need to be registered just for use when printing,
243
* we defer the actual registration and the static initialiser
244
* for the printing class makes the call to registerJREFontsForPrinting()
246
static String fontsForPrinting = null;
247
protected void registerJREFontsWithPlatform(String pathName) {
248
fontsForPrinting = pathName;
251
@SuppressWarnings("removal")
252
public static void registerJREFontsForPrinting() {
253
final String pathName;
254
synchronized (Win32GraphicsEnvironment.class) {
255
GraphicsEnvironment.getLocalGraphicsEnvironment();
256
if (fontsForPrinting == null) {
259
pathName = fontsForPrinting;
260
fontsForPrinting = null;
262
java.security.AccessController.doPrivileged(
263
new java.security.PrivilegedAction<Object>() {
264
public Object run() {
265
File f1 = new File(pathName);
266
String[] ls = f1.list(SunFontManager.getInstance().
267
getTrueTypeFilter());
271
for (int i=0; i <ls.length; i++ ) {
272
File fontFile = new File(f1, ls[i]);
273
registerFontWithPlatform(fontFile.getAbsolutePath());
280
private static native void registerFontWithPlatform(String fontName);
282
private static native void deRegisterFontWithPlatform(String fontName);
285
* populate the map with the most common windows fonts.
288
public HashMap<String, FamilyDescription> populateHardcodedFileNameMap() {
289
HashMap<String, FamilyDescription> platformFontMap
290
= new HashMap<String, FamilyDescription>();
291
FamilyDescription fd;
293
/* Segoe UI is the default UI font for Vista and later, and
294
* is used by the Win L&F which is used by FX too.
295
* Tahoma is used for the Win L&F on XP.
296
* Verdana is used in some FX UI controls.
298
fd = new FamilyDescription();
299
fd.familyName = "Segoe UI";
300
fd.plainFullName = "Segoe UI";
301
fd.plainFileName = "segoeui.ttf";
302
fd.boldFullName = "Segoe UI Bold";
303
fd.boldFileName = "segoeuib.ttf";
304
fd.italicFullName = "Segoe UI Italic";
305
fd.italicFileName = "segoeuii.ttf";
306
fd.boldItalicFullName = "Segoe UI Bold Italic";
307
fd.boldItalicFileName = "segoeuiz.ttf";
308
platformFontMap.put("segoe", fd);
310
fd = new FamilyDescription();
311
fd.familyName = "Tahoma";
312
fd.plainFullName = "Tahoma";
313
fd.plainFileName = "tahoma.ttf";
314
fd.boldFullName = "Tahoma Bold";
315
fd.boldFileName = "tahomabd.ttf";
316
platformFontMap.put("tahoma", fd);
318
fd = new FamilyDescription();
319
fd.familyName = "Verdana";
320
fd.plainFullName = "Verdana";
321
fd.plainFileName = "verdana.TTF";
322
fd.boldFullName = "Verdana Bold";
323
fd.boldFileName = "verdanab.TTF";
324
fd.italicFullName = "Verdana Italic";
325
fd.italicFileName = "verdanai.TTF";
326
fd.boldItalicFullName = "Verdana Bold Italic";
327
fd.boldItalicFileName = "verdanaz.TTF";
328
platformFontMap.put("verdana", fd);
330
/* The following are important because they are the core
331
* members of the default "Dialog" font.
333
fd = new FamilyDescription();
334
fd.familyName = "Arial";
335
fd.plainFullName = "Arial";
336
fd.plainFileName = "ARIAL.TTF";
337
fd.boldFullName = "Arial Bold";
338
fd.boldFileName = "ARIALBD.TTF";
339
fd.italicFullName = "Arial Italic";
340
fd.italicFileName = "ARIALI.TTF";
341
fd.boldItalicFullName = "Arial Bold Italic";
342
fd.boldItalicFileName = "ARIALBI.TTF";
343
platformFontMap.put("arial", fd);
345
fd = new FamilyDescription();
346
fd.familyName = "Symbol";
347
fd.plainFullName = "Symbol";
348
fd.plainFileName = "Symbol.TTF";
349
platformFontMap.put("symbol", fd);
351
fd = new FamilyDescription();
352
fd.familyName = "WingDings";
353
fd.plainFullName = "WingDings";
354
fd.plainFileName = "WINGDING.TTF";
355
platformFontMap.put("wingdings", fd);
357
return platformFontMap;