APIdia Launch Partner
Top Description Fields Constructors Methods
sun.font

public final Class FontUtilities

extends Object
Class Inheritance
Imports
java.awt.Font, java.lang.ref.SoftReference, java.util.concurrent.ConcurrentHashMap, javax.swing.plaf.FontUIResource, sun.awt.OSInfo, sun.util.logging.PlatformLogger

A collection of utility methods.

Field Summary

Modifier and TypeField and Description
private static volatile SoftReference<ConcurrentHashMap<PhysicalFont, CompositeFont>>
compMapRef

This method is provided for internal and exclusive use by Swing.

private static boolean
public static boolean
public static boolean
public static boolean
public static boolean
private static PlatformLogger
private static boolean
public static final int
MAX_LAYOUT_CHARCODE

Referenced by code in the JDK which wants to test for the maximum char code for which layout may be required.

public static final int
MIN_LAYOUT_CHARCODE

Referenced by code in the JDK which wants to test for the minimum char code for which layout may be required.

private static final String[][]
public static boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean
public static boolean
public static FontUIResource
public static Font2D

Returns:

the Font2D object returned by Font.getFont2D()
getFont2D
(Font
the font object to call
font
)

Calls the private getFont2D() method in java.awt.Font objects.

public static FontUIResource
getFontConfigFUIR(String fcFamily, int style, int size)

public static PlatformLogger
private static void
public static boolean
public static boolean
isComplexScript(char[] chs, int start, int limit)

Return true if there any characters which would trigger layout.

public static boolean
isComplexText(char[] chs, int start, int limit)

If there is anything in the text which triggers a case where char->glyph does not map 1:1 in straightforward left->right ordering, then this method returns true.

public static boolean
isDefaultIgnorable(int charCode)

Checks whether or not the specified codepoint is ignorable by default, per the Unicode standard (with exceptions for HarfBuzz and Uniscribe compatibility).

public static boolean

Returns:

whether the specified codepoint is ignorable whitespace
isIgnorableWhitespace
(int
the codepoint to check
ch
)

Checks whether or not the specified codepoint is whitespace which is ignorable at the shaping stage of text rendering.

public static boolean
public static boolean
isNonSimpleChar(char ch)

public static void
public static void
public static void
public static String
public static boolean
textLayoutIsCompatible(Font font)

Used by windows printing to assess if a font is likely to be layout compatible with JDK TrueType fonts should be, but if they have no GPOS table, but do have a GSUB table, then they are probably older fonts GDI handles differently.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

compMapRefback to summary
private static volatile SoftReference<ConcurrentHashMap<PhysicalFont, CompositeFont>> compMapRef

This method is provided for internal and exclusive use by Swing. It may be used in conjunction with fontSupportsDefaultEncoding(Font) In the event that a desktop properties font doesn't directly support the default encoding, (ie because the host OS supports adding support for the current locale automatically for native apps), then Swing calls this method to get a font which uses the specified font for the code points it covers, but also supports this locale just as the standard composite fonts do.

Note

this will over-ride any setting where an application specifies it prefers locale specific composite fonts. The logic for this, is that this method is used only where the user or application has specified that the native L&F be used, and that we should honour that request to use the same font as native apps use. The behaviour of this method is to construct a new composite Font object that uses the specified physical font as its first component, and adds all the components of "dialog" as fall back components. The method currently assumes that only the size and style attributes are set on the specified font. It doesn't copy the font transform or other attributes because they aren't set on a font created from the desktop. This will need to be fixed if use is broadened. Operations such as Font.deriveFont will work properly on the font returned by this method for deriving a different point size. Additionally it tries to support a different style by calling getNewComposite() below. That also supports replacing slot zero with a different physical font but that is expected to be "rare". Deriving with a different style is needed because its been shown that some applications try to do this for Swing FontUIResources. Also operations such as new Font(font.getFontName(..), Font.PLAIN, 14); will NOT yield the same result, as the new underlying CompositeFont cannot be "looked up" in the font registry. This returns a FontUIResource as that is the Font sub-class needed by Swing. Suggested usage is something like : FontUIResource fuir; Font desktopFont = getDesktopFont(..); if (FontManager.fontSupportsDefaultEncoding(desktopFont)) { fuir = new FontUIResource(desktopFont); } else { fuir = FontManager.getCompositeFontUIResource(desktopFont); } return fuir;

debugFontsback to summary
private static boolean debugFonts
isLinuxback to summary
public static boolean isLinux
isMacOSXback to summary
public static boolean isMacOSX
isMacOSX14back to summary
public static boolean isMacOSX14
isWindowsback to summary
public static boolean isWindows
loggerback to summary
private static PlatformLogger logger
loggingback to summary
private static boolean logging
MAX_LAYOUT_CHARCODEback to summary
public static final int MAX_LAYOUT_CHARCODE

Referenced by code in the JDK which wants to test for the maximum char code for which layout may be required. Note this does not account for supplementary characters where the caller interprets 'layout' to mean any case where one 'char' (ie the java type char) does not map to one glyph

MIN_LAYOUT_CHARCODEback to summary
public static final int MIN_LAYOUT_CHARCODE

Referenced by code in the JDK which wants to test for the minimum char code for which layout may be required. Note that even basic latin text can benefit from ligatures, eg "ffi" but we presently apply those only if explicitly requested with TextAttribute.LIGATURES_ON. The value here indicates the lowest char code for which failing to invoke layout would prevent acceptable rendering.

nameMapback to summary
private static final String[][] nameMap
useJDKScalerback to summary
public static boolean useJDKScaler

Constructor Detail

FontUtilitiesback to summary
public FontUtilities()

Method Detail

debugFontsback to summary
public static boolean debugFonts()
fontSupportsDefaultEncodingback to summary
public static boolean fontSupportsDefaultEncoding(Font font)
getCompositeFontUIResourceback to summary
public static FontUIResource getCompositeFontUIResource(Font font)
getFont2Dback to summary
public static Font2D getFont2D(Font font)

Calls the private getFont2D() method in java.awt.Font objects.

Parameters
font:Font

the font object to call

Returns:Font2D

the Font2D object returned by Font.getFont2D()

getFontConfigFUIRback to summary
public static FontUIResource getFontConfigFUIR(String fcFamily, int style, int size)
getLoggerback to summary
public static PlatformLogger getLogger()
initStaticback to summary
private static void initStatic()
Annotations
@SuppressWarnings:deprecation
isComplexCharCodeback to summary
public static boolean isComplexCharCode(int code)
isComplexScriptback to summary
public static boolean isComplexScript(char[] chs, int start, int limit)

Return true if there any characters which would trigger layout. This method considers supplementary characters to be simple, since we do not presently invoke layout on any code points in outside the BMP.

isComplexTextback to summary
public static boolean isComplexText(char[] chs, int start, int limit)

If there is anything in the text which triggers a case where char->glyph does not map 1:1 in straightforward left->right ordering, then this method returns true. Scripts which might require it but are not treated as such due to JDK implementations will not return true. ie a 'true' return is an indication of the treatment by the implementation. Whether supplementary characters should be considered is dependent on the needs of the caller. Since this method accepts the 'char' type then such chars are always represented by a pair. From a rendering perspective these will all (in the cases I know of) still be one unicode character -> one glyph. But if a caller is using this to discover any case where it cannot make naive assumptions about the number of chars, and how to index through them, then it may need the option to have a 'true' return in such a case.

isDefaultIgnorableback to summary
public static boolean isDefaultIgnorable(int charCode)

Checks whether or not the specified codepoint is ignorable by default, per the Unicode standard (with exceptions for HarfBuzz and Uniscribe compatibility). The codepoints categorized as ignorable should remain in sync with HarfBuzz's is_default_ignorable() in hb-unicode.hh.

See the original Unicode list of default-ignorable codepoints here:

00AD         # Cf       SOFT HYPHEN
034F         # Mn       COMBINING GRAPHEME JOINER
061C         # Cf       ARABIC LETTER MARK
115F..1160   # Lo   [2] HANGUL CHOSEONG FILLER..HANGUL JUNGSEONG FILLER
17B4..17B5   # Mn   [2] KHMER VOWEL INHERENT AQ..KHMER VOWEL INHERENT AA
180B..180D   # Mn   [3] MONGOLIAN FREE VARIATION SELECTOR ONE..MONGOLIAN FREE VARIATION SELECTOR THREE
180E         # Cf       MONGOLIAN VOWEL SEPARATOR
180F         # Mn       MONGOLIAN FREE VARIATION SELECTOR FOUR
200B..200F   # Cf   [5] ZERO WIDTH SPACE..RIGHT-TO-LEFT MARK
202A..202E   # Cf   [5] LEFT-TO-RIGHT EMBEDDING..RIGHT-TO-LEFT OVERRIDE
2060..2064   # Cf   [5] WORD JOINER..INVISIBLE PLUS
2065         # Cn       
2066..206F   # Cf  [10] LEFT-TO-RIGHT ISOLATE..NOMINAL DIGIT SHAPES
3164         # Lo       HANGUL FILLER
FE00..FE0F   # Mn  [16] VARIATION SELECTOR-1..VARIATION SELECTOR-16
FEFF         # Cf       ZERO WIDTH NO-BREAK SPACE
FFA0         # Lo       HALFWIDTH HANGUL FILLER
FFF0..FFF8   # Cn   [9] ..
1BCA0..1BCA3 # Cf   [4] SHORTHAND FORMAT LETTER OVERLAP..SHORTHAND FORMAT UP STEP
1D173..1D17A # Cf   [8] MUSICAL SYMBOL BEGIN BEAM..MUSICAL SYMBOL END PHRASE
E0000        # Cn       
E0001        # Cf       LANGUAGE TAG
E0002..E001F # Cn  [30] ..
E0020..E007F # Cf  [96] TAG SPACE..CANCEL TAG
E0080..E00FF # Cn [128] ..
E0100..E01EF # Mn [240] VARIATION SELECTOR-17..VARIATION SELECTOR-256
E01F0..E0FFF # Cn [3600] ..
isIgnorableWhitespaceback to summary
public static boolean isIgnorableWhitespace(int ch)

Checks whether or not the specified codepoint is whitespace which is ignorable at the shaping stage of text rendering. These ignorable whitespace characters should be used prior to text shaping and rendering to determine the position of the text, but are not themselves rendered.

Includes 0x0009 (horizontal tab / TAB), 0x000A (line feed / LF), 0x000B (vertical tab / VT), 0x000C (form feed / FF), 0x000D (carriage return / CR), 0x0085 (next line / NEL), 0x2028 (line separator / LS), 0x2029 (paragraph separator / PS).

Parameters
ch:int

the codepoint to check

Returns:boolean

whether the specified codepoint is ignorable whitespace

isLoggingback to summary
public static boolean isLogging()
isNonSimpleCharback to summary
public static boolean isNonSimpleChar(char ch)
logInfoback to summary
public static void logInfo(String s)
logSevereback to summary
public static void logSevere(String s)
logWarningback to summary
public static void logWarning(String s)
mapFcNameback to summary
public static String mapFcName(String name)
textLayoutIsCompatibleback to summary
public static boolean textLayoutIsCompatible(Font font)

Used by windows printing to assess if a font is likely to be layout compatible with JDK TrueType fonts should be, but if they have no GPOS table, but do have a GSUB table, then they are probably older fonts GDI handles differently.