author | ohair |
Wed, 06 Apr 2011 22:06:11 -0700 | |
changeset 9035 | 1255eb81cc2f |
parent 8128 | 4980e459a3a7 |
child 9050 | 26c2c1de1631 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
8128
diff
changeset
|
2 |
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.java2d; |
|
27 |
||
28 |
import java.awt.Color; |
|
29 |
import java.awt.Font; |
|
30 |
import java.awt.Graphics2D; |
|
31 |
import java.awt.GraphicsConfiguration; |
|
32 |
import java.awt.GraphicsDevice; |
|
33 |
import java.awt.GraphicsEnvironment; |
|
34 |
import java.awt.Insets; |
|
35 |
import java.awt.Rectangle; |
|
36 |
import java.awt.Toolkit; |
|
37 |
import java.awt.font.TextAttribute; |
|
38 |
import java.awt.image.BufferedImage; |
|
887 | 39 |
import java.awt.peer.ComponentPeer; |
2 | 40 |
import java.io.BufferedReader; |
41 |
import java.io.File; |
|
42 |
import java.io.FileInputStream; |
|
43 |
import java.io.FilenameFilter; |
|
44 |
import java.io.InputStreamReader; |
|
45 |
import java.io.IOException; |
|
46 |
import java.text.AttributedCharacterIterator; |
|
47 |
import java.util.ArrayList; |
|
48 |
import java.util.HashSet; |
|
49 |
import java.util.Iterator; |
|
50 |
import java.util.Locale; |
|
51 |
import java.util.Map; |
|
52 |
import java.util.NoSuchElementException; |
|
53 |
import java.util.Set; |
|
54 |
import java.util.StringTokenizer; |
|
55 |
import java.util.TreeMap; |
|
56 |
import java.util.Vector; |
|
57 |
import java.util.concurrent.ConcurrentHashMap; |
|
58 |
import sun.awt.AppContext; |
|
59 |
import sun.awt.DisplayChangedListener; |
|
60 |
import sun.awt.FontConfiguration; |
|
61 |
import sun.awt.SunDisplayChanger; |
|
62 |
import sun.font.CompositeFontDescriptor; |
|
63 |
import sun.font.Font2D; |
|
64 |
import sun.font.FontManager; |
|
3928 | 65 |
import sun.font.FontManagerFactory; |
66 |
import sun.font.FontManagerForSGE; |
|
2 | 67 |
import sun.font.NativeFont; |
68 |
||
69 |
/** |
|
70 |
* This is an implementation of a GraphicsEnvironment object for the |
|
71 |
* default local GraphicsEnvironment. |
|
72 |
* |
|
73 |
* @see GraphicsDevice |
|
74 |
* @see GraphicsConfiguration |
|
75 |
*/ |
|
76 |
public abstract class SunGraphicsEnvironment extends GraphicsEnvironment |
|
3928 | 77 |
implements DisplayChangedListener { |
2 | 78 |
|
3928 | 79 |
public static boolean isOpenSolaris; |
80 |
private static Font defaultFont; |
|
2 | 81 |
|
82 |
public SunGraphicsEnvironment() { |
|
83 |
java.security.AccessController.doPrivileged( |
|
84 |
new java.security.PrivilegedAction() { |
|
85 |
public Object run() { |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
86 |
String version = System.getProperty("os.version", "0.0"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
87 |
try { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
88 |
float ver = Float.parseFloat(version); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
89 |
if (ver > 5.10f) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
90 |
File f = new File("/etc/release"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
91 |
FileInputStream fis = new FileInputStream(f); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
92 |
InputStreamReader isr |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
93 |
= new InputStreamReader(fis, "ISO-8859-1"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
94 |
BufferedReader br = new BufferedReader(isr); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
95 |
String line = br.readLine(); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
96 |
if (line.indexOf("OpenSolaris") >= 0) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
97 |
isOpenSolaris = true; |
8128
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
98 |
} else { |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
99 |
/* We are using isOpenSolaris as meaning |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
100 |
* we know the Solaris commercial fonts aren't |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
101 |
* present. "Solaris Next" (03/10) did not |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
102 |
* include these even though its was not |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
103 |
* OpenSolaris. Need to revisit how this is |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
104 |
* handled but for now as in 6ux, we'll use |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
105 |
* the test for a standard font resource as |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
106 |
* being an indicator as to whether we need |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
107 |
* to treat this as OpenSolaris from a font |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
108 |
* config perspective. |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
109 |
*/ |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
110 |
String courierNew = |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
111 |
"/usr/openwin/lib/X11/fonts/TrueType/CourierNew.ttf"; |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
112 |
File courierFile = new File(courierNew); |
4980e459a3a7
6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds
prr
parents:
7947
diff
changeset
|
113 |
isOpenSolaris = !courierFile.exists(); |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
114 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
115 |
fis.close(); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
116 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
117 |
} catch (Exception e) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
118 |
} |
2 | 119 |
|
120 |
/* Establish the default font to be used by SG2D etc */ |
|
121 |
defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12); |
|
122 |
||
123 |
return null; |
|
124 |
} |
|
125 |
}); |
|
126 |
} |
|
127 |
||
128 |
protected GraphicsDevice[] screens; |
|
129 |
||
130 |
/** |
|
131 |
* Returns an array of all of the screen devices. |
|
132 |
*/ |
|
133 |
public synchronized GraphicsDevice[] getScreenDevices() { |
|
134 |
GraphicsDevice[] ret = screens; |
|
135 |
if (ret == null) { |
|
136 |
int num = getNumScreens(); |
|
137 |
ret = new GraphicsDevice[num]; |
|
138 |
for (int i = 0; i < num; i++) { |
|
139 |
ret[i] = makeScreenDevice(i); |
|
140 |
} |
|
141 |
screens = ret; |
|
142 |
} |
|
143 |
return ret; |
|
144 |
} |
|
145 |
||
3928 | 146 |
/** |
147 |
* Returns the number of screen devices of this graphics environment. |
|
148 |
* |
|
149 |
* @return the number of screen devices of this graphics environment |
|
150 |
*/ |
|
2 | 151 |
protected abstract int getNumScreens(); |
3928 | 152 |
|
153 |
/** |
|
154 |
* Create and return the screen device with the specified number. The |
|
155 |
* device with number <code>0</code> will be the default device (returned |
|
156 |
* by {@link #getDefaultScreenDevice()}. |
|
157 |
* |
|
158 |
* @param screennum the number of the screen to create |
|
159 |
* |
|
160 |
* @return the created screen device |
|
161 |
*/ |
|
2 | 162 |
protected abstract GraphicsDevice makeScreenDevice(int screennum); |
163 |
||
164 |
/** |
|
165 |
* Returns the default screen graphics device. |
|
166 |
*/ |
|
167 |
public GraphicsDevice getDefaultScreenDevice() { |
|
168 |
return getScreenDevices()[0]; |
|
169 |
} |
|
170 |
||
171 |
/** |
|
172 |
* Returns a Graphics2D object for rendering into the |
|
173 |
* given BufferedImage. |
|
174 |
* @throws NullPointerException if BufferedImage argument is null |
|
175 |
*/ |
|
176 |
public Graphics2D createGraphics(BufferedImage img) { |
|
177 |
if (img == null) { |
|
178 |
throw new NullPointerException("BufferedImage cannot be null"); |
|
179 |
} |
|
180 |
SurfaceData sd = SurfaceData.getPrimarySurfaceData(img); |
|
181 |
return new SunGraphics2D(sd, Color.white, Color.black, defaultFont); |
|
182 |
} |
|
183 |
||
7947
236cfb73d510
6980204: closed/java/awt/font/LogicalFonts/MappingTest.java fails
prr
parents:
5506
diff
changeset
|
184 |
public static FontManagerForSGE getFontManagerForSGE() { |
3928 | 185 |
FontManager fm = FontManagerFactory.getInstance(); |
186 |
return (FontManagerForSGE) fm; |
|
2 | 187 |
} |
188 |
/** |
|
189 |
* Returns all fonts available in this environment. |
|
190 |
*/ |
|
191 |
public Font[] getAllFonts() { |
|
3928 | 192 |
FontManagerForSGE fm = getFontManagerForSGE(); |
193 |
Font[] installedFonts = fm.getAllInstalledFonts(); |
|
194 |
Font[] created = fm.getCreatedFonts(); |
|
2 | 195 |
if (created == null || created.length == 0) { |
196 |
return installedFonts; |
|
197 |
} else { |
|
198 |
int newlen = installedFonts.length + created.length; |
|
199 |
Font [] fonts = java.util.Arrays.copyOf(installedFonts, newlen); |
|
200 |
System.arraycopy(created, 0, fonts, |
|
201 |
installedFonts.length, created.length); |
|
202 |
return fonts; |
|
203 |
} |
|
204 |
} |
|
205 |
||
206 |
public String[] getAvailableFontFamilyNames(Locale requestedLocale) { |
|
3928 | 207 |
FontManagerForSGE fm = getFontManagerForSGE(); |
208 |
String[] installed = fm.getInstalledFontFamilyNames(requestedLocale); |
|
2 | 209 |
/* Use a new TreeMap as used in getInstalledFontFamilyNames |
210 |
* and insert all the keys in lower case, so that the sort order |
|
211 |
* is the same as the installed families. This preserves historical |
|
212 |
* behaviour and inserts new families in the right place. |
|
213 |
* It would have been marginally more efficient to directly obtain |
|
214 |
* the tree map and just insert new entries, but not so much as |
|
215 |
* to justify the extra internal interface. |
|
216 |
*/ |
|
3928 | 217 |
TreeMap<String, String> map = fm.getCreatedFontFamilyNames(); |
2 | 218 |
if (map == null || map.size() == 0) { |
219 |
return installed; |
|
220 |
} else { |
|
221 |
for (int i=0; i<installed.length; i++) { |
|
222 |
map.put(installed[i].toLowerCase(requestedLocale), |
|
223 |
installed[i]); |
|
224 |
} |
|
225 |
String[] retval = new String[map.size()]; |
|
226 |
Object [] keyNames = map.keySet().toArray(); |
|
227 |
for (int i=0; i < keyNames.length; i++) { |
|
228 |
retval[i] = (String)map.get(keyNames[i]); |
|
229 |
} |
|
230 |
return retval; |
|
231 |
} |
|
232 |
} |
|
233 |
||
234 |
public String[] getAvailableFontFamilyNames() { |
|
235 |
return getAvailableFontFamilyNames(Locale.getDefault()); |
|
236 |
} |
|
237 |
||
238 |
/** |
|
239 |
* Return the bounds of a GraphicsDevice, less its screen insets. |
|
240 |
* See also java.awt.GraphicsEnvironment.getUsableBounds(); |
|
241 |
*/ |
|
242 |
public static Rectangle getUsableBounds(GraphicsDevice gd) { |
|
243 |
GraphicsConfiguration gc = gd.getDefaultConfiguration(); |
|
244 |
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); |
|
245 |
Rectangle usableBounds = gc.getBounds(); |
|
246 |
||
247 |
usableBounds.x += insets.left; |
|
248 |
usableBounds.y += insets.top; |
|
249 |
usableBounds.width -= (insets.left + insets.right); |
|
250 |
usableBounds.height -= (insets.top + insets.bottom); |
|
251 |
||
252 |
return usableBounds; |
|
253 |
} |
|
254 |
||
255 |
/** |
|
256 |
* From the DisplayChangedListener interface; called |
|
257 |
* when the display mode has been changed. |
|
258 |
*/ |
|
259 |
public void displayChanged() { |
|
260 |
// notify screens in device array to do display update stuff |
|
261 |
for (GraphicsDevice gd : getScreenDevices()) { |
|
262 |
if (gd instanceof DisplayChangedListener) { |
|
263 |
((DisplayChangedListener) gd).displayChanged(); |
|
264 |
} |
|
265 |
} |
|
266 |
||
267 |
// notify SunDisplayChanger list (e.g. VolatileSurfaceManagers and |
|
268 |
// SurfaceDataProxies) about the display change event |
|
269 |
displayChanger.notifyListeners(); |
|
270 |
} |
|
271 |
||
272 |
/** |
|
273 |
* Part of the DisplayChangedListener interface: |
|
274 |
* propagate this event to listeners |
|
275 |
*/ |
|
276 |
public void paletteChanged() { |
|
277 |
displayChanger.notifyPaletteChanged(); |
|
278 |
} |
|
279 |
||
1724
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
1716
diff
changeset
|
280 |
/** |
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
1716
diff
changeset
|
281 |
* Returns true when the display is local, false for remote displays. |
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
1716
diff
changeset
|
282 |
* |
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
1716
diff
changeset
|
283 |
* @return true when the display is local, false for remote displays |
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
1716
diff
changeset
|
284 |
*/ |
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
1716
diff
changeset
|
285 |
public abstract boolean isDisplayLocal(); |
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
1716
diff
changeset
|
286 |
|
2 | 287 |
/* |
288 |
* ----DISPLAY CHANGE SUPPORT---- |
|
289 |
*/ |
|
290 |
||
291 |
protected SunDisplayChanger displayChanger = new SunDisplayChanger(); |
|
292 |
||
293 |
/** |
|
294 |
* Add a DisplayChangeListener to be notified when the display settings |
|
295 |
* are changed. |
|
296 |
*/ |
|
297 |
public void addDisplayChangedListener(DisplayChangedListener client) { |
|
298 |
displayChanger.add(client); |
|
299 |
} |
|
300 |
||
301 |
/** |
|
302 |
* Remove a DisplayChangeListener from Win32GraphicsEnvironment |
|
303 |
*/ |
|
304 |
public void removeDisplayChangedListener(DisplayChangedListener client) { |
|
305 |
displayChanger.remove(client); |
|
306 |
} |
|
307 |
||
308 |
/* |
|
309 |
* ----END DISPLAY CHANGE SUPPORT---- |
|
310 |
*/ |
|
887 | 311 |
|
312 |
/** |
|
313 |
* Returns true if FlipBufferStrategy with COPIED buffer contents |
|
314 |
* is preferred for this peer's GraphicsConfiguration over |
|
315 |
* BlitBufferStrategy, false otherwise. |
|
316 |
* |
|
317 |
* The reason FlipBS could be preferred is that in some configurations |
|
318 |
* an accelerated copy to the screen is supported (like Direct3D 9) |
|
319 |
* |
|
320 |
* @return true if flip strategy should be used, false otherwise |
|
321 |
*/ |
|
322 |
public boolean isFlipStrategyPreferred(ComponentPeer peer) { |
|
323 |
return false; |
|
324 |
} |
|
2 | 325 |
} |