Class FallbackFontSet
- All Implemented Interfaces:
Serializable
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.ROOT
locale.
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
FallbackFontSet
objects are suitably synchronized for use in multiple
threads.
Serialization
FallbackFontSet
objects can be serialized, provided that they contain
only fonts which can be serialized.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty FallbackFontSet.Create a FallbackFontSet by copying an existing one. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFallbackFont
(ULocale locale, Font font) Add a font to the setvoid
addFallbackFonts
(ULocale locale, Font[] fontsToAdd) Add each font in an array to the set.boolean
getFallbackFonts
(ULocale locale) Enumerate the fonts for a locale.int
hashCode()
boolean
isEmpty()
A test on whether this fontset contains any fonts.boolean
A test on whether this fontset contains any fonts for the given locale.toString()
-
Constructor Details
-
FallbackFontSet
public FallbackFontSet()Create an empty FallbackFontSet. -
FallbackFontSet
Create a FallbackFontSet by copying an existing one.
-
-
Method Details
-
addFallbackFonts
Add each font in an array to the set.- Parameters:
locale
- the locale for which those fonts are appropriatefontsToAdd
- the fonts to add
-
addFallbackFont
Add a font to the set- Parameters:
locale
- the locale for which the font is appropriatefont
- the font to add
-
getFallbackFonts
Enumerate the fonts for a locale. The fonts forlocale
are enumerated, then the fonts for the fallback locale oflocale
, and so on. -
equals
-
hashCode
public int hashCode() -
isEmpty
public boolean isEmpty()A test on whether this fontset contains any fonts.- Returns:
- true if the fontset is empty, false otherwise
-
isEmpty
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
-