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