Class FallbackFontSet

  • All Implemented Interfaces:
    java.io.Serializable

    public final class FallbackFontSet
    extends java.lang.Object
    implements java.io.Serializable
    A set of fonts indexed by ULocale, typically used for fallback.

    A FallbackFontSet is a set of fonts indexed by ULocale. A typical use is during formatting of text: if the requested font cannot be found or does not contain suitable glyphs for a portion of the text being formatted, the formatter can enumerate the fallback fonts for the locale of the text until a suitable font is found. Indexing by locale (by opposition to a flat set) improves the quality of the generated rendering; for example, some characters are used to write both Japanese and Chinese, but different shapes are expected.

    The addFallbackFont(ULocale, Font) and addFallbackFonts(ULocale, Font[]) methods allow the addition of one or more fonts to a set, for a given locale.

    The getFallbackFonts(ULocale) method returns an Iterator which first enumerates the fonts for a locale (in the order in which they were added), then the fonts for the fallback locale of that locale, and so on up to the fonts for the ULocale.ROOTlocale.

    For example, with a set setup like this:

     set.add (new ULocale ("en_US"), us1);
     set.add (new ULocale ("en_US"), us2);
     set.add (new ULocale ("en_CA"), ca1);
     set.add (new ULocale ("en_CA"), ca2);
     set.add (new ULocale ("en"), en1);
     set.add (new ULocale ("en"), en2);
     set.add (ULocale.ROOT, r1);
     set.add (ULocale.ROOT, r2);
     
    then the fallback fonts for the locale en_US are {us1, us2, en1, en2, r1, r2} in that order, the fallback fonts for the locale en_CA are {ca1, ca2, en1, en2, r1, r2} in that order, the fallback fonts for the locale en are {en1, en2, r1, r2} in that order, and the fallback fonts for the locale it are {r1, r2} in that order.

    Synchronization

    FallbackFontSetobjects are suitably synchronized for use in multiple threads.

    Serialization

    FallbackFontSetobjects can be serialized, provided that they contain only fonts which can be serialized.
    See Also:
    Serialized Form
    • Constructor Detail

      • FallbackFontSet

        public FallbackFontSet()
        Create an empty FallbackFontSet.
      • FallbackFontSet

        public FallbackFontSet​(FallbackFontSet ffs)
        Create a FallbackFontSet by copying an existing one.
    • Method Detail

      • addFallbackFonts

        public void addFallbackFonts​(ULocale locale,
                                     Font[] fontsToAdd)
        Add each font in an array to the set.
        Parameters:
        locale - the locale for which those fonts are appropriate
        fontsToAdd - the fonts to add
      • addFallbackFont

        public void addFallbackFont​(ULocale locale,
                                    Font font)
        Add a font to the set
        Parameters:
        locale - the locale for which the font is appropriate
        font - the font to add
      • getFallbackFonts

        public java.util.Iterator getFallbackFonts​(ULocale locale)
        Enumerate the fonts for a locale. The fonts for locale are enumerated, then the fonts for the fallback locale of locale, and so on.
      • equals

        public boolean equals​(java.lang.Object otherObject)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • isEmpty

        public boolean isEmpty()
        A test on whether this fontset contains any fonts.
        Returns:
        true if the fontset is empty, false otherwise
      • isEmpty

        public boolean isEmpty​(ULocale locale)
        A test on whether this fontset contains any fonts for the given locale.
        Parameters:
        locale - the locale to test
        Returns:
        true if the fontset has no fonts for the given locale, false otherwise
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object