author | yan |
Mon, 06 Oct 2008 16:45:00 +0400 | |
changeset 1966 | 12a51fb0db0d |
parent 889 | 6549643c008c |
child 1724 | a22a286aa16f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 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. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.awt; |
|
27 |
||
28 |
import java.awt.GraphicsDevice; |
|
29 |
import java.awt.Point; |
|
30 |
import java.awt.Rectangle; |
|
31 |
import java.io.BufferedReader; |
|
32 |
import java.io.File; |
|
33 |
import java.io.FileReader; |
|
34 |
import java.io.FileNotFoundException; |
|
35 |
import java.io.InputStream; |
|
36 |
import java.io.IOException; |
|
37 |
import java.io.StreamTokenizer; |
|
38 |
import java.net.InetAddress; |
|
39 |
import java.net.NetworkInterface; |
|
40 |
import java.net.SocketException; |
|
41 |
import java.net.UnknownHostException; |
|
42 |
||
43 |
import java.util.*; |
|
44 |
import java.util.logging.*; |
|
45 |
||
46 |
import sun.awt.motif.MFontConfiguration; |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
47 |
import sun.font.FcFontConfiguration; |
2 | 48 |
import sun.font.Font2D; |
49 |
import sun.font.FontManager; |
|
50 |
import sun.font.NativeFont; |
|
51 |
import sun.java2d.SunGraphicsEnvironment; |
|
557
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
52 |
import sun.java2d.SurfaceManagerFactory; |
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
53 |
import sun.java2d.UnixSurfaceManagerFactory; |
2 | 54 |
|
55 |
/** |
|
56 |
* This is an implementation of a GraphicsEnvironment object for the |
|
57 |
* default local GraphicsEnvironment used by the Java Runtime Environment |
|
58 |
* for X11 environments. |
|
59 |
* |
|
60 |
* @see GraphicsDevice |
|
61 |
* @see GraphicsConfiguration |
|
62 |
*/ |
|
63 |
public class X11GraphicsEnvironment |
|
64 |
extends SunGraphicsEnvironment |
|
65 |
{ |
|
66 |
private static final Logger log = Logger.getLogger("sun.awt.X11GraphicsEnvironment"); |
|
67 |
private static final Logger screenLog = Logger.getLogger("sun.awt.screen.X11GraphicsEnvironment"); |
|
68 |
||
69 |
private static Boolean xinerState; |
|
70 |
||
71 |
/* |
|
72 |
* This is the set of font directories needed to be on the X font path |
|
73 |
* to enable AWT heavyweights to find all of the font configuration fonts. |
|
74 |
* It is populated by : |
|
75 |
* - awtfontpath entries in the fontconfig.properties |
|
76 |
* - parent directories of "core" fonts used in the fontconfig.properties |
|
77 |
* - looking up font dirs in the xFontDirsMap where the key is a fontID |
|
78 |
* (cut down version of the XLFD read from the font configuration file). |
|
79 |
* This set is nulled out after use to free heap space. |
|
80 |
*/ |
|
81 |
private static HashSet<String> fontConfigDirs = null; |
|
82 |
||
83 |
/* |
|
84 |
* fontNameMap is a map from a fontID (which is a substring of an XLFD like |
|
85 |
* "-monotype-arial-bold-r-normal-iso8859-7") |
|
86 |
* to font file path like |
|
87 |
* /usr/openwin/lib/locale/iso_8859_7/X11/fonts/TrueType/ArialBoldItalic.ttf |
|
88 |
* It's used in a couple of methods like |
|
89 |
* getFileNameFomPlatformName(..) to help locate the font file. |
|
90 |
* We use this substring of a full XLFD because the font configuration files |
|
91 |
* define the XLFDs in a way that's easier to make into a request. |
|
92 |
* E.g., the -0-0-0-0-p-0- reported by X is -*-%d-*-*-p-*- in the font |
|
93 |
* configuration files. We need to remove that part for comparisons. |
|
94 |
*/ |
|
95 |
private static Map fontNameMap = new HashMap(); |
|
96 |
||
97 |
/* xFontDirsMap is also a map from a font ID to a font filepath. |
|
98 |
* The difference from fontNameMap is just that it does not have |
|
99 |
* resolved symbolic links. Normally this is not interesting except |
|
100 |
* that we need to know the directory in which a font was found to |
|
101 |
* add it to the X font server path, since although the files may |
|
102 |
* be linked, the fonts.dir is different and specific to the encoding |
|
103 |
* handled by that directory. This map is nulled out after use to free |
|
104 |
* heap space. If the optimal path is taken, such that all fonts in |
|
105 |
* font configuration files are referenced by filename, then the font |
|
106 |
* dir can be directly derived as its parent directory. |
|
107 |
* If a font is used by two XLFDs, each corresponding to a different |
|
108 |
* X11 font directory, then precautions must be taken to include both |
|
109 |
* directories. |
|
110 |
*/ |
|
111 |
private static Map xFontDirsMap; |
|
112 |
||
113 |
/* |
|
114 |
* xlfdMap is a map from a platform path like |
|
115 |
* /usr/openwin/lib/locale/ja/X11/fonts/TT/HG-GothicB.ttf to an XLFD like |
|
116 |
* "-ricoh-hg gothic b-medium-r-normal--0-0-0-0-m-0-jisx0201.1976-0" |
|
117 |
* Because there may be multiple native names, because the font is used |
|
118 |
* to support multiple X encodings for example, the value of an entry in |
|
119 |
* this map is always a vector where we store all the native names. |
|
120 |
* For fonts which we don't understand the key isn't a pathname, its |
|
121 |
* the full XLFD string like :- |
|
122 |
* "-ricoh-hg gothic b-medium-r-normal--0-0-0-0-m-0-jisx0201.1976-0" |
|
123 |
*/ |
|
124 |
private static Map xlfdMap = new HashMap(); |
|
125 |
||
126 |
/* |
|
127 |
* Used to eliminate redundant work. When a font directory is |
|
128 |
* registered it added to this list. Subsequent registrations for the |
|
129 |
* same directory can then be skipped by checking this Map. |
|
130 |
* Access to this map is not synchronised here since creation |
|
131 |
* of the singleton GE instance is already synchronised and that is |
|
132 |
* the only code path that accesses this map. |
|
133 |
*/ |
|
134 |
private static HashMap registeredDirs = new HashMap(); |
|
135 |
||
136 |
/* Array of directories to be added to the X11 font path. |
|
137 |
* Used by static method called from Toolkits which use X11 fonts. |
|
138 |
* Specifically this means MToolkit |
|
139 |
*/ |
|
140 |
private static String[] fontdirs = null; |
|
141 |
||
142 |
static { |
|
143 |
java.security.AccessController.doPrivileged( |
|
144 |
new java.security.PrivilegedAction() { |
|
145 |
public Object run() { |
|
146 |
System.loadLibrary("awt"); |
|
147 |
||
148 |
/* |
|
149 |
* Note: The MToolkit object depends on the static initializer |
|
150 |
* of X11GraphicsEnvironment to initialize the connection to |
|
151 |
* the X11 server. |
|
152 |
*/ |
|
153 |
if (!isHeadless()) { |
|
154 |
// first check the OGL system property |
|
155 |
boolean glxRequested = false; |
|
156 |
String prop = System.getProperty("sun.java2d.opengl"); |
|
157 |
if (prop != null) { |
|
158 |
if (prop.equals("true") || prop.equals("t")) { |
|
159 |
glxRequested = true; |
|
160 |
} else if (prop.equals("True") || prop.equals("T")) { |
|
161 |
glxRequested = true; |
|
162 |
glxVerbose = true; |
|
163 |
} |
|
164 |
} |
|
165 |
||
166 |
// initialize the X11 display connection |
|
167 |
initDisplay(glxRequested); |
|
168 |
||
169 |
// only attempt to initialize GLX if it was requested |
|
170 |
if (glxRequested) { |
|
171 |
glxAvailable = initGLX(); |
|
172 |
if (glxVerbose && !glxAvailable) { |
|
173 |
System.out.println( |
|
174 |
"Could not enable OpenGL " + |
|
175 |
"pipeline (GLX 1.3 not available)"); |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
return null; |
|
181 |
} |
|
182 |
}); |
|
557
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
183 |
|
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
184 |
// Install the correct surface manager factory. |
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
185 |
SurfaceManagerFactory.setInstance(new UnixSurfaceManagerFactory()); |
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
186 |
|
2 | 187 |
} |
188 |
||
189 |
private static boolean glxAvailable; |
|
190 |
private static boolean glxVerbose; |
|
191 |
||
192 |
private static native boolean initGLX(); |
|
193 |
||
194 |
public static boolean isGLXAvailable() { |
|
195 |
return glxAvailable; |
|
196 |
} |
|
197 |
||
198 |
public static boolean isGLXVerbose() { |
|
199 |
return glxVerbose; |
|
200 |
} |
|
201 |
||
202 |
/** |
|
203 |
* Checks if Shared Memory extension can be used. |
|
204 |
* Returns: |
|
205 |
* -1 if server doesn't support MITShm |
|
206 |
* 1 if server supports it and it can be used |
|
207 |
* 0 otherwise |
|
208 |
*/ |
|
209 |
private static native int checkShmExt(); |
|
210 |
||
211 |
private static native String getDisplayString(); |
|
212 |
private static Boolean isDisplayLocal; |
|
213 |
||
214 |
/** |
|
215 |
* This should only be called from the static initializer, so no need for |
|
216 |
* the synchronized keyword. |
|
217 |
*/ |
|
218 |
private static native void initDisplay(boolean glxRequested); |
|
219 |
||
220 |
public X11GraphicsEnvironment() { |
|
221 |
} |
|
222 |
||
223 |
protected native int getNumScreens(); |
|
224 |
||
225 |
protected GraphicsDevice makeScreenDevice(int screennum) { |
|
226 |
return new X11GraphicsDevice(screennum); |
|
227 |
} |
|
228 |
||
229 |
protected native int getDefaultScreenNum(); |
|
230 |
/** |
|
231 |
* Returns the default screen graphics device. |
|
232 |
*/ |
|
233 |
public GraphicsDevice getDefaultScreenDevice() { |
|
234 |
return getScreenDevices()[getDefaultScreenNum()]; |
|
235 |
} |
|
236 |
||
237 |
public static boolean isDisplayLocal() { |
|
238 |
if (isDisplayLocal == null) { |
|
239 |
SunToolkit.awtLock(); |
|
240 |
try { |
|
241 |
if (isDisplayLocal == null) { |
|
242 |
isDisplayLocal = Boolean.valueOf(_isDisplayLocal()); |
|
243 |
} |
|
244 |
} finally { |
|
245 |
SunToolkit.awtUnlock(); |
|
246 |
} |
|
247 |
} |
|
248 |
return isDisplayLocal.booleanValue(); |
|
249 |
} |
|
250 |
||
251 |
private static boolean _isDisplayLocal() { |
|
252 |
if (isHeadless()) { |
|
253 |
return true; |
|
254 |
} |
|
255 |
||
256 |
String isRemote = (String)java.security.AccessController.doPrivileged( |
|
257 |
new sun.security.action.GetPropertyAction("sun.java2d.remote")); |
|
258 |
if (isRemote != null) { |
|
259 |
return isRemote.equals("false"); |
|
260 |
} |
|
261 |
||
262 |
int shm = checkShmExt(); |
|
263 |
if (shm != -1) { |
|
264 |
return (shm == 1); |
|
265 |
} |
|
266 |
||
267 |
// If XServer doesn't support ShMem extension, |
|
268 |
// try the other way |
|
269 |
||
270 |
String display = getDisplayString(); |
|
271 |
int ind = display.indexOf(':'); |
|
272 |
final String hostName = display.substring(0, ind); |
|
273 |
if (ind <= 0) { |
|
274 |
// ':0' case |
|
275 |
return true; |
|
276 |
} |
|
277 |
||
278 |
Boolean result = (Boolean)java.security.AccessController.doPrivileged( |
|
279 |
new java.security.PrivilegedAction() { |
|
280 |
public Object run() { |
|
281 |
InetAddress remAddr[] = null; |
|
282 |
Enumeration locals = null; |
|
283 |
Enumeration interfaces = null; |
|
284 |
try { |
|
285 |
interfaces = NetworkInterface.getNetworkInterfaces(); |
|
286 |
remAddr = InetAddress.getAllByName(hostName); |
|
287 |
if (remAddr == null) { |
|
288 |
return Boolean.FALSE; |
|
289 |
} |
|
290 |
} catch (UnknownHostException e) { |
|
291 |
System.err.println("Unknown host: " + hostName); |
|
292 |
return Boolean.FALSE; |
|
293 |
} catch (SocketException e1) { |
|
294 |
System.err.println(e1.getMessage()); |
|
295 |
return Boolean.FALSE; |
|
296 |
} |
|
297 |
||
298 |
for (; interfaces.hasMoreElements();) { |
|
299 |
locals = ((NetworkInterface)interfaces.nextElement()).getInetAddresses(); |
|
300 |
for (; locals.hasMoreElements();) { |
|
301 |
for (int i = 0; i < remAddr.length; i++) { |
|
302 |
if (locals.nextElement().equals(remAddr[i])) { |
|
303 |
return Boolean.TRUE; |
|
304 |
} |
|
305 |
} |
|
306 |
} |
|
307 |
} |
|
308 |
return Boolean.FALSE; |
|
309 |
}}); |
|
310 |
return result.booleanValue(); |
|
311 |
} |
|
312 |
||
313 |
/* These maps are used on Linux where we reference the Lucida oblique |
|
314 |
* fonts in fontconfig files even though they aren't in the standard |
|
315 |
* font directory. This explicitly remaps the XLFDs for these to the |
|
316 |
* correct base font. This is needed to prevent composite fonts from |
|
317 |
* defaulting to the Lucida Sans which is a bad substitute for the |
|
318 |
* monospaced Lucida Sans Typewriter. Also these maps prevent the |
|
319 |
* JRE from doing wasted work at start up. |
|
320 |
*/ |
|
321 |
HashMap<String, String> oblmap = null; |
|
322 |
||
323 |
private String getObliqueLucidaFontID(String fontID) { |
|
324 |
if (fontID.startsWith("-lucidasans-medium-i-normal") || |
|
325 |
fontID.startsWith("-lucidasans-bold-i-normal") || |
|
326 |
fontID.startsWith("-lucidatypewriter-medium-i-normal") || |
|
327 |
fontID.startsWith("-lucidatypewriter-bold-i-normal")) { |
|
328 |
return fontID.substring(0, fontID.indexOf("-i-")); |
|
329 |
} else { |
|
330 |
return null; |
|
331 |
} |
|
332 |
} |
|
333 |
||
334 |
private void initObliqueLucidaFontMap() { |
|
335 |
oblmap = new HashMap<String, String>(); |
|
336 |
oblmap.put("-lucidasans-medium", |
|
337 |
jreLibDirName+"/fonts/LucidaSansRegular.ttf"); |
|
338 |
oblmap.put("-lucidasans-bold", |
|
339 |
jreLibDirName+"/fonts/LucidaSansDemiBold.ttf"); |
|
340 |
oblmap.put("-lucidatypewriter-medium", |
|
341 |
jreLibDirName+"/fonts/LucidaTypewriterRegular.ttf"); |
|
342 |
oblmap.put("-lucidatypewriter-bold", |
|
343 |
jreLibDirName+"/fonts/LucidaTypewriterBold.ttf"); |
|
344 |
} |
|
345 |
||
346 |
/** |
|
347 |
* Takes family name property in the following format: |
|
348 |
* "-linotype-helvetica-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1" |
|
349 |
* and returns the name of the corresponding physical font. |
|
350 |
* This code is used to resolve font configuration fonts, and expects |
|
351 |
* only to get called for these fonts. |
|
352 |
*/ |
|
353 |
public String getFileNameFromPlatformName(String platName) { |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
354 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
355 |
/* If the FontConfig file doesn't use xlfds, or its |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
356 |
* FcFontConfiguration, this may be already a file name. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
357 |
*/ |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
358 |
if (platName.startsWith("/")) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
359 |
return platName; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
360 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
361 |
|
2 | 362 |
String fileName = null; |
363 |
String fontID = specificFontIDForName(platName); |
|
364 |
||
365 |
/* If the font filename has been explicitly assigned in the |
|
366 |
* font configuration file, use it. This avoids accessing |
|
367 |
* the wrong fonts on Linux, where different fonts (some |
|
368 |
* of which may not be usable by 2D) may share the same |
|
369 |
* specific font ID. It may also speed up the lookup. |
|
370 |
*/ |
|
371 |
fileName = super.getFileNameFromPlatformName(platName); |
|
372 |
if (fileName != null) { |
|
373 |
if (isHeadless() && fileName.startsWith("-")) { |
|
374 |
/* if it's headless, no xlfd should be used */ |
|
375 |
return null; |
|
376 |
} |
|
377 |
if (fileName.startsWith("/")) { |
|
378 |
/* If a path is assigned in the font configuration file, |
|
379 |
* it is required that the config file also specify using the |
|
380 |
* new awtfontpath key the X11 font directories |
|
381 |
* which must be added to the X11 font path to support |
|
382 |
* AWT access to that font. For that reason we no longer |
|
383 |
* have code here to add the parent directory to the list |
|
384 |
* of font config dirs, since the parent directory may not |
|
385 |
* be sufficient if fonts are symbolically linked to a |
|
386 |
* different directory. |
|
387 |
* |
|
388 |
* Add this XLFD (platform name) to the list of known |
|
389 |
* ones for this file. |
|
390 |
*/ |
|
391 |
Vector xVal = (Vector) xlfdMap.get(fileName); |
|
392 |
if (xVal == null) { |
|
393 |
/* Try to be robust on Linux distros which move fonts |
|
394 |
* around by verifying that the fileName represents a |
|
395 |
* file that exists. If it doesn't, set it to null |
|
396 |
* to trigger a search. |
|
397 |
*/ |
|
398 |
if (getFontConfiguration().needToSearchForFile(fileName)) { |
|
399 |
fileName = null; |
|
400 |
} |
|
401 |
if (fileName != null) { |
|
402 |
xVal = new Vector(); |
|
403 |
xVal.add(platName); |
|
404 |
xlfdMap.put(fileName, xVal); |
|
405 |
} |
|
406 |
} else { |
|
407 |
if (!xVal.contains(platName)) { |
|
408 |
xVal.add(platName); |
|
409 |
} |
|
410 |
} |
|
411 |
} |
|
412 |
if (fileName != null) { |
|
413 |
fontNameMap.put(fontID, fileName); |
|
414 |
return fileName; |
|
415 |
} |
|
416 |
} |
|
417 |
||
418 |
if (fontID != null) { |
|
419 |
fileName = (String)fontNameMap.get(fontID); |
|
420 |
/* On Linux check for the Lucida Oblique fonts */ |
|
421 |
if (fileName == null && isLinux && !isOpenJDK()) { |
|
422 |
if (oblmap == null) { |
|
423 |
initObliqueLucidaFontMap(); |
|
424 |
} |
|
425 |
String oblkey = getObliqueLucidaFontID(fontID); |
|
426 |
if (oblkey != null) { |
|
427 |
fileName = oblmap.get(oblkey); |
|
428 |
} |
|
429 |
} |
|
430 |
if (fontPath == null && |
|
431 |
(fileName == null || !fileName.startsWith("/"))) { |
|
432 |
if (debugFonts) { |
|
433 |
logger.warning("** Registering all font paths because " + |
|
434 |
"can't find file for " + platName); |
|
435 |
} |
|
436 |
fontPath = getPlatformFontPath(noType1Font); |
|
437 |
registerFontDirs(fontPath); |
|
438 |
if (debugFonts) { |
|
439 |
logger.warning("** Finished registering all font paths"); |
|
440 |
} |
|
441 |
fileName = (String)fontNameMap.get(fontID); |
|
442 |
} |
|
443 |
if (fileName == null && !isHeadless()) { |
|
444 |
/* Query X11 directly to see if this font is available |
|
445 |
* as a native font. |
|
446 |
*/ |
|
447 |
fileName = getX11FontName(platName); |
|
448 |
} |
|
449 |
if (fileName == null) { |
|
450 |
fontID = switchFontIDForName(platName); |
|
451 |
fileName = (String)fontNameMap.get(fontID); |
|
452 |
} |
|
453 |
if (fileName != null) { |
|
454 |
fontNameMap.put(fontID, fileName); |
|
455 |
} |
|
456 |
} |
|
457 |
return fileName; |
|
458 |
} |
|
459 |
||
460 |
private static String getX11FontName(String platName) { |
|
461 |
String xlfd = platName.replaceAll("%d", "*"); |
|
462 |
if (NativeFont.fontExists(xlfd)) { |
|
463 |
return xlfd; |
|
464 |
} else { |
|
465 |
return null; |
|
466 |
} |
|
467 |
} |
|
468 |
||
469 |
/** |
|
470 |
* Returns the face name for the given XLFD. |
|
471 |
*/ |
|
472 |
public String getFileNameFromXLFD(String name) { |
|
473 |
String fileName = null; |
|
474 |
String fontID = specificFontIDForName(name); |
|
475 |
if (fontID != null) { |
|
476 |
fileName = (String)fontNameMap.get(fontID); |
|
477 |
if (fileName == null) { |
|
478 |
fontID = switchFontIDForName(name); |
|
479 |
fileName = (String)fontNameMap.get(fontID); |
|
480 |
} |
|
481 |
if (fileName == null) { |
|
482 |
fileName = getDefaultFontFile(); |
|
483 |
} |
|
484 |
} |
|
485 |
return fileName; |
|
486 |
} |
|
487 |
||
488 |
// constants identifying XLFD and font ID fields |
|
489 |
private static final int FOUNDRY_FIELD = 1; |
|
490 |
private static final int FAMILY_NAME_FIELD = 2; |
|
491 |
private static final int WEIGHT_NAME_FIELD = 3; |
|
492 |
private static final int SLANT_FIELD = 4; |
|
493 |
private static final int SETWIDTH_NAME_FIELD = 5; |
|
494 |
private static final int ADD_STYLE_NAME_FIELD = 6; |
|
495 |
private static final int PIXEL_SIZE_FIELD = 7; |
|
496 |
private static final int POINT_SIZE_FIELD = 8; |
|
497 |
private static final int RESOLUTION_X_FIELD = 9; |
|
498 |
private static final int RESOLUTION_Y_FIELD = 10; |
|
499 |
private static final int SPACING_FIELD = 11; |
|
500 |
private static final int AVERAGE_WIDTH_FIELD = 12; |
|
501 |
private static final int CHARSET_REGISTRY_FIELD = 13; |
|
502 |
private static final int CHARSET_ENCODING_FIELD = 14; |
|
503 |
||
504 |
private String switchFontIDForName(String name) { |
|
505 |
||
506 |
int[] hPos = new int[14]; |
|
507 |
int hyphenCnt = 1; |
|
508 |
int pos = 1; |
|
509 |
||
510 |
while (pos != -1 && hyphenCnt < 14) { |
|
511 |
pos = name.indexOf('-', pos); |
|
512 |
if (pos != -1) { |
|
513 |
hPos[hyphenCnt++] = pos; |
|
514 |
pos++; |
|
515 |
} |
|
516 |
} |
|
517 |
||
518 |
if (hyphenCnt != 14) { |
|
519 |
if (debugFonts) { |
|
520 |
logger.severe("Font Configuration Font ID is malformed:" + name); |
|
521 |
} |
|
522 |
return name; // what else can we do? |
|
523 |
} |
|
524 |
||
525 |
String slant = name.substring(hPos[SLANT_FIELD-1]+1, |
|
526 |
hPos[SLANT_FIELD]); |
|
527 |
String family = name.substring(hPos[FAMILY_NAME_FIELD-1]+1, |
|
528 |
hPos[FAMILY_NAME_FIELD]); |
|
529 |
String registry = name.substring(hPos[CHARSET_REGISTRY_FIELD-1]+1, |
|
530 |
hPos[CHARSET_REGISTRY_FIELD]); |
|
531 |
String encoding = name.substring(hPos[CHARSET_ENCODING_FIELD-1]+1); |
|
532 |
||
533 |
if (slant.equals("i")) { |
|
534 |
slant = "o"; |
|
535 |
} else if (slant.equals("o")) { |
|
536 |
slant = "i"; |
|
537 |
} |
|
538 |
// workaround for #4471000 |
|
539 |
if (family.equals("itc zapfdingbats") |
|
540 |
&& registry.equals("sun") |
|
541 |
&& encoding.equals("fontspecific")){ |
|
542 |
registry = "adobe"; |
|
543 |
} |
|
544 |
StringBuffer sb = |
|
545 |
new StringBuffer(name.substring(hPos[FAMILY_NAME_FIELD-1], |
|
546 |
hPos[SLANT_FIELD-1]+1)); |
|
547 |
sb.append(slant); |
|
548 |
sb.append(name.substring(hPos[SLANT_FIELD], |
|
549 |
hPos[SETWIDTH_NAME_FIELD]+1)); |
|
550 |
sb.append(registry); |
|
551 |
sb.append(name.substring(hPos[CHARSET_ENCODING_FIELD-1])); |
|
552 |
String retval = sb.toString().toLowerCase (Locale.ENGLISH); |
|
553 |
return retval; |
|
554 |
} |
|
555 |
||
556 |
||
557 |
private String specificFontIDForName(String name) { |
|
558 |
||
559 |
int[] hPos = new int[14]; |
|
560 |
int hyphenCnt = 1; |
|
561 |
int pos = 1; |
|
562 |
||
563 |
while (pos != -1 && hyphenCnt < 14) { |
|
564 |
pos = name.indexOf('-', pos); |
|
565 |
if (pos != -1) { |
|
566 |
hPos[hyphenCnt++] = pos; |
|
567 |
pos++; |
|
568 |
} |
|
569 |
} |
|
570 |
||
571 |
if (hyphenCnt != 14) { |
|
572 |
if (debugFonts) { |
|
573 |
logger.severe("Font Configuration Font ID is malformed:" + name); |
|
574 |
} |
|
575 |
return name; // what else can we do? |
|
576 |
} |
|
577 |
||
578 |
StringBuffer sb = |
|
579 |
new StringBuffer(name.substring(hPos[FAMILY_NAME_FIELD-1], |
|
580 |
hPos[SETWIDTH_NAME_FIELD])); |
|
581 |
sb.append(name.substring(hPos[CHARSET_REGISTRY_FIELD-1])); |
|
582 |
String retval = sb.toString().toLowerCase (Locale.ENGLISH); |
|
583 |
return retval; |
|
584 |
} |
|
585 |
||
586 |
protected String[] getNativeNames(String fontFileName, |
|
587 |
String platformName) { |
|
588 |
Vector nativeNames; |
|
589 |
if ((nativeNames=(Vector)xlfdMap.get(fontFileName))==null) { |
|
590 |
if (platformName == null) { |
|
591 |
return null; |
|
592 |
} else { |
|
593 |
/* back-stop so that at least the name used in the |
|
594 |
* font configuration file is known as a native name |
|
595 |
*/ |
|
596 |
String []natNames = new String[1]; |
|
597 |
natNames[0] = platformName; |
|
598 |
return natNames; |
|
599 |
} |
|
600 |
} else { |
|
601 |
int len = nativeNames.size(); |
|
602 |
return (String[])nativeNames.toArray(new String[len]); |
|
603 |
} |
|
604 |
} |
|
605 |
||
606 |
||
607 |
// An X font spec (xlfd) includes an encoding. The same TrueType font file |
|
608 |
// may be referenced from different X font directories in font.dir files |
|
609 |
// to support use in multiple encodings by X apps. |
|
610 |
// So for the purposes of font configuration logical fonts where AWT |
|
611 |
// heavyweights need to access the font via X APIs we need to ensure that |
|
612 |
// the directory for precisely the encodings needed by this are added to |
|
613 |
// the x font path. This requires that we note the platform names |
|
614 |
// specified in font configuration files and use that to identify the |
|
615 |
// X font directory that contains a font.dir file for that platform name |
|
616 |
// and add it to the X font path (if display is local) |
|
617 |
// Here we make use of an already built map of xlfds to font locations |
|
618 |
// to add the font location to the set of those required to build the |
|
619 |
// x font path needed by AWT. |
|
620 |
// These are added to the x font path later. |
|
621 |
// All this is necessary because on Solaris the font.dir directories |
|
622 |
// may contain not real font files, but symbolic links to the actual |
|
623 |
// location but that location is not suitable for the x font path, since |
|
624 |
// it probably doesn't have a font.dir at all and certainly not one |
|
625 |
// with the required encodings |
|
626 |
// If the fontconfiguration file is properly set up so that all fonts |
|
627 |
// are mapped to files then we will never trigger initialising |
|
628 |
// xFontDirsMap (it will be null). In this case the awtfontpath entries |
|
629 |
// must specify all the X11 directories needed by AWT. |
|
630 |
protected void addFontToPlatformFontPath(String platformName) { |
|
631 |
if (xFontDirsMap != null) { |
|
632 |
String fontID = specificFontIDForName(platformName); |
|
633 |
String dirName = (String)xFontDirsMap.get(fontID); |
|
634 |
if (dirName != null) { |
|
635 |
fontConfigDirs.add(dirName); |
|
636 |
} |
|
637 |
} |
|
638 |
return; |
|
639 |
} |
|
640 |
||
641 |
protected void getPlatformFontPathFromFontConfig() { |
|
642 |
if (fontConfigDirs == null) { |
|
643 |
fontConfigDirs = getFontConfiguration().getAWTFontPathSet(); |
|
644 |
if (debugFonts && fontConfigDirs != null) { |
|
645 |
String[] names = fontConfigDirs.toArray(new String[0]); |
|
646 |
for (int i=0;i<names.length;i++) { |
|
647 |
logger.info("awtfontpath : " + names[i]); |
|
648 |
} |
|
649 |
} |
|
650 |
} |
|
651 |
} |
|
652 |
||
653 |
protected void registerPlatformFontsUsedByFontConfiguration() { |
|
654 |
if (fontConfigDirs == null) { |
|
655 |
return; |
|
656 |
} |
|
657 |
if (isLinux) { |
|
658 |
fontConfigDirs.add(jreLibDirName+File.separator+"oblique-fonts"); |
|
659 |
} |
|
660 |
fontdirs = (String[])fontConfigDirs.toArray(new String[0]); |
|
661 |
} |
|
662 |
||
663 |
/* Called by MToolkit to set the X11 font path */ |
|
664 |
public static void setNativeFontPath() { |
|
665 |
if (fontdirs == null) { |
|
666 |
return; |
|
667 |
} |
|
668 |
||
669 |
// need to register these individually rather than by one call |
|
670 |
// to ensure that one bad directory doesn't cause all to be rejected |
|
671 |
for (int i=0; i<fontdirs.length; i++) { |
|
672 |
if (debugFonts) { |
|
673 |
logger.info("Add " + fontdirs[i] + " to X11 fontpath"); |
|
674 |
} |
|
675 |
FontManager.setNativeFontPath(fontdirs[i]); |
|
676 |
} |
|
677 |
} |
|
678 |
||
679 |
/* Register just the paths, (it doesn't register the fonts). |
|
680 |
* If a font configuration file has specified a baseFontPath |
|
681 |
* fontPath is just those directories, unless on usage we |
|
682 |
* find it doesn't contain what we need for the logical fonts. |
|
683 |
* Otherwise, we register all the paths on Solaris, because |
|
684 |
* the fontPath we have here is the complete one from |
|
685 |
* parsing /var/sadm/install/contents, not just |
|
686 |
* what's on the X font path (may be this should be |
|
687 |
* changed). |
|
688 |
* But for now what it means is that if we didn't do |
|
689 |
* this then if the font weren't listed anywhere on the |
|
690 |
* less complete font path we'd trigger loadFonts which |
|
691 |
* actually registers the fonts. This may actually be |
|
692 |
* the right thing tho' since that would also set up |
|
693 |
* the X font path without which we wouldn't be able to |
|
694 |
* display some "native" fonts. |
|
695 |
* So something to revisit is that probably fontPath |
|
696 |
* here ought to be only the X font path + jre font dir. |
|
697 |
* loadFonts should have a separate native call to |
|
698 |
* get the rest of the platform font path. |
|
699 |
* |
|
700 |
* Registering the directories can now be avoided in the |
|
701 |
* font configuration initialisation when filename entries |
|
702 |
* exist in the font configuration file for all fonts. |
|
703 |
* (Perhaps a little confusingly a filename entry is |
|
704 |
* actually keyed using the XLFD used in the font entries, |
|
705 |
* and it maps *to* a real filename). |
|
706 |
* In the event any are missing, registration of all |
|
707 |
* directories will be invoked to find the real files. |
|
708 |
* |
|
709 |
* But registering the directory performed other |
|
710 |
* functions such as filling in the map of all native names |
|
711 |
* for the font. So when this method isn't invoked, they still |
|
712 |
* must be found. This is mitigated by getNativeNames now |
|
713 |
* being able to return at least the platform name, but mostly |
|
714 |
* by ensuring that when a filename key is found, that |
|
715 |
* xlfd key is stored as one of the set of platform names |
|
716 |
* for the font. Its a set because typical font configuration |
|
717 |
* files reference the same CJK font files using multiple |
|
718 |
* X11 encodings. For the code that adds this to the map |
|
719 |
* see X11GE.getFileNameFromPlatformName(..) |
|
720 |
* If you don't get all of these then some code points may |
|
721 |
* not use the Xserver, and will not get the PCF bitmaps |
|
722 |
* that are available for some point sizes. |
|
723 |
* So, in the event that there is such a problem, |
|
724 |
* unconditionally making this call may be necessary, at |
|
725 |
* some cost to JRE start-up |
|
726 |
*/ |
|
727 |
protected void registerFontDirs(String pathName) { |
|
728 |
||
729 |
StringTokenizer parser = new StringTokenizer(pathName, |
|
730 |
File.pathSeparator); |
|
731 |
try { |
|
732 |
while (parser.hasMoreTokens()) { |
|
733 |
String dirPath = parser.nextToken(); |
|
734 |
if (dirPath != null && !registeredDirs.containsKey(dirPath)) { |
|
735 |
registeredDirs.put(dirPath, null); |
|
736 |
registerFontDir(dirPath); |
|
737 |
} |
|
738 |
} |
|
739 |
} catch (NoSuchElementException e) { |
|
740 |
} |
|
741 |
} |
|
742 |
||
743 |
/* NOTE: this method needs to be executed in a privileged context. |
|
744 |
* The superclass constructor which is the primary caller of |
|
745 |
* this method executes entirely in such a context. Additionally |
|
746 |
* the loadFonts() method does too. So all should be well. |
|
747 |
||
748 |
*/ |
|
749 |
protected void registerFontDir(String path) { |
|
750 |
/* fonts.dir file format looks like :- |
|
751 |
* 47 |
|
752 |
* Arial.ttf -monotype-arial-regular-r-normal--0-0-0-0-p-0-iso8859-1 |
|
753 |
* Arial-Bold.ttf -monotype-arial-bold-r-normal--0-0-0-0-p-0-iso8859-1 |
|
754 |
* ... |
|
755 |
*/ |
|
756 |
if (debugFonts) { |
|
757 |
logger.info("ParseFontDir " + path); |
|
758 |
} |
|
759 |
File fontsDotDir = new File(path + File.separator + "fonts.dir"); |
|
760 |
FileReader fr = null; |
|
761 |
try { |
|
762 |
if (fontsDotDir.canRead()) { |
|
763 |
fr = new FileReader(fontsDotDir); |
|
764 |
BufferedReader br = new BufferedReader(fr, 8192); |
|
765 |
StreamTokenizer st = new StreamTokenizer(br); |
|
766 |
st.eolIsSignificant(true); |
|
767 |
int ttype = st.nextToken(); |
|
768 |
if (ttype == StreamTokenizer.TT_NUMBER) { |
|
769 |
int numEntries = (int)st.nval; |
|
770 |
ttype = st.nextToken(); |
|
771 |
if (ttype == StreamTokenizer.TT_EOL) { |
|
772 |
st.resetSyntax(); |
|
773 |
st.wordChars(32, 127); |
|
774 |
st.wordChars(128 + 32, 255); |
|
775 |
st.whitespaceChars(0, 31); |
|
776 |
||
777 |
for (int i=0; i < numEntries; i++) { |
|
778 |
ttype = st.nextToken(); |
|
779 |
if (ttype == StreamTokenizer.TT_EOF) { |
|
780 |
break; |
|
781 |
} |
|
782 |
if (ttype != StreamTokenizer.TT_WORD) { |
|
783 |
break; |
|
784 |
} |
|
785 |
int breakPos = st.sval.indexOf(' '); |
|
786 |
if (breakPos <= 0) { |
|
787 |
/* On TurboLinux 8.0 a fonts.dir file had |
|
788 |
* a line with integer value "24" which |
|
789 |
* appeared to be the number of remaining |
|
790 |
* entries in the file. This didn't add to |
|
791 |
* the value on the first line of the file. |
|
792 |
* Seemed like XFree86 didn't like this line |
|
793 |
* much either. It failed to parse the file. |
|
794 |
* Ignore lines like this completely, and |
|
795 |
* don't let them count as an entry. |
|
796 |
*/ |
|
797 |
numEntries++; |
|
798 |
ttype = st.nextToken(); |
|
799 |
if (ttype != StreamTokenizer.TT_EOL) { |
|
800 |
break; |
|
801 |
} |
|
802 |
||
803 |
continue; |
|
804 |
} |
|
805 |
if (st.sval.charAt(0) == '!') { |
|
806 |
/* TurboLinux 8.0 comment line: ignore. |
|
807 |
* can't use st.commentChar('!') to just |
|
808 |
* skip because this line mustn't count |
|
809 |
* against numEntries. |
|
810 |
*/ |
|
811 |
numEntries++; |
|
812 |
ttype = st.nextToken(); |
|
813 |
if (ttype != StreamTokenizer.TT_EOL) { |
|
814 |
break; |
|
815 |
} |
|
816 |
continue; |
|
817 |
} |
|
818 |
String fileName = st.sval.substring(0, breakPos); |
|
819 |
/* TurboLinux 8.0 uses some additional syntax to |
|
820 |
* indicate algorithmic styling values. |
|
821 |
* Ignore ':' separated files at the beginning |
|
822 |
* of the fileName |
|
823 |
*/ |
|
824 |
int lastColon = fileName.lastIndexOf(':'); |
|
825 |
if (lastColon > 0) { |
|
826 |
if (lastColon+1 >= fileName.length()) { |
|
827 |
continue; |
|
828 |
} |
|
829 |
fileName = fileName.substring(lastColon+1); |
|
830 |
} |
|
831 |
String fontPart = st.sval.substring(breakPos+1); |
|
832 |
String fontID = specificFontIDForName(fontPart); |
|
833 |
String sVal = (String) fontNameMap.get(fontID); |
|
834 |
||
835 |
if (debugFonts) { |
|
836 |
logger.info("file=" + fileName + |
|
837 |
" xlfd=" + fontPart); |
|
838 |
logger.info("fontID=" + fontID + |
|
839 |
" sVal=" + sVal); |
|
840 |
} |
|
841 |
String fullPath = null; |
|
842 |
try { |
|
843 |
File file = new File(path,fileName); |
|
844 |
/* we may have a resolved symbolic link |
|
845 |
* this becomes important for an xlfd we |
|
846 |
* still need to know the location it was |
|
847 |
* found to update the X server font path |
|
848 |
* for use by AWT heavyweights - and when 2D |
|
849 |
* wants to use the native rasteriser. |
|
850 |
*/ |
|
851 |
if (xFontDirsMap == null) { |
|
852 |
xFontDirsMap = new HashMap(); |
|
853 |
} |
|
854 |
xFontDirsMap.put(fontID, path); |
|
855 |
fullPath = file.getCanonicalPath(); |
|
856 |
} catch (IOException e) { |
|
857 |
fullPath = path + File.separator + fileName; |
|
858 |
} |
|
859 |
Vector xVal = (Vector) xlfdMap.get(fullPath); |
|
860 |
if (debugFonts) { |
|
861 |
logger.info("fullPath=" + fullPath + |
|
862 |
" xVal=" + xVal); |
|
863 |
} |
|
864 |
if ((xVal == null || !xVal.contains(fontPart)) && |
|
865 |
(sVal == null) || !sVal.startsWith("/")) { |
|
866 |
if (debugFonts) { |
|
867 |
logger.info("Map fontID:"+fontID + |
|
868 |
"to file:" + fullPath); |
|
869 |
} |
|
870 |
fontNameMap.put(fontID, fullPath); |
|
871 |
if (xVal == null) { |
|
872 |
xVal = new Vector(); |
|
873 |
xlfdMap.put (fullPath, xVal); |
|
874 |
} |
|
875 |
xVal.add(fontPart); |
|
876 |
} |
|
877 |
||
878 |
ttype = st.nextToken(); |
|
879 |
if (ttype != StreamTokenizer.TT_EOL) { |
|
880 |
break; |
|
881 |
} |
|
882 |
} |
|
883 |
} |
|
884 |
} |
|
885 |
fr.close(); |
|
886 |
} |
|
887 |
} catch (IOException ioe1) { |
|
888 |
} finally { |
|
889 |
if (fr != null) { |
|
890 |
try { |
|
891 |
fr.close(); |
|
892 |
} catch (IOException ioe2) { |
|
893 |
} |
|
894 |
} |
|
895 |
} |
|
896 |
} |
|
897 |
||
898 |
@Override |
|
899 |
public void loadFonts() { |
|
900 |
super.loadFonts(); |
|
901 |
/* These maps are greatly expanded during a loadFonts but |
|
902 |
* can be reset to their initial state afterwards. |
|
903 |
* Since preferLocaleFonts() and preferProportionalFonts() will |
|
904 |
* trigger a partial repopulating from the FontConfiguration |
|
905 |
* it has to be the inital (empty) state for the latter two, not |
|
906 |
* simply nulling out. |
|
907 |
* xFontDirsMap is a special case in that the implementation |
|
908 |
* will typically not ever need to initialise it so it can be null. |
|
909 |
*/ |
|
910 |
xFontDirsMap = null; |
|
911 |
xlfdMap = new HashMap(1); |
|
912 |
fontNameMap = new HashMap(1); |
|
913 |
} |
|
914 |
||
915 |
// Implements SunGraphicsEnvironment.createFontConfiguration. |
|
916 |
protected FontConfiguration createFontConfiguration() { |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
917 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
918 |
/* The logic here decides whether to use a preconfigured |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
919 |
* fontconfig.properties file, or synthesise one using platform APIs. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
920 |
* On Solaris (as opposed to OpenSolaris) we try to use the |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
921 |
* pre-configured ones, but if the files it specifies are missing |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
922 |
* we fail-safe to synthesising one. This might happen if Solaris |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
923 |
* changes its fonts. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
924 |
* For OpenSolaris I don't expect us to ever create fontconfig files, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
925 |
* so it will always synthesise. Note that if we misidentify |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
926 |
* OpenSolaris as Solaris, then the test for the presence of |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
927 |
* Solaris-only font files will correct this. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
928 |
* For Linux we require an exact match of distro and version to |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
929 |
* use the preconfigured file, and also that it points to |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
930 |
* existent fonts. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
931 |
* If synthesising fails, we fall back to any preconfigured file |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
932 |
* and do the best we can. For the commercial JDK this will be |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
933 |
* fine as it includes the Lucida fonts. OpenJDK should not hit |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
934 |
* this as the synthesis should always work on its platforms. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
935 |
*/ |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
936 |
FontConfiguration mFontConfig = new MFontConfiguration(this); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
937 |
if (isOpenSolaris || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
938 |
(isLinux && |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
939 |
(!mFontConfig.foundOsSpecificFile() || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
940 |
!mFontConfig.fontFilesArePresent()) || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
941 |
(isSolaris && !mFontConfig.fontFilesArePresent()))) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
942 |
FcFontConfiguration fcFontConfig = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
943 |
new FcFontConfiguration(this); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
944 |
if (fcFontConfig.init()) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
945 |
return fcFontConfig; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
946 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
947 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
948 |
mFontConfig.init(); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
949 |
return mFontConfig; |
2 | 950 |
} |
951 |
public FontConfiguration |
|
952 |
createFontConfiguration(boolean preferLocaleFonts, |
|
953 |
boolean preferPropFonts) { |
|
954 |
||
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
955 |
FontConfiguration config = getFontConfiguration(); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
956 |
if (config instanceof FcFontConfiguration) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
957 |
// Doesn't need to implement the alternate support. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
958 |
return config; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
959 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
960 |
|
2 | 961 |
return new MFontConfiguration(this, |
962 |
preferLocaleFonts, preferPropFonts); |
|
963 |
} |
|
964 |
||
965 |
/** |
|
966 |
* Returns face name for default font, or null if |
|
967 |
* no face names are used for CompositeFontDescriptors |
|
968 |
* for this platform. |
|
969 |
*/ |
|
970 |
public String getDefaultFontFaceName() { |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
971 |
|
2 | 972 |
return null; |
973 |
} |
|
974 |
||
975 |
private static native boolean pRunningXinerama(); |
|
976 |
private static native Point getXineramaCenterPoint(); |
|
977 |
||
978 |
/** |
|
979 |
* Override for Xinerama case: call new Solaris API for getting the correct |
|
980 |
* centering point from the windowing system. |
|
981 |
*/ |
|
982 |
public Point getCenterPoint() { |
|
983 |
if (runningXinerama()) { |
|
984 |
Point p = getXineramaCenterPoint(); |
|
985 |
if (p != null) { |
|
986 |
return p; |
|
987 |
} |
|
988 |
} |
|
989 |
return super.getCenterPoint(); |
|
990 |
} |
|
991 |
||
992 |
/** |
|
993 |
* Override for Xinerama case |
|
994 |
*/ |
|
995 |
public Rectangle getMaximumWindowBounds() { |
|
996 |
if (runningXinerama()) { |
|
997 |
return getXineramaWindowBounds(); |
|
998 |
} else { |
|
999 |
return super.getMaximumWindowBounds(); |
|
1000 |
} |
|
1001 |
} |
|
1002 |
||
1003 |
public boolean runningXinerama() { |
|
1004 |
if (xinerState == null) { |
|
1005 |
// pRunningXinerama() simply returns a global boolean variable, |
|
1006 |
// so there is no need to synchronize here |
|
1007 |
xinerState = Boolean.valueOf(pRunningXinerama()); |
|
1008 |
if (screenLog.isLoggable(Level.FINER)) { |
|
1009 |
screenLog.log(Level.FINER, "Running Xinerama: " + xinerState); |
|
1010 |
} |
|
1011 |
} |
|
1012 |
return xinerState.booleanValue(); |
|
1013 |
} |
|
1014 |
||
1015 |
/** |
|
1016 |
* Return the bounds for a centered Window on a system running in Xinerama |
|
1017 |
* mode. |
|
1018 |
* |
|
1019 |
* Calculations are based on the assumption of a perfectly rectangular |
|
1020 |
* display area (display edges line up with one another, and displays |
|
1021 |
* have consistent width and/or height). |
|
1022 |
* |
|
1023 |
* The bounds to return depend on the arrangement of displays and on where |
|
1024 |
* Windows are to be centered. There are two common situations: |
|
1025 |
* |
|
1026 |
* 1) The center point lies at the center of the combined area of all the |
|
1027 |
* displays. In this case, the combined area of all displays is |
|
1028 |
* returned. |
|
1029 |
* |
|
1030 |
* 2) The center point lies at the center of a single display. In this case |
|
1031 |
* the user most likely wants centered Windows to be constrained to that |
|
1032 |
* single display. The boundaries of the one display are returned. |
|
1033 |
* |
|
1034 |
* It is possible for the center point to be at both the center of the |
|
1035 |
* entire display space AND at the center of a single monitor (a square of |
|
1036 |
* 9 monitors, for instance). In this case, the entire display area is |
|
1037 |
* returned. |
|
1038 |
* |
|
1039 |
* Because the center point is arbitrarily settable by the user, it could |
|
1040 |
* fit neither of the cases above. The fallback case is to simply return |
|
1041 |
* the combined area for all screens. |
|
1042 |
*/ |
|
1043 |
protected Rectangle getXineramaWindowBounds() { |
|
1044 |
Point center = getCenterPoint(); |
|
1045 |
Rectangle unionRect, tempRect; |
|
1046 |
GraphicsDevice[] gds = getScreenDevices(); |
|
1047 |
Rectangle centerMonitorRect = null; |
|
1048 |
int i; |
|
1049 |
||
1050 |
// if center point is at the center of all monitors |
|
1051 |
// return union of all bounds |
|
1052 |
// |
|
1053 |
// MM*MM MMM M |
|
1054 |
// M*M * |
|
1055 |
// MMM M |
|
1056 |
||
1057 |
// if center point is at center of a single monitor (but not of all |
|
1058 |
// monitors) |
|
1059 |
// return bounds of single monitor |
|
1060 |
// |
|
1061 |
// MMM MM |
|
1062 |
// MM* *M |
|
1063 |
||
1064 |
// else, center is in some strange spot (such as on the border between |
|
1065 |
// monitors), and we should just return the union of all monitors |
|
1066 |
// |
|
1067 |
// MM MMM |
|
1068 |
// MM MMM |
|
1069 |
||
1070 |
unionRect = getUsableBounds(gds[0]); |
|
1071 |
||
1072 |
for (i = 0; i < gds.length; i++) { |
|
1073 |
tempRect = getUsableBounds(gds[i]); |
|
1074 |
if (centerMonitorRect == null && |
|
1075 |
// add a pixel or two for fudge-factor |
|
1076 |
(tempRect.width / 2) + tempRect.x > center.x - 1 && |
|
1077 |
(tempRect.height / 2) + tempRect.y > center.y - 1 && |
|
1078 |
(tempRect.width / 2) + tempRect.x < center.x + 1 && |
|
1079 |
(tempRect.height / 2) + tempRect.y < center.y + 1) { |
|
1080 |
centerMonitorRect = tempRect; |
|
1081 |
} |
|
1082 |
unionRect = unionRect.union(tempRect); |
|
1083 |
} |
|
1084 |
||
1085 |
// first: check for center of all monitors (video wall) |
|
1086 |
// add a pixel or two for fudge-factor |
|
1087 |
if ((unionRect.width / 2) + unionRect.x > center.x - 1 && |
|
1088 |
(unionRect.height / 2) + unionRect.y > center.y - 1 && |
|
1089 |
(unionRect.width / 2) + unionRect.x < center.x + 1 && |
|
1090 |
(unionRect.height / 2) + unionRect.y < center.y + 1) { |
|
1091 |
||
1092 |
if (screenLog.isLoggable(Level.FINER)) { |
|
1093 |
screenLog.log(Level.FINER, "Video Wall: center point is at center of all displays."); |
|
1094 |
} |
|
1095 |
return unionRect; |
|
1096 |
} |
|
1097 |
||
1098 |
// next, check if at center of one monitor |
|
1099 |
if (centerMonitorRect != null) { |
|
1100 |
if (screenLog.isLoggable(Level.FINER)) { |
|
1101 |
screenLog.log(Level.FINER, "Center point at center of a particular " + |
|
1102 |
"monitor, but not of the entire virtual display."); |
|
1103 |
} |
|
1104 |
return centerMonitorRect; |
|
1105 |
} |
|
1106 |
||
1107 |
// otherwise, the center is at some weird spot: return unionRect |
|
1108 |
if (screenLog.isLoggable(Level.FINER)) { |
|
1109 |
screenLog.log(Level.FINER, "Center point is somewhere strange - return union of all bounds."); |
|
1110 |
} |
|
1111 |
return unionRect; |
|
1112 |
} |
|
1113 |
||
1114 |
/** |
|
1115 |
* From the DisplayChangedListener interface; devices do not need |
|
1116 |
* to react to this event. |
|
1117 |
*/ |
|
1118 |
@Override |
|
1119 |
public void paletteChanged() { |
|
1120 |
} |
|
1121 |
} |