author | prr |
Fri, 25 May 2018 16:23:17 -0700 | |
changeset 50348 | 008f416a79cb |
parent 47216 | 71c04702a3d5 |
child 55192 | 26dd6fdc4165 |
permissions | -rw-r--r-- |
29513 | 1 |
/* |
30938
35ae5c70d60e
8030087: Avoid public native methods in sun.awt packages
serb
parents:
29513
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
29513 | 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.awt; |
|
27 |
||
28 |
import sun.font.FcFontConfiguration; |
|
29 |
import sun.font.FontConfigManager; |
|
30 |
import sun.font.SunFontManager; |
|
31 |
||
32 |
/** |
|
33 |
* A {@link sun.font.FontManager} that uses fontconfig to find system fonts. |
|
34 |
*/ |
|
35 |
public class FcFontManager extends SunFontManager { |
|
36 |
||
37 |
private FontConfigManager fcManager = null; |
|
38 |
||
39 |
public synchronized FontConfigManager getFontConfigManager() { |
|
40 |
||
41 |
if (fcManager == null) { |
|
42 |
fcManager = new FontConfigManager(); |
|
43 |
} |
|
44 |
||
45 |
return fcManager; |
|
46 |
} |
|
47 |
||
48 |
@Override |
|
49 |
protected FontConfiguration createFontConfiguration() { |
|
50 |
FcFontConfiguration fcFontConfig = new FcFontConfiguration(this); |
|
51 |
if (fcFontConfig.init()) { |
|
52 |
return fcFontConfig; |
|
53 |
} else { |
|
54 |
throw new InternalError("failed to initialize fontconfig"); |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
@Override |
|
59 |
public FontConfiguration createFontConfiguration(boolean preferLocaleFonts, |
|
60 |
boolean preferPropFonts) { |
|
61 |
FcFontConfiguration fcFontConfig = |
|
62 |
new FcFontConfiguration(this, preferLocaleFonts, preferPropFonts); |
|
63 |
if (fcFontConfig.init()) { |
|
64 |
return fcFontConfig; |
|
65 |
} else { |
|
66 |
throw new InternalError("failed to initialize fontconfig"); |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
@Override |
|
71 |
protected String[] getDefaultPlatformFont() { |
|
72 |
final String[] info = new String[2]; |
|
73 |
getFontConfigManager().initFontConfigFonts(false); |
|
74 |
FontConfigManager.FcCompFont[] fontConfigFonts = |
|
75 |
getFontConfigManager().getFontConfigFonts(); |
|
50348
008f416a79cb
8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents:
47216
diff
changeset
|
76 |
if (fontConfigFonts != null) { |
008f416a79cb
8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents:
47216
diff
changeset
|
77 |
for (int i=0; i<fontConfigFonts.length; i++) { |
008f416a79cb
8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents:
47216
diff
changeset
|
78 |
if ("sans".equals(fontConfigFonts[i].fcFamily) && |
008f416a79cb
8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents:
47216
diff
changeset
|
79 |
0 == fontConfigFonts[i].style) { |
008f416a79cb
8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents:
47216
diff
changeset
|
80 |
info[0] = fontConfigFonts[i].firstFont.familyName; |
008f416a79cb
8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents:
47216
diff
changeset
|
81 |
info[1] = fontConfigFonts[i].firstFont.fontFile; |
008f416a79cb
8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents:
47216
diff
changeset
|
82 |
break; |
008f416a79cb
8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents:
47216
diff
changeset
|
83 |
} |
29513 | 84 |
} |
85 |
} |
|
86 |
/* Absolute last ditch attempt in the face of fontconfig problems. |
|
87 |
* If we didn't match, pick the first, or just make something |
|
88 |
* up so we don't NPE. |
|
89 |
*/ |
|
90 |
if (info[0] == null) { |
|
50348
008f416a79cb
8191522: Remove Bigelow&Holmes Lucida fonts from JDK sources
prr
parents:
47216
diff
changeset
|
91 |
if (fontConfigFonts != null && fontConfigFonts.length > 0 && |
29513 | 92 |
fontConfigFonts[0].firstFont.fontFile != null) { |
93 |
info[0] = fontConfigFonts[0].firstFont.familyName; |
|
94 |
info[1] = fontConfigFonts[0].firstFont.fontFile; |
|
95 |
} else { |
|
96 |
info[0] = "Dialog"; |
|
97 |
info[1] = "/dialog.ttf"; |
|
98 |
} |
|
99 |
} |
|
100 |
return info; |
|
101 |
} |
|
102 |
||
30938
35ae5c70d60e
8030087: Avoid public native methods in sun.awt packages
serb
parents:
29513
diff
changeset
|
103 |
native String getFontPathNative(boolean noType1Fonts, boolean isX11GE); |
29513 | 104 |
|
105 |
protected synchronized String getFontPath(boolean noType1Fonts) { |
|
106 |
return getFontPathNative(noType1Fonts, false); |
|
107 |
} |
|
108 |
||
109 |
} |