FontManager.java revision 0
0N/A * Copyright 2003-2007 Sun 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 * Interface between Java Fonts (java.awt.Font) and the underlying 0N/A * font files/native font resources and the Java and native font scalers. 0N/A /* Pool of 20 font file channels chosen because some UTF-8 locale 0N/A * composite fonts can use up to 16 platform fonts (including the 0N/A * Lucida fall back). This should prevent channel thrashing when 0N/A * dealing with one of these fonts. 0N/A * The pool array stores the fonts, rather than directly referencing 0N/A * the channels, as the font needs to do the open/close work. 0N/A /* Need to implement a simple linked list scheme for fast 0N/A * traversal and lookup. 0N/A * Also want to "fast path" dialog so there's minimal overhead. 0N/A /* There are at exactly 20 composite fonts: 5 faces (but some are not 0N/A * usually different), in 4 styles. The array may be auto-expanded 0N/A * later if more are needed, eg for user-defined composites or locale 0N/A /* given a full name find the Font. Remind: there's duplication 0N/A * here in that this contains the content of compositeFonts + 0N/A /* TrueType fonts have localised names. Support searching all 0N/A * of these before giving up on a name. 0N/A /* deprecated, unsupported hack - actually invokes a bug! */ 0N/A public static boolean isSolaris8;
// needed to check for JA wavedash fix. 0N/A public static boolean isSolaris9;
// needed to check for songti font usage. 0N/A /* Used to indicate required return type from toArray(..); */ 0N/A /* Key is familyname+style value as an int. 0N/A * Value is filename containing the font. 0N/A * If no mapping exists, it means there is no font file for the style 0N/A * If the mapping exists but the file doesn't exist in the deferred 0N/A * list then it means its not installed. 0N/A * This looks like a lot of code and strings but if it saves even 0N/A * a single file being opened at JRE start-up there's a big payoff. 0N/A * Lucida Sans is probably the only important case as the others 0N/A * are rarely used. Consider removing the other mappings if there's 0N/A * no evidence they are useful in practice. 0N/A /* Lucida Sans Family */ 0N/A /* Lucida Sans full names (map Bold and DemiBold to same file) */ 0N/A /* Lucida Sans Typewriter Family */ 0N/A "LucidaTypewriterRegular.ttf");
0N/A /* Typewriter full names (map Bold and DemiBold to same file) */ 0N/A "LucidaTypewriter.ttf");
0N/A "LucidaTypewriterBold.ttf");
0N/A "LucidaTypewriterBold.ttf");
0N/A "LucidaTypewriterBold.ttf");
0N/A /* Lucida Bright Family */ 0N/A /* Lucida Bright full names (map Bold and DemiBold to same file) */ 0N/A "LucidaBrightDemiItalic.ttf");
0N/A "LucidaBrightDemiItalic.ttf");
0N/A // so there's no need to do anything explicit here. 0N/A System.
out.
println(
"Enabling platform font metrics for win32. This is an unsupported option.");
0N/A System.
out.
println(
"This yields incorrect composite font metrics as reported by 1.1.x releases.");
0N/A System.
out.
println(
"It is appropriate only for use by applications which do not use any Java 2");
0N/A /* Initialise ptrs used by JNI methods */ 0N/A /* use poolSize to quickly detect if there's any free slots. 0N/A * This is a performance tweak based on the assumption that 0N/A * if this is executed at all often, its because there are many 0N/A * fonts being used and the pool will be full, and we will save 0N/A * a fruitless iteration 0N/A // is it possible for this to be the same font? 0N/A /* replace with new font, poolSize is unchanged. */ 0N/A /* lastPoolIndex is updated so that the least recently opened 0N/A * file will be closed next. 0N/A * In the normal course of events, the pool of fonts can remain open 0N/A * ready for quick access to their contents. The pool is sized so 0N/A * that it is not an excessive consumer of system resources whilst 0N/A * facilitating performance by providing ready access to the most 0N/A * recently used set of font files. 0N/A * The only reason to call removeFromPool(..) is for a Font that 0N/A * you want to to have GC'd. Currently this would apply only to fonts 0N/A * created with java.awt.Font.createFont(..). 0N/A * In this case, the caller is expected to have arranged for the file 0N/A * REMIND: consider how to know when a createFont created font should 0N/A * This method is provided for internal and exclusive use by Swing. 0N/A * @param font representing a physical font. 0N/A * @return true if the underlying font is a TrueType or OpenType font 0N/A * that claims to support the Microsoft Windows encoding corresponding to 0N/A * the default file.encoding property of this JRE instance. 0N/A * This narrow value is useful for Swing to decide if the font is useful 0N/A * for the the Windows Look and Feel, or, if a composite font should be 0N/A * The information used to make the decision is obtained from 0N/A * the ulCodePageRange fields in the font. 0N/A * A caller can use isLogicalFont(Font) in this class before calling 0N/A * this method and would not need to call this method if that 0N/A// static boolean fontSupportsDefaultEncoding(Font font) { 0N/A// (String) java.security.AccessController.doPrivileged( 0N/A// new sun.security.action.GetPropertyAction("file.encoding")); 0N/A// if (encoding == null || font == null) { 0N/A// encoding = encoding.toLowerCase(Locale.ENGLISH); 0N/A// return FontManager.fontSupportsEncoding(font, encoding); 0N/A /* Revise the implementation to in fact mean "font is a composite font. 0N/A * This ensures that Swing components will always benefit from the 0N/A * This method is provided for internal and exclusive use by Swing. 0N/A * It may be used in conjunction with fontSupportsDefaultEncoding(Font) 0N/A * In the event that a desktop properties font doesn't directly 0N/A * support the default encoding, (ie because the host OS supports 0N/A * adding support for the current locale automatically for native apps), 0N/A * then Swing calls this method to get a font which uses the specified 0N/A * font for the code points it covers, but also supports this locale 0N/A * just as the standard composite fonts do. 0N/A * Note: this will over-ride any setting where an application 0N/A * specifies it prefers locale specific composite fonts. 0N/A * The logic for this, is that this method is used only where the user or 0N/A * application has specified that the native L&F be used, and that 0N/A * we should honour that request to use the same font as native apps use. 0N/A * The behaviour of this method is to construct a new composite 0N/A * Font object that uses the specified physical font as its first 0N/A * component, and adds all the components of "dialog" as fall back 0N/A * The method currently assumes that only the size and style attributes 0N/A * are set on the specified font. It doesn't copy the font transform or 0N/A * other attributes because they aren't set on a font created from 0N/A * the desktop. This will need to be fixed if use is broadened. 0N/A * Operations such as Font.deriveFont will work properly on the 0N/A * font returned by this method for deriving a different point size. 0N/A * Additionally it tries to support a different style by calling 0N/A * getNewComposite() below. That also supports replacing slot zero 0N/A * with a different physical font but that is expected to be "rare". 0N/A * Deriving with a different style is needed because its been shown 0N/A * that some applications try to do this for Swing FontUIResources. 0N/A * Also operations such as new Font(font.getFontName(..), Font.PLAIN, 14); 0N/A * will NOT yield the same result, as the new underlying CompositeFont 0N/A * cannot be "looked up" in the font registry. 0N/A * This returns a FontUIResource as that is the Font sub-class needed 0N/A * Suggested usage is something like : 0N/A * FontUIResource fuir; 0N/A * Font desktopFont = getDesktopFont(..); 0N/A * // NOTE even if fontSupportsDefaultEncoding returns true because 0N/A * // you get Tahoma and are running in an English locale, you may 0N/A * // still want to just call getCompositeFontUIResource() anyway 0N/A * // as only then will you get fallback fonts - eg for CJK. 0N/A * if (FontManager.fontSupportsDefaultEncoding(desktopFont)) { 0N/A * fuir = new FontUIResource(..); 0N/A * fuir = FontManager.getCompositeFontUIResource(desktopFont); 0N/A /* Swing should only be calling this when a font is obtained 0N/A * from desktop properties, so should generally be a physical font, 0N/A * an exception might be for names like "MS Serif" which are 0N/A * automatically mapped to "Serif", so there's no need to do 0N/A * anything special in that case. But note that suggested usage 0N/A * is first to call fontSupportsDefaultEncoding(Font) and this 0N/A * method should not be called if that were to return true. 0N/A /* marking this as a created font is needed as only created fonts 0N/A * copy their creator's handles. 0N/A /* This variant is used only when the application specifies 0N/A * a variant of composite fonts which prefers locale specific or 0N/A * proportional fonts. 0N/A /* if the cache has an existing composite for this case, make 0N/A * its handle point to this new font. 0N/A * This ensures that when the altNameCache that is passed in 0N/A * is the global mapNameCache - ie we are running as an application - 0N/A * that any statically created java.awt.Font instances which already 0N/A * have a Font2D instance will have that re-directed to the new Font 0N/A * on subsequent uses. This is particularly important for "the" 0N/A * default font instance, or similar cases where a UI toolkit (eg 0N/A * Swing) has cached a java.awt.Font. Note that if Swing is using 0N/A * a custom composite APIs which update the standard composites have 0N/A * no effect - this is typically the case only when using the Windows 0N/A * L&F where these APIs would conflict with that L&F anyway. 0N/A * Systems may have fonts with the same name. 0N/A * We want to register only one of such fonts (at least until 0N/A * such time as there might be APIs which can accommodate > 1). 0N/A * Rank is 1) font configuration fonts, 2) JRE fonts, 3) OT/TT fonts, 0N/A * 4) Type1 fonts, 5) native fonts. 0N/A * If the new font has the same name as the old font, the higher 0N/A * ranked font gets added, replacing the lower ranked one. 0N/A * If the fonts are of equal rank, then make a special case of 0N/A * font configuration rank fonts, which are on closer inspection, 0N/A * OT/TT fonts such that the larger font is registered. This is 0N/A * a heuristic since a font may be "larger" in the sense of more 0N/A * code points, or be a larger "file" because it has more bitmaps. 0N/A * So it is possible that using filesize may lead to less glyphs, and 0N/A * using glyphs may lead to lower quality display. Probably number 0N/A * of glyphs is the ideal, but filesize is information we already 0N/A * have and is good enough for the known cases. 0N/A * Also don't want to register fonts that match JRE font families 0N/A * but are coming from a source other than the JRE. 0N/A * This will ensure that we will algorithmically style the JRE 0N/A * plain font and get the same set of glyphs for all styles. 0N/A * Note that this method returns a value 0N/A * if it returns the same object as its argument that means this 0N/A * font was newly registered. 0N/A * If it returns a different object it means this font already exists, 0N/A * and you should use that one. 0N/A * If it returns null means this font was not registered and none 0N/A * in that name is registered. The caller must find a substitute 0N/A /* Don't register any font that has the same name as a composite */ 0N/A /* If the new font is of an equal or higher rank, it is a 0N/A * candidate to replace the current one, subject to further tests. 0N/A /* All fonts initialise their mapper when first 0N/A * used. If the mapper is non-null then this font 0N/A * has been accessed at least once. In that case 0N/A * do not replace it. This may be overly stringent, 0N/A * but its probably better not to replace a font that 0N/A * someone is already using without a compelling reason. 0N/A * Additionally the primary case where it is known 0N/A * this behaviour is important is in certain composite 0N/A * fonts, and since all the components of a given 0N/A * composite are usually initialised together this 0N/A * is unlikely. For this to be a problem, there would 0N/A * have to be a case where two different composites used 0N/A * different versions of the same-named font, and they 0N/A * were initialised and used at separate times. 0N/A * In that case we continue on and allow the new font to 0N/A * be installed, but replaceFont will continue to allow 0N/A * the original font to be used in Composite fonts. 0N/A /* Normally we require a higher rank to replace a font, 0N/A * but as a special case, if the two fonts are the same rank, 0N/A * and are instances of TrueTypeFont we want the 0N/A * more complete (larger) one. 0N/A /* Don't replace ever JRE fonts. 0N/A * This test is in case a font configuration references 0N/A * a Lucida font, which has been mapped to a Lucida 0N/A * from the host O/S. The assumption here is that any 0N/A * such font configuration file is probably incorrect, or 0N/A * the host O/S version is for the use of AWT. 0N/A * In other words if we reach here, there's a possible 0N/A * problem with our choice of font configuration fonts. 0N/A /* The class FontRegistrationInfo is used when a client says not 0N/A * to register a font immediately. This mechanism is used to defer 0N/A * initialisation of all the components of composite fonts at JRE 0N/A * start-up. The CompositeFont class is "aware" of this and when it 0N/A * is first used it asks for the registration of its components. 0N/A * Also in the event that any physical font is requested the 0N/A * deferred fonts are initialised before triggering a search of the 0N/A * Two maps are used. One to track the deferred fonts. The 0N/A * other to track the fonts that have been initialised through this 0N/A /* Remind: possibly enhance initialiseDeferredFonts() to be 0N/A * optionally given a name and a style and it could stop when it 0N/A * finds that font - but this would be a problem if two of the 0N/A * fonts reference the same font face name (cf the Solaris 0N/A /* We keep a map of the files which contain the Lucida fonts so we 0N/A * don't need to search for them. 0N/A * But since we know what fonts these files contain, we can also avoid 0N/A * opening them to look for a font name we don't recognise - see 0N/A * findDeferredFont(). 0N/A * For typical cases where the font isn't a JRE one the overhead is 0N/A * this method call, HashMap.get() and null reference test, then 0N/A * a boolean test of noOtherJREFontFiles. 0N/A /* Iterate over the deferred font files looking for any in the 0N/A * jre directory that we didn't recognise, open each of these. 0N/A * In almost all installations this will quickly fall through 0N/A * because only the Lucidas will be present and jreOtherFontFiles 0N/A * noOtherJREFontFiles is used so we can skip this block as soon 0N/A * as its determined that its not needed - almost always after the 0N/A * very first time through. 0N/A /* skip names which aren't absolute, aren't in the JRE 0N/A * directory, or are known Lucida fonts. 0N/A /* This skips JRE installed fonts. */ 0N/A public static synchronized 0N/A /* Store the handle, so that if a font is bad, we 0N/A * retrieve the substituted font. 0N/A /* Probably shouldn't happen, but just in case */ 0N/A /* Note that the return value from this method is not always 0N/A * derived from this file, and may be null. See addToFontList for 0N/A * some explanation of this. 0N/A * This is the Physical font used when some other font on the system 0N/A * can't be located. There has to be at least one font or the font 0N/A * system is not useful and the graphics environment cannot sustain 0N/A * the Java platform. 0N/A /* findFont2D will load all fonts before giving up the search. 0N/A * If the JRE Lucida isn't found (eg because the JRE fonts 0N/A * directory is missing), it could find another version of Lucida 0N/A * from the host system. This is OK because at that point we are 0N/A * misconfiguration and this is probably a reasonable substitution. 0N/A /* Because of the findFont2D call above, if we reach here, we 0N/A * know all fonts have already been loaded, just accept any 0N/A * match at this point. If this fails we are in real trouble 0N/A * and I don't know how to recover from there being absolutely 0N/A * no fonts anywhere on the system. 0N/A throw new Error(
"Probable fatal error:No fonts found.");
0N/A * return String representation of style prepended with "." 0N/A * This is useful for performance to avoid unnecessary string operations. 0N/A return ".bolditalic";
0N/A /* This is implemented only on windows and is called from code that 0N/A * executes only on windows. This isn't pretty but its not a precedent 0N/A * in this file. This very probably should be cleaned up at some point. 0N/A private static native void 0N/A /* Obtained from Platform APIs (windows only) 0N/A * Map from lower-case font full name to basename of font file. 0N/A * Eg "arial bold" -> ARIALBD.TTF. 0N/A * For TTC files, there is a mapping for each font in the file. 0N/A /* Obtained from Platform APIs (windows only) 0N/A * Map from lower-case font full name to the name of its font family 0N/A * Eg "arial bold" -> "Arial" 0N/A /* Obtained from Platform APIs (windows only) 0N/A * Map from a lower-case family name to a list of full names of 0N/A * the member fonts, eg: 0N/A * "arial" -> ["Arial", "Arial Bold", "Arial Italic","Arial Bold Italic"] 0N/A /* The directories which contain platform fonts */ 0N/A /* This is needed since some windows registry names don't match 0N/A * - UPC styled font names have a double space, but the 0N/A * registry entry mapping to a file doesn't. 0N/A * - Marlett is in a hidden file not listed in the registry 0N/A * - The registry advertises that the file david.ttf contains a 0N/A * font with the full name "David Regular" when in fact its 0N/A * Directly fix up these known cases as this is faster. 0N/A * If a font which doesn't match these known cases has no file, 0N/A * it may be a font that has been temporarily added to the known set 0N/A * or it may be an installed font with a missing registry entry. 0N/A * Installed fonts are those in the windows font directories. 0N/A * Make a best effort attempt to locate these. 0N/A * We obtain the list of TrueType fonts in these directories and 0N/A * filter out all the font files we already know about from the registry. 0N/A * What remains may be "bad" fonts, duplicate fonts, or perhaps the 0N/A * missing font(s) we are looking for. 0N/A * Open each of these files to find out. 0N/A /* If this name exists and isn't for a valid name 0N/A * replace the mapping to the file with this font 0N/A /* Every font key in fontToFileMap ought to correspond to a 0N/A * font key in fontToFamilyNameMap. Entries that don't seem 0N/A * to correspond are likely fonts that were named differently 0N/A * by GDI than in the registry. One known cause of this is when 0N/A * Windows has had its regional settings changed so that from 0N/A * GDI we get a localised (eg Chinese or Japanese) name for the 0N/A * font, but the registry retains the English version of the name 0N/A * that corresponded to the "install" locale for windows. 0N/A * Since we are in this code block because there are unmapped 0N/A * font names, we can look to find unused font->file mappings 0N/A * and then open the files to read the names. We don't generally 0N/A * want to open font files, as its a performance hit, but this 0N/A * occurs only for a small number of fonts on specific system 0N/A * configs - ie is believed that a "true" Japanese windows would 0N/A * have JA names in the registry too. 0N/A * Clone fontToFileMap and remove from the clone all keys which 0N/A * match a fontToFamilyNameMap key. What remains maps to the 0N/A * files we want to open to find the fonts GDI returned. 0N/A * A font in such a file is added to the fontToFileMap after 0N/A * checking its one of the unmappedFontNames we are looking for. 0N/A * The original name that didn't map is removed from fontToFileMap 0N/A * so essentially this "fixes up" fontToFileMap to use the same 0N/A * Also note that typically the fonts for which this occurs in 0N/A * CJK locales are TTC fonts and not all fonts in a TTC may have 0N/A * localised names. Eg MSGOTHIC.TTC contains 3 fonts and one of 0N/A * them "MS UI Gothic" has no JA name whereas the other two do. 0N/A * So not every font in these files is unmapped or new. 0N/A /* If there are still unmapped font names, this means there's 0N/A * something that wasn't in the registry. We need to get all 0N/A * the font files directly and look at the ones that weren't 0N/A * found in the registry. 0N/A /* getFontFilesFromPath() returns all lower case names. 0N/A * To compare we also need lower case 0N/A * versions of the names from the registry. 0N/A /* We don't look for Type1 files here as windows will 0N/A * not enumerate these, so aren't useful in reconciling 0N/A * GDI's unmapped files. We do find these later when 0N/A * we enumerate all fonts. 0N/A /* remove from the set of names that will be returned to the 0N/A * user any fonts that can't be mapped to files. 0N/A for (
int i=
0; i<
sz; i++) {
0N/A * In some cases windows may have fonts in the fonts folder that 0N/A * don't show up in the registry or in the GDI calls to enumerate fonts. 0N/A * The only way to find these is to list the directory. We invoke this 0N/A * additional hit of listing the directory. This hit is small enough 0N/A * that its not significant in these 'enumerate all the fonts' cases. 0N/A * The basic approach is to cross-reference the files windows found 0N/A * with the ones in the directory listing approach, and for each 0N/A * in the latter list that is missing from the former list, register it. 0N/A /* getFontFilesFromPath() returns all lower case names. 0N/A * To compare we also need lower case 0N/A * versions of the names from the registry. 0N/A /* To avoid any issues with concurrent modification, create 0N/A * copies of the existing maps, add the new fonts into these 0N/A * and then replace the references to the old ones with the 0N/A * new maps. ConcurrentHashmap is another option but its a lot 0N/A * more changes and with this exception, these maps are intended 0N/A // prefer the font's locale name. 0N/A /* Note this return list excludes logical fonts and JRE fonts */ 0N/A /* This odd code with TreeMap is used to preserve a historical 0N/A * behaviour wrt the sorting order .. */ 0N/A /* Used to register any font files that are found by platform APIs 0N/A * that weren't previously found in the standard font locations. 0N/A * the isAbsolute() check is needed since that's whats stored in the 0N/A * set, and on windows, the fonts in the system font directory that 0N/A * are in the fontToFileMap are just basenames. We don't want to try 0N/A * to register those again, but we do want to register other registry 0N/A public static boolean 0N/A /* Path may be absolute or a base file name relative to one of 0N/A * the platform font directories 0N/A return s;
// shouldn't happen, but harmless 0N/A /* lcName is required to be lower case for use as a key. 0N/A * lcName may be a full name, or a family name, and style may 0N/A * be specified in addition to either of these. So be sure to 0N/A * get the right one. Since an app *could* ask for "Foo Regular" 0N/A * and later ask for "Foo Italic", if we don't register all the 0N/A * styles, then logic in findFont2D may try to style the original 0N/A * so we register the entire family if we get a match here. 0N/A * This is still a big win because this code is invoked where 0N/A * otherwise we would register all fonts. 0N/A * It's also useful for the case where "Foo Bold" was specified with 0N/A * style Font.ITALIC, as we would want in that case to try to return 0N/A * "Foo Bold Italic" if it exists, and it is only by locating "Foo Bold" 0N/A * and opening it that we really "know" it's Bold, and can look for 0N/A * a font that supports that and the italic style. 0N/A * The code in here is not overtly windows-specific but in fact it 0N/A * is unlikely to be useful as is on other platforms. It is maintained 0N/A * in this shared source file to be close to its sole client and 0N/A * because so much of the logic is intertwined with the logic in 0N/A /* first check that for every font in this family we can find 0N/A * a font file. The specific reason for doing this is that 0N/A * in at least one case on Windows a font has the face name "David" 0N/A * but the registry entry is "David Regular". That is the "unique" 0N/A * name of the font but in other cases the registry contains the 0N/A * "full" name. See the specifications of name ids 3 and 4 in the 0N/A * TrueType 'name' table. 0N/A * In general this could cause a problem that we fail to register 0N/A * if we all members of a family that we may end up mapping to 0N/A * the wrong font member: eg return Bold when Plain is needed. 0N/A /* Currently this code only looks for TrueType fonts, so format 0N/A * and rank can be specified without looking at the filename. 0N/A /* Register all fonts in this family. */ 0N/A /* Currently this code only looks for TrueType fonts, so format 0N/A * and rank can be specified without looking at the filename. 0N/A /* Handle case where request "MyFont Bold", style=Font.ITALIC */ 0N/A * The client supplies a name and a style. 0N/A * The name could be a family name, or a full name. 0N/A * A font may exist with the specified style, or it may 0N/A * exist only in some other style. For non-native fonts the scaler 0N/A * may be able to emulate the required style. 0N/A /* If preferLocaleFonts() or preferProportionalFonts() has been 0N/A * called we may be using an alternate set of composite fonts in this 0N/A * app context. The presence of a pre-built name map indicates whether 0N/A * this is so, and gives access to the alternate composite for the 0N/A // The check below is just so that the bitmap fonts being set by 0N/A // AWT and Swing thru the desktop properties do not trigger the 0N/A // the load fonts case. The two bitmap fonts are now mapped to 0N/A // appropriate equivalents for serif and sansserif. 0N/A // Note that the cost of this comparison is only for the first 0N/A // call until the map is filled. 0N/A /* This isn't intended to support a client passing in the 0N/A * string default, but if a client passes in null for the name 0N/A * the java.awt.Font class internally substitutes this name. 0N/A * So we need to recognise it here to prevent a loadFonts 0N/A * on the unrecognised name. The only potential problem with 0N/A * this is it would hide any real font called "default"! 0N/A * But that seems like a potential problem we can ignore for now. 0N/A /* First see if its a family name. */ 0N/A /* If it wasn't a family name, it should be a full name of 0N/A * either a composite, or a physical font 0N/A /* Check that the requested style matches the matched font's style. 0N/A * But also match style automatically if the requested style is 0N/A * "plain". This because the existing behaviour is that the fonts 0N/A * listed via getAllFonts etc always list their style as PLAIN. 0N/A * This does lead to non-commutative behaviours where you might 0N/A * start with "Lucida Sans Regular" and ask for a BOLD version 0N/A * and get "Lucida Sans DemiBold" but if you ask for the PLAIN 0N/A * style of "Lucida Sans DemiBold" you get "Lucida Sans DemiBold". 0N/A * This consistent however with what happens if you have a bold 0N/A * version of a font and no plain version exists - alg. styling 0N/A * doesn't "unbolden" the font. 0N/A /* If it was a full name like "Lucida Sans Regular", but 0N/A * the style requested is "bold", then we want to see if 0N/A * there's the appropriate match against another font in 0N/A * that family before trying to load all fonts, or applying a 0N/A * algorithmic styling 0N/A /* We exactly matched the requested style, use it! */ 0N/A /* This next call is designed to support the case 0N/A * where bold italic is requested, and if we must 0N/A * style, then base it on either bold or italic - 0N/A /* The next check is perhaps one 0N/A * that shouldn't be done. ie if we get this 0N/A * far we have probably as close a match as we 0N/A * are going to get. We could load all fonts to 0N/A * see if somehow some parts of the family are 0N/A * loaded but not all of it. 0N/A /* If reach here its possible that this is in a client which never 0N/A * loaded the GraphicsEnvironment, so we haven't even loaded ANY of 0N/A * the fonts from the environment. Do so now and recurse. 0N/A /* Don't want Windows to return a Lucida Sans font from 0N/A /* If reach here and no match has been located, then if there are 0N/A * uninitialised deferred fonts, load as many of those as needed 0N/A * to find the deferred font. If none is found through that 0N/A * search continue on. 0N/A * There is possibly a minor issue when more than one 0N/A * deferred font implements the same font face. Since deferred 0N/A * fonts are only those in font configuration files, this is a 0N/A * controlled situation, the known case being Solaris euro_fonts 0N/A * versions of Arial, Times New Roman, Courier New. However 0N/A * the larger font will transparently replace the smaller one 0N/A * - see addToFontList() - when it is needed by the composite font. 0N/A /* Some apps use deprecated 1.0 names such as helvetica and courier. On 0N/A * If running on Solaris will register all the fonts in this 0N/A * May as well register the whole directory without actually testing 0N/A * the font name is one of the deprecated names as the next step would 0N/A * load all fonts which are in this directory anyway. 0N/A * In the event that this lookup is successful it potentially "hides" 0N/A * TrueType versions of such fonts that are elsewhere but since they 0N/A * do not exist on Solaris this is not a problem. 0N/A * Set a flag to indicate we've done this registration to avoid 0N/A * repetition and more seriously, to avoid recursion. 0N/A /* "timesroman" is a special case since that's not the 0N/A * name of any known font on Solaris or elsewhere. 0N/A /* We check for application registered fonts before 0N/A * explicitly loading all fonts as if necessary the registration 0N/A * code will have done so anyway. And we don't want to needlessly 0N/A * load the actual files for all fonts. 0N/A * Just as for installed fonts we check for family before fullname. 0N/A * We do not add these fonts to fontNameCache for the 0N/A * app context case which eliminates the overhead of a per context 0N/A /* If reach here and no match has been located, then if all fonts 0N/A * are not yet loaded, do so, and then recurse. 0N/A /* The primary name is the locale default - ie not US/English but 0N/A * whatever is the default in this locale. This is the way it always 0N/A * has been but may be surprising to some developers if "Arial Regular" 0N/A * were hard-coded in their app and yet "Arial Regular" was not the 0N/A * default name. Fortunately for them, as a consequence of the JDK 0N/A * supporting returning names and family names for arbitrary locales, 0N/A * we also need to support searching all localised names for a match. 0N/A * But because this case of the name used to reference a font is not 0N/A * the same as the default for this locale is rare, it makes sense to 0N/A * search a much shorter list of default locale names and only go to 0N/A * a longer list of names in the event that no match was found. 0N/A * So add here code which searches localised names too. 0N/A * As in 1.4.x this happens only after loading all fonts, which 0N/A * is probably the right order. 0N/A /* Perhaps its a "compatibility" name - timesroman, helvetica, 0N/A * or courier, which 1.0 apps used for logical fonts. 0N/A * We look for these "late" after a loadFonts as we must not 0N/A * hide real fonts of these names. 0N/A * Map these appropriately: 0N/A * On windows this means according to the rules specified by the 0N/A * FontConfiguration : do it only for encoding==Cp1252 0N/A * REMIND: this is something we plan to remove. 0N/A /* This method can be more efficient as it will only need to 0N/A * do the lookup once, and subsequent calls on the java.awt.Font 0N/A * instance can utilise the cached Font2D on that object. 0N/A * Its unfortunate it needs to be a native method, but the font2D 0N/A * variable has to be private. 0N/A /* Stuff below was in NativeFontWrapper and needed a new home */ 0N/A * Workaround for apps which are dependent on a font metrics bug 0N/A * in JDK 1.1. This is an unsupported win32 private setting. 0N/A private static final short US_LCID =
0x0409;
// US English - default 0N/A // Return a Microsoft LCID from the given Locale. 0N/A // Used when getting localized font data. 0N/A // optimize for common case 0N/A // the following statements are derived from the langIDMap 0N/A // $1~/\/\*/ { next} 0N/A // $3~/\?\?/ { next } 0N/A // $1~/0x0409/ { next } 0N/A // $1~/0x0c0a/ { next } 0N/A // $1~/0x042c/ { next } 0N/A // $1~/0x0443/ { next } 0N/A // $1~/0x0812/ { next } 0N/A // $1~/0x04/ { print " addLCIDMapEntry(map, " substr($3, 0, 3) "\", (short) " substr($1, 0, 6) ");" ; next } 0N/A // $3~/,/ { print " addLCIDMapEntry(map, " $3 " (short) " substr($1, 0, 6) ");" ; next } 0N/A // { print " addLCIDMapEntry(map, " $3 ", (short) " substr($1, 0, 6) ");" ; next } 0N/A // The lines of this script: 0N/A // - eliminate comments 0N/A // - eliminate questionable locales 0N/A // - eliminate language-only locales 0N/A // - eliminate the default LCID value 0N/A // - eliminate a few other unneeded LCID values 0N/A // - print language-only locale entries for x04* LCID values 0N/A // (apparently Microsoft doesn't use language-only LCID values - 0N/A // - print complete entries for all other LCID values 0N/A // awk -f awk-script langIDMap > statements 0N/A /* The thread must be a member of a thread group 0N/A * which will not get GCed before VM exit. 0N/A * Make its parent the top-level thread group. 0N/A /* remind: used in X11GraphicsEnvironment and called often enough 0N/A * that we ought to obsolete this code 0N/A * It designed to be called (for example) by the font scaler 0N/A * when in processing a font file it is discovered to be incorrect. 0N/A * This is different than the case where fonts are discovered to 0N/A * be incorrect during initial verification, as such fonts are 0N/A * Handles to this font held are re-directed to a default font. 0N/A * This default may not be an ideal substitute buts it better than 0N/A * crashing This code assumes a PhysicalFont parameter as it doesn't 0N/A * make sense for a Composite to be "bad". 0N/A /* We should never reach here, but just in case */ 0N/A * This encapsulates all the work that needs to be done when a 0N/A * Font2D is replaced by a different Font2D. 0N/A /* If we try to replace the font with itself, that won't work, 0N/A * so pick any alternative physical font 0N/A /* eliminate references to this font, so it won't be located 0N/A * by future callers, and will be eligible for GC when all 0N/A * references are removed 0N/A /* Should I be replacing these, or just I just remove 0N/A * the names from the map? 0N/A /* some maps don't support this operation. 0N/A * In this case just give up and remove the entry. 0N/A /* Deferred initialization of composites shouldn't be 0N/A * a problem for this case, since a font must have been 0N/A * initialised to be discovered to be bad. 0N/A * Some JRE composites on Solaris use two versions of the same 0N/A * font. The replaced font isn't bad, just "smaller" so there's 0N/A * no need to make the slot point to the new font. 0N/A * Since composites have a direct reference to the Font2D (not 0N/A * via a handle) making this substitution is not safe and could 0N/A * cause an additional problem and so this substitution is 0N/A * warranted only when a font is truly "bad" and could cause 0N/A * a crash. So we now replace it only if its being substituted 0N/A * with some font other than a fontconfig rank font 0N/A * Since in practice a substitution will have the same rank 0N/A * this may never happen, but the code is safer even if its 0N/A * The only obvious "glitch" from this stems from the current 0N/A * implementation that when asked for the number of glyphs in a 0N/A * composite it lies and returns the number in slot 0 because 0N/A * composite glyphs aren't contiguous. Since we live with that 0N/A * we can live with the glitch that depending on how it was 0N/A * initialised a composite may return different values for this. 0N/A * Fixing the issues with composite glyph ids is tricky as 0N/A * there are exclusion ranges and unlike other fonts even the 0N/A * true "numGlyphs" isn't a contiguous range. Likely the only 0N/A * solution is an API that returns an array of glyph ranges 0N/A * which takes precedence over the existing API. That might 0N/A * also need to address excluding ranges which represent a 0N/A * code point supported by an earlier component. 0N/A /* This replicate the core logic of findFont2D but operates on 0N/A * all the locale names. This hasn't been merged into findFont2D to 0N/A * keep the logic simpler and reduce overhead, since this case is 0N/A * almost never used. The main case in which it is called is when 0N/A * a bogus font name is used and we need to check all possible names 0N/A * before returning the default case. 0N/A /* If reach here and no match has been located, then if we have 0N/A * not yet built the map of localeFullNamesToFont for TT fonts, do so 0N/A * now. This method must be called after all fonts have been loaded. 0N/A /* First see if its a family name. */ 0N/A /* If it wasn't a family name, it should be a full name. */ 0N/A /* We exactly matched the requested style, use it! */ 0N/A /* The next check is perhaps one 0N/A * that shouldn't be done. ie if we get this 0N/A * far we have probably as close a match as we 0N/A * are going to get. We could load all fonts to 0N/A * see if somehow some parts of the family are 0N/A * loaded but not all of it. 0N/A * This check is commented out for now. 0N/A /* Supporting "alternate" composite fonts on 2D graphics objects 0N/A * is accessed by the application by calling methods on the local 0N/A * GraphicsEnvironment. The overall implementation is described 0N/A * in one place, here, since otherwise the implementation is spread 0N/A * around it may be difficult to track. 0N/A * The methods below call into SunGraphicsEnvironment which creates a 0N/A * new FontConfiguration instance. The FontConfiguration class, 0N/A * and its platform sub-classes are updated to take parameters requesting 0N/A * these behaviours. This is then used to create new composite font 0N/A * instances. Since this calls the initCompositeFont method in 0N/A * SunGraphicsEnvironment it performs the same initialization as is 0N/A * performed normally. There may be some duplication of effort, but 0N/A * that code is already written to be able to perform properly if called 0N/A * to duplicate work. The main difference is that if we detect we are 0N/A * are not placed in the "default" maps but into an AppContext instance. 0N/A * The font lookup mechanism in java.awt.Font.getFont2D() is also updated 0N/A * so that look-up for composite fonts will in that case always 0N/A * do a lookup rather than returning a cached result. 0N/A * This is inefficient but necessary else singleton java.awt.Font 0N/A * instances would not retrieve the correct Font2D for the appcontext. 0N/A * sun.font.FontManager.findFont2D is also updated to that it uses 0N/A * a name map cache specific to that appcontext. 0N/A * Getting an AppContext is expensive, so there is a global variable 0N/A * that records whether these methods have ever been called and can 0N/A * avoid the expense for almost all applications. Once the correct 0N/A * CompositeFont is associated with the Font, everything should work 0N/A * through existing mechanisms. 0N/A * A special case is that GraphicsEnvironment.getAllFonts() must 0N/A * return an AppContext specific list. 0N/A * Calling the methods below is "heavyweight" but it is expected that 0N/A * these methods will be called very rarely. 0N/A * If usingPerAppContextComposites is true, we are in "applet" 0N/A * (eg browser) enviroment and at least one context has selected 0N/A * an alternate composite font behaviour. 0N/A * If usingAlternateComposites is true, we are not in an "applet" 0N/A * environment and the (single) application has selected 0N/A * an alternate composite font behaviour. 0N/A * - Printing: The implementation delegates logical fonts to an AWT 0N/A * mechanism which cannot use these alternate configurations. 0N/A * We can detect that alternate fonts are in use and back-off to 2D, but 0N/A * that uses outlines. Much of this can be fixed with additional work 0N/A * but that may have to wait. The results should be correct, just not 0N/A /* These values are used only if we are running as a standalone 0N/A * application, as determined by maybeMultiAppContext(); 0N/A /* This method doesn't check if alternates are selected in this app 0N/A * context. Its used by the FontMetrics caching code which in such 0N/A * a case cannot retrieve a cached metrics solely on the basis of 0N/A * the Font.equals() method since it needs to also check if the Font2D 0N/A * We also use non-standard composites for Swing native L&F fonts on 0N/A * Windows. In that case the policy is that the metrics reported are 0N/A * based solely on the physical font in the first slot which is the 0N/A * visible java.awt.Font. So in that case the metrics cache which tests 0N/A * the Font does what we want. In the near future when we expand the GTK 0N/A * logical font definitions we may need to revisit this if GTK reports 0N/A * combined metrics instead. For now though this test can be simple. 0N/A /* Modifies the behaviour of a subsequent call to preferLocaleFonts() 0N/A * to use Mincho instead of Gothic for dialoginput in JA locales 0N/A * on windows. Not needed on other platforms. 0N/A /* Test if re-ordering will have any effect */ 0N/A /* If there is an existing hashtable, we can drop it. */ 0N/A /* If no proportional fonts are configured, there's no need 0N/A * to take any action. 0N/A /* If there is an existing hashtable, we can drop it. */ 0N/A /* Keys are used to lookup per-AppContext Hashtables */ 0N/A /* This method should not be called with "null". 0N/A * It is the caller's responsibility to ensure that. 0N/A /* Initialise these objects only once we start to use this API */ 0N/A /* We want to ensure that this font cannot override existing 0N/A * installed fonts. Check these conditions : 0N/A * - family name is not that of an installed font 0N/A * - full name is not that of an installed font 0N/A * - family name is not the same as the full name of an installed font 0N/A * - full name is not the same as the family name of an installed font 0N/A * The last two of these may initially look odd but the reason is 0N/A * that (unfortunately) Font constructors do not distinuguish these. 0N/A * An extreme example of such a problem would be a font which has 0N/A * family name "Dialog.Plain" and full name of "Dialog". 0N/A * The one arguably overly stringent restriction here is that if an 0N/A * application wants to supply a new member of an existing family 0N/A * It will get rejected. But since the JRE can perform synthetic 0N/A * styling in many cases its not necessary. 0N/A * We don't apply the same logic to registered fonts. If apps want 0N/A * to do this lets assume they have a reason. It won't cause problems 0N/A * except for themselves. 0N/A /* Checks passed, now register the font */ 0N/A /* Create the FontFamily and add font to the tables */ 0N/A /* Remove name cache entries if not using app contexts. 0N/A * To accommodate a case where code may have registered first a plain 0N/A * family member and then used it and is now registering a bold family 0N/A * member, we need to remove all members of the family, so that the 0N/A * new style can get picked up rather than continuing to synthesise. 0N/A /* Remove from the name cache all references to the Font2D */ 0N/A // It may look odd to use TreeMap but its more convenient to the caller. 0N/A /* Begin support for GTK Look and Feel - query libfontconfig and 0N/A * return a composite Font to Swing that uses the desktop font(s). 0N/A * logical font name. 0N/A {
"sans",
"sansserif"},
0N/A {
"sans-serif",
"sansserif"},
0N/A {
"monospace",
"monospaced"}
0N/A /* fontconfig recognises slants roman, italic, as well as oblique, 0N/A * and a slew of weights, where the ones that matter here are 0N/A * To fully qualify what we want, we can for example ask for (eg) 0N/A * Font.PLAIN : "serif:regular:roman" 0N/A * Font.BOLD : "serif:bold:roman" 0N/A * Font.ITALIC : "serif:regular:italic" 0N/A * Font.BOLD|Font.ITALIC : "serif:bold:italic" 0N/A "sans:regular:roman",
0N/A "sans:regular:italic",
0N/A "serif:regular:roman",
0N/A "serif:regular:italic",
0N/A "serif:bold:italic",
0N/A "monospace:regular:roman",
0N/A "monospace:bold:roman",
0N/A "monospace:regular:italic",
0N/A "monospace:bold:italic",
0N/A /* This class is just a data structure. 0N/A //boolean preferBitmaps; // if embedded bitmaps preferred over AA 0N/A private static native int 0N/A /* This is public solely so that for debugging purposes it can be called 0N/A * with other names, which might (eg) include a size, eg "sans-24" 0N/A * The return value is a text aa rendering hint value. 0N/A * Normally we should call the no-args version. 0N/A /* Called from code that needs to know what are the AA settings 0N/A * that apps using FC would pick up for the default desktop font. 0N/A * Note apps can change the default desktop font. etc, so this 0N/A * isn't certain to be right but its going to correct for most cases. 0N/A * Native return values map to the text aa values in sun.awt.SunHints. 0N/A * which is used to look up the renderinghint value object. 0N/A /* This array has the array elements created in Java code and is 0N/A * passed down to native to be filled in. 0N/A /* Return an array of FontConfigInfo structs describing the primary 0N/A /* This can be made public if it's needed to force a re-read 0N/A * rather than using the cached values. The re-read would be needed 0N/A * only if some event signalled that the fontconfig has changed. 0N/A * In that event this method would need to return directly the array 0N/A * to be used by the caller in case it subsequently changed. 0N/A /* If it's a TTC file we need to know that as we will need to 0N/A * make sure we return the right font */ 0N/A /* If this file is already registered, can just return its font. 0N/A * However we do need to check in case it's a TTC as we need 0N/A * a specific font, so rather than directly returning it, let 0N/A * findFont2D resolve that. 0N/A /* If the font may hide a JRE font (eg fontconfig says it is 0N/A * Lucida Sans), we want to use the JRE version, so make it 0N/A * point to the JRE font. 0N/A /* It is also possible the font file is on the "deferred" list, 0N/A * in which case we can just initialise it now. 0N/A /* use findFont2D to get the right font from TTC's */ 0N/A /* In the majority of cases we reach here, and need to determine 0N/A * the type and rank to register the font. 0N/A /** returns an array of two strings. The first element is the 0N/A * name of the font. The second element is the file name. 0N/A /* Absolute last ditch attempt in the face of fontconfig problems. 0N/A * If we didn't match, pick the first, or just make something 0N/A * up so we don't NPE. 0N/A * We need to return a Composite font which has as the font in 0N/A * its first slot one obtained from fontconfig. 0N/A /* jdkFont is going to be used for slots 1..N and as a fallback. 0N/A * Slot 0 will be the physical font from fontconfig. 0N/A /* First, see if the family and exact style is already registered. 0N/A * If it is, use it. If it's not, then try to register it. 0N/A * If that registration fails (signalled by null) just return the 0N/A * regular JDK composite. 0N/A * Algorithmically styled fonts won't match on exact style, so 0N/A * will fall through this code, but the regisration code will 0N/A * find that file already registered and return its font. 0N/A /* Now register the fonts in the family (the other styles) after 0N/A * checking that they aren't already registered and are actually in 0N/A * a different file. They may be the same file in CJK cases. 0N/A * For cases where they are different font files - eg as is common for 0N/A * Latin fonts, then we rely on fontconfig to report these correctly. 0N/A * Assume that all styles of this font are found by fontconfig, 0N/A * so we can find all the family members which must be registered 0N/A * together to prevent synthetic styling. 0N/A /* Now we have a physical font. We will back this up with the JDK 0N/A * logical font (sansserif, serif, or monospaced) that corresponds 0N/A /* This is called by Swing passing in a fontconfig family name 0N/A * such as "sans". In return Swing gets a FontUIResource instance 0N/A * that has queried fontconfig to resolve the font(s) used for this. 0N/A * Fontconfig will if asked return a list of fonts to give the largest 0N/A * possible code point coverage. 0N/A * For now we use only the first font returned by fontconfig, and 0N/A * back it up with the most closely matching JDK logical font. 0N/A * Essentially this means pre-pending what we return now with fontconfig's 0N/A * preferred physical font. This could lead to some duplication in cases, 0N/A * if we already included that font later. We probably should remove such 0N/A * duplicates, but it is not a significant problem. It can be addressed 0N/A * later as part of creating a Composite which uses more of the 0N/A * same fonts as fontconfig. At that time we also should pay more 0N/A * attention to the special rendering instructions fontconfig returns, 0N/A * such as whether we should prefer embedded bitmaps over antialiasing. 0N/A * There's no way to express that via a Font at present. 0N/A /* If GTK L&F were to be used on windows, we need to return 0N/A * something. Since on windows Swing won't have the code to 0N/A * call fontconfig, even if it is present, fcFamily and mapped 0N/A * name will default to sans and therefore sansserif so this 0N/A /* The name of the font will be that of the physical font in slot, 0N/A * but by setting the handle to that of the CompositeFont it 0N/A * renders as that CompositeFont. 0N/A * It also needs to be marked as a created font which is the 0N/A * current mechanism to signal that deriveFont etc must copy 0N/A * the handle from the original font. 0N/A /* The following fields and methods which relate to layout 0N/A * perhaps belong in some other class but FontManager is already 0N/A * widely used as an entry point for other JDK code that needs 0N/A * access to the font system internals. 0N/A * Referenced by code in the JDK which wants to test for the 0N/A * minimum char code for which layout may be required. 0N/A * Note that even basic latin text can benefit from ligatures, 0N/A * eg "ffi" but we presently apply those only if explicitly 0N/A * requested with TextAttribute.LIGATURES_ON. 0N/A * The value here indicates the lowest char code for which failing 0N/A * to invoke layout would prevent acceptable rendering. 0N/A * Referenced by code in the JDK which wants to test for the 0N/A * maximum char code for which layout may be required. 0N/A * Note this does not account for supplementary characters 0N/A * where the caller interprets 'layout' to mean any case where 0N/A * one 'char' (ie the java type char) does not map to one glyph 0N/A /* If the character code falls into any of a number of unicode ranges 0N/A * where we know that simple left->right layout mapping chars to glyphs 0N/A * 1:1 and accumulating advances is going to produce incorrect results, 0N/A * we want to know this so the caller can use a more intelligent layout 0N/A * approach. A caller who cares about optimum performance may want to 0N/A * check the first case and skip the method call if its in that range. 0N/A * Although there's a lot of tests in here, knowing you can skip 0N/A * CTL saves a great deal more. The rest of the checks are ordered 0N/A * so that rather than checking explicitly if (>= start & <= end) 0N/A * which would mean all ranges would need to be checked so be sure 0N/A * CTL is not needed, the method returns as soon as it recognises 0N/A * the code point is outside of a CTL ranges. 0N/A * NOTE: Since this method accepts an 'int' it is asssumed to properly 0N/A * represent a CHARACTER. ie it assumes the caller has already 0N/A * converted surrogate pairs into supplementary characters, and so 0N/A * can handle this case and doesn't need to be told such a case is 0N/A // Trigger layout for combining diacriticals 0x0300->0x036f 0N/A // No automatic layout for Greek, Cyrillic, Armenian. 0N/A // Hebrew 0590 - 05ff 0N/A // Arabic 0600 - 06ff 0N/A return false;
// Syriac and Thaana 0N/A // if Indic, assume shaping for conjuncts, reordering: 0N/A // 0900 - 097F Devanagari 0N/A // 0980 - 09FF Bengali 0N/A // 0A00 - 0A7F Gurmukhi 0N/A // 0A80 - 0AFF Gujarati 0N/A // 0B00 - 0B7F Oriya 0N/A // 0B80 - 0BFF Tamil 0N/A // 0C00 - 0C7F Telugu 0N/A // 0C80 - 0CFF Kannada 0N/A // 0D00 - 0D7F Malayalam 0N/A // 0D80 - 0DFF Sinhala 0N/A // 0E00 - 0E7F if Thai, assume shaping for vowel, tone marks 0N/A else if (
code <=
0x17ff) {
// 1780 - 17FF Khmer 0N/A else if (
code <=
0x200d) {
// zwj or zwnj 0N/A else if (
code >=
0x202a &&
code <=
0x202e) {
// directional control 0N/A else if (
code >=
0x206a &&
code <=
0x206f) {
// directional control 0N/A /* This is almost the same as the method above, except it takes a 0N/A * char which means it may include undecoded surrogate pairs. 0N/A * The distinction is made so that code which needs to identify all 0N/A * cases in which we do not have a simple mapping from 0N/A * char->unicode character->glyph can be be identified. 0N/A * For example measurement cannot simply sum advances of 'chars', 0N/A * the caret in editable text cannot advance one 'char' at a time, etc. 0N/A * These callers really are asking for more than whether 'layout' 0N/A * needs to be run, they need to know if they can assume 1->1 0N/A * char->glyph mapping. 0N/A * If there is anything in the text which triggers a case 0N/A * where char->glyph does not map 1:1 in straightforward 0N/A * left->right ordering, then this method returns true. 0N/A * Scripts which might require it but are not treated as such 0N/A * due to JDK implementations will not return true. 0N/A * ie a 'true' return is an indication of the treatment by 0N/A * the implementation. 0N/A * Whether supplementary characters should be considered is dependent 0N/A * on the needs of the caller. Since this method accepts the 'char' type 0N/A * then such chars are always represented by a pair. From a rendering 0N/A * perspective these will all (in the cases I know of) still be one 0N/A * unicode character -> one glyph. But if a caller is using this to 0N/A * discover any case where it cannot make naive assumptions about 0N/A * the number of chars, and how to index through them, then it may 0N/A * need the option to have a 'true' return in such a case. 0N/A * Used by windows printing to assess if a font is likely to 0N/A * be layout compatible with JDK 0N/A * TrueType fonts should be, but if they have no GPOS table, 0N/A * but do have a GSUB table, then they are probably older 0N/A * fonts GDI handles differently. 0N/A //Find preferred font scaler 0N/A //NB: we can allow property based preferences 0N/A // (theoretically logic can be font type specific) 0N/A boolean.
class,
int.
class};
0N/A //NB: rewrite using factory? constructor is ugly way 0N/A /* At the moment it is harmless to create 2 null scalers 0N/A so, technically, syncronized keyword is not needed. 0N/A But it is safer to keep it to avoid subtle problems if we will be 0N/A adding checks like whether scaler is null scaler. */ 0N/A /* This is the only place to instantiate new FontScaler. 0N/A * Therefore this is very convinient place to register 0N/A * scaler with Disposer as well as trigger deregistring bad font 0N/A * in case when scaler reports this. 0N/A //if we can not instantiate scaler assume bad font 0N/A //NB: technically it could be also because of internal scaler 0N/A // error but here we are assuming scaler is ok.