author | prr |
Thu, 12 Jun 2008 13:17:33 -0700 | |
changeset 883 | c3e81f0acd3d |
parent 557 | 800259d3792b |
child 887 | 0aab8d3fa11a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright 1997-2006 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.GraphicsEnvironment; |
|
30 |
import java.awt.Toolkit; |
|
31 |
import java.io.File; |
|
32 |
import java.io.IOException; |
|
33 |
import java.lang.ref.WeakReference; |
|
34 |
import java.util.ArrayList; |
|
35 |
import java.util.ListIterator; |
|
36 |
import java.util.NoSuchElementException; |
|
37 |
import java.util.StringTokenizer; |
|
38 |
import sun.awt.DisplayChangedListener; |
|
39 |
import sun.awt.SunDisplayChanger; |
|
40 |
import sun.awt.windows.WFontConfiguration; |
|
41 |
import sun.awt.windows.WPrinterJob; |
|
42 |
import sun.awt.windows.WToolkit; |
|
43 |
import sun.font.FontManager; |
|
44 |
import sun.java2d.SunGraphicsEnvironment; |
|
557
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
550
diff
changeset
|
45 |
import sun.java2d.SurfaceManagerFactory; |
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
550
diff
changeset
|
46 |
import sun.java2d.WindowsSurfaceManagerFactory; |
2 | 47 |
import sun.java2d.windows.WindowsFlags; |
48 |
||
49 |
/** |
|
50 |
* This is an implementation of a GraphicsEnvironment object for the |
|
51 |
* default local GraphicsEnvironment used by the Java Runtime Environment |
|
52 |
* for Windows. |
|
53 |
* |
|
54 |
* @see GraphicsDevice |
|
55 |
* @see GraphicsConfiguration |
|
56 |
*/ |
|
57 |
||
58 |
public class Win32GraphicsEnvironment |
|
59 |
extends SunGraphicsEnvironment |
|
60 |
{ |
|
61 |
static { |
|
62 |
// Ensure awt is loaded already. Also, this forces static init |
|
63 |
// of WToolkit and Toolkit, which we depend upon |
|
64 |
WToolkit.loadLibraries(); |
|
65 |
// setup flags before initializing native layer |
|
66 |
WindowsFlags.initFlags(); |
|
67 |
initDisplayWrapper(); |
|
68 |
eudcFontFileName = getEUDCFontFile(); |
|
557
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
550
diff
changeset
|
69 |
|
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
550
diff
changeset
|
70 |
// Install correct surface manager factory. |
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
550
diff
changeset
|
71 |
SurfaceManagerFactory.setInstance(new WindowsSurfaceManagerFactory()); |
2 | 72 |
} |
73 |
||
74 |
/** |
|
75 |
* Noop function that just acts as an entry point for someone to force |
|
76 |
* a static initialization of this class. |
|
77 |
*/ |
|
78 |
public static void init() {} |
|
79 |
||
80 |
/** |
|
81 |
* Initializes native components of the graphics environment. This |
|
82 |
* includes everything from the native GraphicsDevice elements to |
|
83 |
* the DirectX rendering layer. |
|
84 |
*/ |
|
85 |
private static native void initDisplay(); |
|
86 |
||
87 |
private static boolean displayInitialized; // = false; |
|
88 |
public static void initDisplayWrapper() { |
|
89 |
if (!displayInitialized) { |
|
90 |
displayInitialized = true; |
|
91 |
initDisplay(); |
|
92 |
} |
|
93 |
} |
|
94 |
||
95 |
public Win32GraphicsEnvironment() { |
|
96 |
} |
|
97 |
||
98 |
protected native int getNumScreens(); |
|
99 |
protected native int getDefaultScreen(); |
|
100 |
||
101 |
public GraphicsDevice getDefaultScreenDevice() { |
|
102 |
return getScreenDevices()[getDefaultScreen()]; |
|
103 |
} |
|
104 |
||
105 |
/** |
|
106 |
* Returns the number of pixels per logical inch along the screen width. |
|
107 |
* In a system with multiple display monitors, this value is the same for |
|
108 |
* all monitors. |
|
109 |
* @returns number of pixels per logical inch in X direction |
|
110 |
*/ |
|
111 |
public native int getXResolution(); |
|
112 |
/** |
|
113 |
* Returns the number of pixels per logical inch along the screen height. |
|
114 |
* In a system with multiple display monitors, this value is the same for |
|
115 |
* all monitors. |
|
116 |
* @returns number of pixels per logical inch in Y direction |
|
117 |
*/ |
|
118 |
public native int getYResolution(); |
|
119 |
||
120 |
||
121 |
/* |
|
122 |
* ----DISPLAY CHANGE SUPPORT---- |
|
123 |
*/ |
|
124 |
||
125 |
// list of invalidated graphics devices (those which were removed) |
|
126 |
private ArrayList<WeakReference<Win32GraphicsDevice>> oldDevices; |
|
127 |
/* |
|
128 |
* From DisplayChangeListener interface. |
|
129 |
* Called from WToolkit and executed on the event thread when the |
|
130 |
* display settings are changed. |
|
131 |
*/ |
|
132 |
@Override |
|
133 |
public void displayChanged() { |
|
134 |
// getNumScreens() will return the correct current number of screens |
|
135 |
GraphicsDevice newDevices[] = new GraphicsDevice[getNumScreens()]; |
|
136 |
GraphicsDevice oldScreens[] = screens; |
|
137 |
// go through the list of current devices and determine if they |
|
138 |
// could be reused, or will have to be replaced |
|
139 |
if (oldScreens != null) { |
|
140 |
for (int i = 0; i < oldScreens.length; i++) { |
|
141 |
if (!(screens[i] instanceof Win32GraphicsDevice)) { |
|
142 |
// REMIND: can we ever have anything other than Win32GD? |
|
143 |
assert (false) : oldScreens[i]; |
|
144 |
continue; |
|
145 |
} |
|
146 |
Win32GraphicsDevice gd = (Win32GraphicsDevice)oldScreens[i]; |
|
147 |
// devices may be invalidated from the native code when the |
|
148 |
// display change happens (device add/removal also causes a |
|
149 |
// display change) |
|
150 |
if (!gd.isValid()) { |
|
151 |
if (oldDevices == null) { |
|
152 |
oldDevices = |
|
153 |
new ArrayList<WeakReference<Win32GraphicsDevice>>(); |
|
154 |
} |
|
155 |
oldDevices.add(new WeakReference<Win32GraphicsDevice>(gd)); |
|
156 |
} else if (i < newDevices.length) { |
|
157 |
// reuse the device |
|
158 |
newDevices[i] = gd; |
|
159 |
} |
|
160 |
} |
|
161 |
oldScreens = null; |
|
162 |
} |
|
163 |
// create the new devices (those that weren't reused) |
|
164 |
for (int i = 0; i < newDevices.length; i++) { |
|
165 |
if (newDevices[i] == null) { |
|
166 |
newDevices[i] = makeScreenDevice(i); |
|
167 |
} |
|
168 |
} |
|
169 |
// install the new array of devices |
|
170 |
// Note: no synchronization here, it doesn't matter if a thread gets |
|
171 |
// a new or an old array this time around |
|
172 |
screens = newDevices; |
|
173 |
for (GraphicsDevice gd : screens) { |
|
174 |
if (gd instanceof DisplayChangedListener) { |
|
175 |
((DisplayChangedListener)gd).displayChanged(); |
|
176 |
} |
|
177 |
} |
|
178 |
// re-invalidate all old devices. It's needed because those in the list |
|
179 |
// may become "invalid" again - if the current default device is removed, |
|
180 |
// for example. Also, they need to be notified about display |
|
181 |
// changes as well. |
|
182 |
if (oldDevices != null) { |
|
183 |
int defScreen = getDefaultScreen(); |
|
184 |
for (ListIterator<WeakReference<Win32GraphicsDevice>> it = |
|
185 |
oldDevices.listIterator(); it.hasNext();) |
|
186 |
{ |
|
187 |
Win32GraphicsDevice gd = it.next().get(); |
|
188 |
if (gd != null) { |
|
189 |
gd.invalidate(defScreen); |
|
190 |
gd.displayChanged(); |
|
191 |
} else { |
|
192 |
// no more references to this device, remove it |
|
193 |
it.remove(); |
|
194 |
} |
|
195 |
} |
|
196 |
} |
|
197 |
// Reset the static GC for the (possibly new) default screen |
|
198 |
WToolkit.resetGC(); |
|
199 |
||
200 |
// notify SunDisplayChanger list (e.g. VolatileSurfaceManagers and |
|
201 |
// CachingSurfaceManagers) about the display change event |
|
202 |
displayChanger.notifyListeners(); |
|
203 |
// note: do not call super.displayChanged, we've already done everything |
|
204 |
} |
|
205 |
||
206 |
||
207 |
/* |
|
208 |
* ----END DISPLAY CHANGE SUPPORT---- |
|
209 |
*/ |
|
210 |
||
211 |
/* Used on Windows to obtain from the windows registry the name |
|
212 |
* of a file containing the system EUFC font. If running in one of |
|
213 |
* the locales for which this applies, and one is defined, the font |
|
214 |
* defined by this file is appended to all composite fonts as a |
|
215 |
* fallback component. |
|
216 |
*/ |
|
217 |
private static native String getEUDCFontFile(); |
|
218 |
||
219 |
/** |
|
220 |
* Whether registerFontFile expects absolute or relative |
|
221 |
* font file names. |
|
222 |
*/ |
|
223 |
protected boolean useAbsoluteFontFileNames() { |
|
224 |
return false; |
|
225 |
} |
|
226 |
||
227 |
/* Unlike the shared code version, this expects a base file name - |
|
228 |
* not a full path name. |
|
229 |
* The font configuration file has base file names and the FontConfiguration |
|
230 |
* class reports these back to the GraphicsEnvironment, so these |
|
231 |
* are the componentFileNames of CompositeFonts. |
|
232 |
*/ |
|
233 |
protected void registerFontFile(String fontFileName, String[] nativeNames, |
|
234 |
int fontRank, boolean defer) { |
|
235 |
||
236 |
// REMIND: case compare depends on platform |
|
237 |
if (registeredFontFiles.contains(fontFileName)) { |
|
238 |
return; |
|
239 |
} |
|
240 |
registeredFontFiles.add(fontFileName); |
|
241 |
||
242 |
int fontFormat; |
|
243 |
if (ttFilter.accept(null, fontFileName)) { |
|
244 |
fontFormat = FontManager.FONTFORMAT_TRUETYPE; |
|
245 |
} else if (t1Filter.accept(null, fontFileName)) { |
|
246 |
fontFormat = FontManager.FONTFORMAT_TYPE1; |
|
247 |
} else { |
|
248 |
/* on windows we don't use/register native fonts */ |
|
249 |
return; |
|
250 |
} |
|
251 |
||
252 |
if (fontPath == null) { |
|
253 |
fontPath = getPlatformFontPath(noType1Font); |
|
254 |
} |
|
255 |
||
256 |
/* Look in the JRE font directory first. |
|
257 |
* This is playing it safe as we would want to find fonts in the |
|
258 |
* JRE font directory ahead of those in the system directory |
|
259 |
*/ |
|
260 |
String tmpFontPath = jreFontDirName+File.pathSeparator+fontPath; |
|
261 |
StringTokenizer parser = new StringTokenizer(tmpFontPath, |
|
262 |
File.pathSeparator); |
|
263 |
||
264 |
boolean found = false; |
|
265 |
try { |
|
266 |
while (!found && parser.hasMoreTokens()) { |
|
267 |
String newPath = parser.nextToken(); |
|
550
e85f91b9bb95
6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents:
548
diff
changeset
|
268 |
boolean ujr = newPath.equals(jreFontDirName); |
2 | 269 |
File theFile = new File(newPath, fontFileName); |
270 |
if (theFile.canRead()) { |
|
271 |
found = true; |
|
272 |
String path = theFile.getAbsolutePath(); |
|
273 |
if (defer) { |
|
274 |
FontManager.registerDeferredFont(fontFileName, path, |
|
275 |
nativeNames, |
|
550
e85f91b9bb95
6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents:
548
diff
changeset
|
276 |
fontFormat, ujr, |
2 | 277 |
fontRank); |
278 |
} else { |
|
279 |
FontManager.registerFontFile(path, nativeNames, |
|
550
e85f91b9bb95
6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents:
548
diff
changeset
|
280 |
fontFormat, ujr, |
2 | 281 |
fontRank); |
282 |
} |
|
283 |
break; |
|
284 |
} |
|
285 |
} |
|
286 |
} catch (NoSuchElementException e) { |
|
287 |
System.err.println(e); |
|
288 |
} |
|
289 |
if (!found) { |
|
290 |
addToMissingFontFileList(fontFileName); |
|
291 |
} |
|
292 |
} |
|
293 |
||
294 |
/* register only TrueType/OpenType fonts |
|
295 |
* Because these need to be registed just for use when printing, |
|
296 |
* we defer the actual registration and the static initialiser |
|
297 |
* for the printing class makes the call to registerJREFontsForPrinting() |
|
298 |
*/ |
|
299 |
static String fontsForPrinting = null; |
|
300 |
protected void registerJREFontsWithPlatform(String pathName) { |
|
301 |
fontsForPrinting = pathName; |
|
302 |
} |
|
303 |
||
304 |
public static void registerJREFontsForPrinting() { |
|
548
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
305 |
final String pathName; |
2 | 306 |
synchronized (Win32GraphicsEnvironment.class) { |
307 |
GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
308 |
if (fontsForPrinting == null) { |
|
309 |
return; |
|
310 |
} |
|
311 |
pathName = fontsForPrinting; |
|
312 |
fontsForPrinting = null; |
|
313 |
} |
|
548
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
314 |
java.security.AccessController.doPrivileged( |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
315 |
new java.security.PrivilegedAction() { |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
316 |
public Object run() { |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
317 |
File f1 = new File(pathName); |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
318 |
String[] ls = f1.list(new TTFilter()); |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
319 |
if (ls == null) { |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
320 |
return null; |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
321 |
} |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
322 |
for (int i=0; i <ls.length; i++ ) { |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
323 |
File fontFile = new File(f1, ls[i]); |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
324 |
registerFontWithPlatform(fontFile.getAbsolutePath()); |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
325 |
} |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
326 |
return null; |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
327 |
} |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
328 |
}); |
2 | 329 |
} |
330 |
||
331 |
protected static native void registerFontWithPlatform(String fontName); |
|
332 |
||
333 |
protected static native void deRegisterFontWithPlatform(String fontName); |
|
334 |
||
335 |
protected GraphicsDevice makeScreenDevice(int screennum) { |
|
336 |
return new Win32GraphicsDevice(screennum); |
|
337 |
} |
|
338 |
||
339 |
// Implements SunGraphicsEnvironment.createFontConfiguration. |
|
340 |
protected FontConfiguration createFontConfiguration() { |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
341 |
FontConfiguration fc = new WFontConfiguration(this); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
342 |
fc.init(); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
343 |
return fc; |
2 | 344 |
} |
345 |
||
346 |
public FontConfiguration createFontConfiguration(boolean preferLocaleFonts, |
|
347 |
boolean preferPropFonts) { |
|
348 |
||
349 |
return new WFontConfiguration(this, preferLocaleFonts,preferPropFonts); |
|
350 |
} |
|
351 |
} |