SunGraphicsEnvironment.java revision 430
430N/A * Copyright 1997-2008 Sun Microsystems Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * This is an implementation of a GraphicsEnvironment object for the 0N/A * default local GraphicsEnvironment. 0N/A * @see GraphicsDevice 0N/A * @see GraphicsConfiguration 0N/A /* fontPath is the location of all fonts on the system, excluding the 0N/A * JRE's own font directory but including any path specified using the 0N/A * sun.java2d.fontpath property. Together with that property, it is 0N/A * initialised by the getPlatformFontPath() method 0N/A * This call must be followed by a call to registerFontDirs(fontPath) 0N/A * once any extra debugging path has been appended. 0N/A /* discoveredAllFonts is set to true when all fonts on the font path are 0N/A * discovered. This usually also implies opening, validating and 0N/A * registering, but an implementation may be optimized to avold this. 0N/A * So see also "loadedAllFontFiles" 0N/A /* loadedAllFontFiles is set to true when all fonts on the font path are 0N/A * actually opened, validated and registered. This always implies 0N/A * discoveredAllFonts is true. 0N/A * A few things in Java 2D code are different in OpenJDK, 0N/A * so need a way to tell which implementation this is. 0N/A * The absence of Lucida Sans Regular is the simplest way for now. 0N/A * so they are always available and preferred over other fonts. 0N/A * This needs to be registered before the composite fonts as 0N/A * otherwise some native font that corresponds may be found 0N/A * as we don't have a way to handle two fonts of the same 0N/A * name, so the JRE one must be the first one registered. 0N/A * Pass "true" to registerFonts method as on-screen these 0N/A * JRE fonts always go through the T2K rasteriser. 0N/A /* Linux font configuration uses these fonts */ 0N/A /* Register the JRE fonts so that the native platform can 0N/A * access them. This is used only on Windows so that when 0N/A * printing the printer driver can access the fonts. 0N/A /* Create the font configuration and get any font path 0N/A * that might be specified. 0N/A /* In prior releases the debugging font path replaced 0N/A * all normally located font directories except for the 0N/A * JRE fonts dir. This directory is still always located and 0N/A * placed at the head of the path but as an augmentation 0N/A * to the previous behaviour the 0N/A * changes below allow you to additionally append to 0N/A * the font path by starting with append: or prepend by 0N/A * starting with a prepend: sign. Eg: to append 0N/A * If there is an appendedfontpath it in the font configuration 0N/A * it is used instead of searching the system for dirs. 0N/A * The behaviour of append and prepend is then similar 0N/A * to the normal case. ie it goes after what 0N/A * you prepend and * before what you append. If the 0N/A * neither the append or prepend syntaxes is used then as 0N/A * except for the JRE dir the path is replaced and it is 0N/A * up to you to make sure that all the right directories 0N/A * are located. This is platform and locale-specific so 0N/A * its almost impossible to get right, so it should be 0N/A * used with caution. 0N/A /* In debugging mode we register all the paths 0N/A * Caution: this is a very expensive call on Solaris:- 0N/A /* If the font configuration contains an "appendedfontpath" 0N/A * entry, it is interpreted as a set of locations that 0N/A * should always be registered. 0N/A * It may be additional to locations normally found for 0N/A * that place, or it may be locations that need to have 0N/A * all their paths registered to locate all the needed 0N/A * This is typically when the same .TTF file is referenced 0N/A * from multiple font.dir files and all of these must be 0N/A * read to find all the native (XLFD) names for the font, 0N/A * so that X11 font APIs can be used for as many code 0N/A * points as possible. 0N/A /* On Solaris, we need to register the Japanese TrueType 0N/A * directory so that we can find the corresponding bitmap 0N/A * fonts. This could be done by listing the directory in 0N/A * the font configuration file, but we don't want to 0N/A * confuse users with this quirk. There are no bitmap fonts 0N/A * for other writing systems that correspond to TrueType 0N/A * fonts and have matching XLFDs. We need to register the 0N/A * bitmap fonts only in environments where they're on the 0N/A * X font path, i.e., in the Japanese locale. 0N/A * Note that if the X Toolkit is in use the font path isn't 0N/A * set up by JDK, but users of a JA locale should have it 0N/A * set up already by their login environment. 0N/A /* Establish the default font to be used by SG2D etc */ 0N/A * Returns an array of all of the screen devices. 0N/A for (
int i =
0; i <
num; i++) {
0N/A * Returns the default screen graphics device. 0N/A * Returns a Graphics2D object for rendering into the 0N/A * given BufferedImage. 0N/A * @throws NullPointerException if BufferedImage argument is null 0N/A /* A call to this method should be followed by a call to 0N/A * registerFontDirs(..) 0N/A * Get all directories which contain installed fonts. 0N/A * Whether registerFontFile expects absolute or relative 0N/A * Returns file name for default font, either absolute 0N/A * or relative as needed by registerFontFile. 0N/A * Returns face name for default font, or null if 0N/A * no face names are used for CompositeFontDescriptors 0N/A * for this platform. 0N/A /* Use lock specific to the font system */ 0N/A // this will find all fonts including those already 0N/A // registered. But we have checks in place to prevent 0N/A // double registration. 0N/A /* Use lock specific to the font system */ 0N/A // this will find all fonts including those already 0N/A // registered. But we have checks in place to prevent 0N/A // double registration. 0N/A * This is for use only within getAllFonts(). 0N/A * Fonts listed in the fontconfig files for windows were all 0N/A * on the "deferred" initialisation list. They were registered 0N/A * either in the course of the application, or in the call to 0N/A * loadFonts() within getAllFonts(). The fontconfig file specifies 0N/A * the names of the fonts using the English names. If there's a 0N/A * different name in the execution locale, then the platform will 0N/A * report that, and we will construct the font with both names, and 0N/A * thereby enumerate it twice. This happens for Japanese fonts listed 0N/A * in the windows fontconfig, when run in the JA locale. The solution 0N/A * is to rely (in this case) on the platform's font->file mapping to 0N/A * determine that this name corresponds to a file we already registered. 0N/A * This works because 0N/A * - we know when we get here all deferred fonts are already initialised 0N/A * - when we register a font file, we register all fonts in it. 0N/A * - we know the fontconfig fonts are all in the windows registry 0N/A * Returns all fonts installed in this environment. 0N/A /* warning: the number of composite fonts could change dynamically 0N/A * if applications are allowed to create them. "allfonts" could 0N/A * Returns all fonts available in this environment. 0N/A * Default locale can be changed but we need to know the initial locale 0N/A * as that is what is used by native code. Changing Java default locale 0N/A * doesn't affect that. 0N/A * Returns the locale in use when using native code to communicate 0N/A * with platform APIs. On windows this is known as the "system" locale, 0N/A * and it is usually the same as the platform locale, but not always, 0N/A * so this method also checks an implementation property used only 0N/A * on windows and uses that if set. 0N/A /* On windows the system locale may be different than the 0N/A * user locale. This is an unsupported configuration, but 0N/A * in that case we want to return a dummy locale that will 0N/A * never cause a match in the usage of this API. This is 0N/A * important because Windows documents that the family 0N/A * names of fonts are enumerated using the language of 0N/A * the system locale. BY returning a dummy locale in that 0N/A * case we do not use the platform API which would not 0N/A * return us the names we want. 0N/A /* Really we need only the JRE fonts family names, but there's little 0N/A * overhead in doing this the easy way by adding all the currently 0N/A // these names are always there and aren't localised 0N/A /* Platform APIs may be used to get the set of available family 0N/A * names for the current default locale so long as it is the same 0N/A * as the start-up system locale, rather than loading all fonts. 0N/A /* Augment platform names with JRE font family names */ 0N/A /* Use a new TreeMap as used in getInstalledFontFamilyNames 0N/A * and insert all the keys in lower case, so that the sort order 0N/A * is the same as the installed families. This preserves historical 0N/A * behaviour and inserts new families in the right place. 0N/A * It would have been marginally more efficient to directly obtain 0N/A * the tree map and just insert new entries, but not so much as 0N/A * to justify the extra internal interface. 0N/A * Returns a file name for the physical font represented by this platform 0N/A * font name. The default implementation tries to obtain the file name 0N/A * from the font configuration. 0N/A * Subclasses may override to provide information from other sources. 0N/A /* all conveniently have the same suffix length */ 0N/A if (
offset <=
0) {
/* must be at least A.ttf */ 0N/A /* all conveniently have the same suffix length */ 0N/A if (
offset <=
0) {
/* must be at least A.pfa */ 0N/A /* all conveniently have the same suffix length */ 0N/A if (
offset <=
0) {
/* must be at least A.ttf or A.pfa */ 0N/A /* No need to keep consing up new instances - reuse a singleton. 0N/A * The trade-off is that these objects don't get GC'd. 0N/A /* The majority of the register functions in this class are 0N/A * registering platform fonts in the JRE's font maps. 0N/A * The next one is opposite in function as it registers the JRE 0N/A * fonts as platform fonts. If subsequent to calling this 0N/A * your implementation enumerates platform fonts in a way that 0N/A * would return these fonts too you may get duplicates. 0N/A * This function is primarily used to install the JRE fonts 0N/A * so that the native platform can access them. 0N/A * It is intended to be overridden by platform subclasses 0N/A * Currently minimal use is made of this as generally 0N/A * Java 2D doesn't need the platform to be able to 0N/A * use its fonts and platforms which already have matching 0N/A * fonts registered (possibly even from other different JRE 0N/A * versions) generally can't be guaranteed to use the 0N/A * one registered by this JRE version in response to 0N/A * requests from this JRE. 0N/A /* Called from FontManager - has Solaris specific implementation */ 0N/A /* Called to register fall back fonts */ 0N/A // REMIND: case compare depends on platform 0N/A * helper function for registerFonts 0N/A // REMIND: case compare depends on platform 0N/A continue;
// skip this font file. 0N/A * A GE may verify whether a font file used in a fontconfiguration 0N/A * exists. If it doesn't then either we may substitute the default 0N/A * font, or perhaps elide it altogether from the composite font. 0N/A * This makes some sense on windows where the font file is only 0N/A * likely to be in one place. But on other OSes, eg Linux, the file 0N/A * can move around depending. So there we probably don't want to assume 0N/A * its missing and so won't add it to this list. 0N/A * If this list - missingFontFiles - is non-null then the composite 0N/A * font initialisation logic tests to see if a font file is in that 0N/A * Only one thread should be able to add to this set so we don't 0N/A * Creates this environment's FontConfiguration. 0N/A * This method asks the font configuration API for all platform names 0N/A * looking up their corresponding file name and registers these fonts. 0N/A * It also ensures that the fonts are accessible via platform APIs. 0N/A * The composites themselves are then registered. 0N/A /* No file located, so register using the platform name, 0N/A * i.e. as a native font. 0N/A /* If platform APIs also need to access the font, add it 0N/A * to a set to be registered with the platform too. 0N/A * This may be used to add the parent directory to the X11 0N/A * font path if its not already there. See the docs for the 0N/A * subclass implementation. 0N/A * This is now mainly for the benefit of X11-based AWT 0N/A * But for historical reasons, 2D initialisation code 0N/A * makes these calls. 0N/A * If the fontconfiguration file is properly set up 0N/A * so that all fonts are mapped to files and all their 0N/A * appropriate directories are specified, then this 0N/A * method will be low cost as it will return after 0N/A * a test that finds a null lookup map. 0N/A /* Uncomment these two lines to "generate" the XLFD->filename 0N/A * mappings needed to speed start-up on Solaris. 0N/A * Augment this with the appendedpathname and the mappings 0N/A * for native (F3) fonts 0N/A //String platName = platformFontName.replaceAll(" ", "_"); 0N/A //System.out.println("filename."+platName+"="+fontFileName); 0N/A /* This registers accumulated paths from the calls to 0N/A * addFontToPlatformFontPath(..) and any specified by 0N/A * the font configuration. Rather than registering 0N/A * the fonts it puts them in a place and form suitable for 0N/A * the Toolkit to pick up and use if a toolkit is initialised, 0N/A * and if it uses X11 fonts. 0N/A /* It would be better eventually to handle this in the 0N/A * FontConfiguration code which should also remove duplicate slots 0N/A /* FontConfiguration needs to convey how many fonts it has added 0N/A * as fallback component fonts which should not affect metrics. 0N/A * The core component count will be the number of metrics slots. 0N/A * This does not preclude other mechanisms for adding 0N/A * fall back component fonts to the composite. 0N/A * Notifies graphics environment that the logical font configuration 0N/A * uses the given platform font name. The graphics environment may 0N/A * use this for platform specific initialization. 0N/A * Determines whether the given font is a logical font. 0N/A * Return the default font configuration. 0N/A * Return the bounds of a GraphicsDevice, less its screen insets. 0N/A * See also java.awt.GraphicsEnvironment.getUsableBounds(); 0N/A * This method is provided for internal and exclusive use by Swing. 0N/A * This method should no longer be called, instead directly call 0N/A * FontManager.fontSupportsDefaultEncoding(Font). 0N/A * This method will be removed once Swing is updated to no longer 0N/A * This invocation is not in a privileged block because 0N/A * all privileged operations (reading files and properties) 0N/A * was conducted on the creation of the GE 0N/A /* If (as we do on X11) need to set a platform font path, 0N/A * then the needed path may be specified by the platform 0N/A * specific FontConfiguration class & data file. Such platforms 0N/A * (ie X11) need to override this method to retrieve this information 0N/A * into suitable data structures. 0N/A * From the DisplayChangedListener interface; called 0N/A * when the display mode has been changed. 0N/A // notify screens in device array to do display update stuff 0N/A // notify SunDisplayChanger list (e.g. VolatileSurfaceManagers and 0N/A // SurfaceDataProxies) about the display change event 0N/A * Part of the DisplayChangedListener interface: 0N/A * propagate this event to listeners 0N/A * ----DISPLAY CHANGE SUPPORT---- 0N/A * Add a DisplayChangeListener to be notified when the display settings 0N/A * Remove a DisplayChangeListener from Win32GraphicsEnvironment 0N/A * ----END DISPLAY CHANGE SUPPORT---- 430N/A * Returns true if FlipBufferStrategy with COPIED buffer contents 430N/A * is preferred for this peer's GraphicsConfiguration over 430N/A * BlitBufferStrategy, false otherwise. 430N/A * The reason FlipBS could be preferred is that in some configurations 430N/A * an accelerated copy to the screen is supported (like Direct3D 9) 430N/A * @return true if flip strategy should be used, false otherwise