- java.lang.Object
-
- java.awt.font.NumericShaper
-
- All Implemented Interfaces:
- Serializable
public final class NumericShaper extends Object implements Serializable
TheNumericShaper
class is used to convert Latin-1 (European) digits to other Unicode decimal digits. Users of this class will primarily be people who wish to present data using national digit shapes, but find it more convenient to represent the data internally using Latin-1 (European) digits. This does not interpret the deprecated numeric shape selector character (U+206E).Instances of
NumericShaper
are typically applied as attributes to text with theNUMERIC_SHAPING
attribute of theTextAttribute
class. For example, this code snippet causes aTextLayout
to shape European digits to Arabic in an Arabic context:
Map map = new HashMap(); map.put(TextAttribute.NUMERIC_SHAPING, NumericShaper.getContextualShaper(NumericShaper.ARABIC)); FontRenderContext frc = ...; TextLayout layout = new TextLayout(text, map, frc); layout.draw(g2d, x, y);
It is also possible to perform numeric shaping explicitly using instances ofNumericShaper
, as this code snippet demonstrates:
char[] text = ...; // shape all EUROPEAN digits (except zero) to ARABIC digits NumericShaper shaper = NumericShaper.getShaper(NumericShaper.ARABIC); shaper.shape(text, start, count); // shape European digits to ARABIC digits if preceding text is Arabic, or // shape European digits to TAMIL digits if preceding text is Tamil, or // leave European digits alone if there is no preceding text, or // preceding text is neither Arabic nor Tamil NumericShaper shaper = NumericShaper.getContextualShaper(NumericShaper.ARABIC | NumericShaper.TAMIL, NumericShaper.EUROPEAN); shaper.shape(text, start, count);
Bit mask- and enum-based Unicode ranges
This class supports two different programming interfaces to represent Unicode ranges for script-specific digits: bit mask-based ones, such as
NumericShaper.ARABIC
, and enum-based ones, such asNumericShaper.Range.ARABIC
. Multiple ranges can be specified by ORing bit mask-based constants, such as:
or creating aNumericShaper.ARABIC | NumericShaper.TAMIL
Set
with theNumericShaper.Range
constants, such as:
The enum-based ranges are a super set of the bit mask-based ones.EnumSet.of(NumericShaper.Scirpt.ARABIC, NumericShaper.Range.TAMIL)
If the two interfaces are mixed (including serialization), Unicode range values are mapped to their counterparts where such mapping is possible, such as
NumericShaper.Range.ARABIC
from/toNumericShaper.ARABIC
. If any unmappable range values are specified, such asNumericShaper.Range.BALINESE
, those ranges are ignored.Decimal Digits Precedence
A Unicode range may have more than one set of decimal digits. If multiple decimal digits sets are specified for the same Unicode range, one of the sets will take precedence as follows.
Unicode Range NumericShaper
ConstantsPrecedence Arabic NumericShaper.ARABIC
NumericShaper.EASTERN_ARABIC
NumericShaper.EASTERN_ARABIC
NumericShaper.Range.ARABIC
NumericShaper.Range.EASTERN_ARABIC
NumericShaper.Range.EASTERN_ARABIC
Tai Tham NumericShaper.Range.TAI_THAM_HORA
NumericShaper.Range.TAI_THAM_THAM
NumericShaper.Range.TAI_THAM_THAM
- Since:
- 1.4
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static class
NumericShaper.Range
ANumericShaper.Range
represents a Unicode range of a script having its own decimal digits.
-
Field Summary
Fields Modifier and Type Field and Description static int
ALL_RANGES
Identifies all ranges, for full contextual shaping.static int
ARABIC
Identifies the ARABIC range and decimal base.static int
BENGALI
Identifies the BENGALI range and decimal base.static int
DEVANAGARI
Identifies the DEVANAGARI range and decimal base.static int
EASTERN_ARABIC
Identifies the ARABIC range and ARABIC_EXTENDED decimal base.static int
ETHIOPIC
Identifies the ETHIOPIC range and decimal base.static int
EUROPEAN
Identifies the Latin-1 (European) and extended range, and Latin-1 (European) decimal base.static int
GUJARATI
Identifies the GUJARATI range and decimal base.static int
GURMUKHI
Identifies the GURMUKHI range and decimal base.static int
KANNADA
Identifies the KANNADA range and decimal base.static int
KHMER
Identifies the KHMER range and decimal base.static int
LAO
Identifies the LAO range and decimal base.static int
MALAYALAM
Identifies the MALAYALAM range and decimal base.static int
MONGOLIAN
Identifies the MONGOLIAN range and decimal base.static int
MYANMAR
Identifies the MYANMAR range and decimal base.static int
ORIYA
Identifies the ORIYA range and decimal base.static int
TAMIL
Identifies the TAMIL range and decimal base.static int
TELUGU
Identifies the TELUGU range and decimal base.static int
THAI
Identifies the THAI range and decimal base.static int
TIBETAN
Identifies the TIBETAN range and decimal base.
-
Method Summary
Methods Modifier and Type Method and Description boolean
equals(Object o)
Returnstrue
if the specified object is an instance ofNumericShaper
and shapes identically to this one, regardless of the range representations, the bit mask or the enum.static NumericShaper
getContextualShaper(int ranges)
Returns a contextual shaper for the provided unicode range(s).static NumericShaper
getContextualShaper(int ranges, int defaultContext)
Returns a contextual shaper for the provided unicode range(s).static NumericShaper
getContextualShaper(Set<NumericShaper.Range> ranges)
Returns a contextual shaper for the provided Unicode range(s).static NumericShaper
getContextualShaper(Set<NumericShaper.Range> ranges, NumericShaper.Range defaultContext)
Returns a contextual shaper for the provided Unicode range(s).int
getRanges()
Returns anint
that ORs together the values for all the ranges that will be shaped.Set<NumericShaper.Range>
getRangeSet()
Returns aSet
representing all the Unicode ranges in thisNumericShaper
that will be shaped.static NumericShaper
getShaper(int singleRange)
Returns a shaper for the provided unicode range.static NumericShaper
getShaper(NumericShaper.Range singleRange)
Returns a shaper for the provided Unicode range.int
hashCode()
Returns a hash code for this shaper.boolean
isContextual()
Returns aboolean
indicating whether or not this shaper shapes contextually.void
shape(char[] text, int start, int count)
Converts the digits in the text that occur between start and start + count.void
shape(char[] text, int start, int count, int context)
Converts the digits in the text that occur between start and start + count, using the provided context.void
shape(char[] text, int start, int count, NumericShaper.Range context)
Converts the digits in the text that occur betweenstart
andstart + count
, using the providedcontext
.String
toString()
Returns aString
that describes this shaper.
-
-
-
Field Detail
-
EUROPEAN
public static final int EUROPEAN
Identifies the Latin-1 (European) and extended range, and Latin-1 (European) decimal base.- See Also:
- Constant Field Values
-
ARABIC
public static final int ARABIC
Identifies the ARABIC range and decimal base.- See Also:
- Constant Field Values
-
EASTERN_ARABIC
public static final int EASTERN_ARABIC
Identifies the ARABIC range and ARABIC_EXTENDED decimal base.- See Also:
- Constant Field Values
-
DEVANAGARI
public static final int DEVANAGARI
Identifies the DEVANAGARI range and decimal base.- See Also:
- Constant Field Values
-
BENGALI
public static final int BENGALI
Identifies the BENGALI range and decimal base.- See Also:
- Constant Field Values
-
GURMUKHI
public static final int GURMUKHI
Identifies the GURMUKHI range and decimal base.- See Also:
- Constant Field Values
-
GUJARATI
public static final int GUJARATI
Identifies the GUJARATI range and decimal base.- See Also:
- Constant Field Values
-
ORIYA
public static final int ORIYA
Identifies the ORIYA range and decimal base.- See Also:
- Constant Field Values
-
TAMIL
public static final int TAMIL
Identifies the TAMIL range and decimal base.- See Also:
- Constant Field Values
-
TELUGU
public static final int TELUGU
Identifies the TELUGU range and decimal base.- See Also:
- Constant Field Values
-
KANNADA
public static final int KANNADA
Identifies the KANNADA range and decimal base.- See Also:
- Constant Field Values
-
MALAYALAM
public static final int MALAYALAM
Identifies the MALAYALAM range and decimal base.- See Also:
- Constant Field Values
-
THAI
public static final int THAI
Identifies the THAI range and decimal base.- See Also:
- Constant Field Values
-
LAO
public static final int LAO
Identifies the LAO range and decimal base.- See Also:
- Constant Field Values
-
TIBETAN
public static final int TIBETAN
Identifies the TIBETAN range and decimal base.- See Also:
- Constant Field Values
-
MYANMAR
public static final int MYANMAR
Identifies the MYANMAR range and decimal base.- See Also:
- Constant Field Values
-
ETHIOPIC
public static final int ETHIOPIC
Identifies the ETHIOPIC range and decimal base.- See Also:
- Constant Field Values
-
KHMER
public static final int KHMER
Identifies the KHMER range and decimal base.- See Also:
- Constant Field Values
-
MONGOLIAN
public static final int MONGOLIAN
Identifies the MONGOLIAN range and decimal base.- See Also:
- Constant Field Values
-
ALL_RANGES
public static final int ALL_RANGES
Identifies all ranges, for full contextual shaping.This constant specifies all of the bit mask-based ranges. Use
EmunSet.allOf(NumericShaper.Range.class)
to specify all of the enum-based ranges.- See Also:
- Constant Field Values
-
-
Method Detail
-
getShaper
public static NumericShaper getShaper(int singleRange)
Returns a shaper for the provided unicode range. All Latin-1 (EUROPEAN) digits are converted to the corresponding decimal unicode digits.- Parameters:
singleRange
- the specified Unicode range- Returns:
- a non-contextual numeric shaper
- Throws:
IllegalArgumentException
- if the range is not a single range
-
getShaper
public static NumericShaper getShaper(NumericShaper.Range singleRange)
Returns a shaper for the provided Unicode range. All Latin-1 (EUROPEAN) digits are converted to the corresponding decimal digits of the specified Unicode range.- Parameters:
singleRange
- the Unicode range given by aNumericShaper.Range
constant.- Returns:
- a non-contextual
NumericShaper
. - Throws:
NullPointerException
- ifsingleRange
isnull
- Since:
- 1.7
-
getContextualShaper
public static NumericShaper getContextualShaper(int ranges)
Returns a contextual shaper for the provided unicode range(s). Latin-1 (EUROPEAN) digits are converted to the decimal digits corresponding to the range of the preceding text, if the range is one of the provided ranges. Multiple ranges are represented by or-ing the values together, such as,NumericShaper.ARABIC | NumericShaper.THAI
. The shaper assumes EUROPEAN as the starting context, that is, if EUROPEAN digits are encountered before any strong directional text in the string, the context is presumed to be EUROPEAN, and so the digits will not shape.- Parameters:
ranges
- the specified Unicode ranges- Returns:
- a shaper for the specified ranges
-
getContextualShaper
public static NumericShaper getContextualShaper(Set<NumericShaper.Range> ranges)
Returns a contextual shaper for the provided Unicode range(s). The Latin-1 (EUROPEAN) digits are converted to the decimal digits corresponding to the range of the preceding text, if the range is one of the provided ranges.The shaper assumes EUROPEAN as the starting context, that is, if EUROPEAN digits are encountered before any strong directional text in the string, the context is presumed to be EUROPEAN, and so the digits will not shape.
- Parameters:
ranges
- the specified Unicode ranges- Returns:
- a contextual shaper for the specified ranges
- Throws:
NullPointerException
- ifranges
isnull
.- Since:
- 1.7
-
getContextualShaper
public static NumericShaper getContextualShaper(int ranges, int defaultContext)
Returns a contextual shaper for the provided unicode range(s). Latin-1 (EUROPEAN) digits will be converted to the decimal digits corresponding to the range of the preceding text, if the range is one of the provided ranges. Multiple ranges are represented by or-ing the values together, for example,NumericShaper.ARABIC | NumericShaper.THAI
. The shaper uses defaultContext as the starting context.- Parameters:
ranges
- the specified Unicode rangesdefaultContext
- the starting context, such asNumericShaper.EUROPEAN
- Returns:
- a shaper for the specified Unicode ranges.
- Throws:
IllegalArgumentException
- if the specifieddefaultContext
is not a single valid range.
-
getContextualShaper
public static NumericShaper getContextualShaper(Set<NumericShaper.Range> ranges, NumericShaper.Range defaultContext)
Returns a contextual shaper for the provided Unicode range(s). The Latin-1 (EUROPEAN) digits will be converted to the decimal digits corresponding to the range of the preceding text, if the range is one of the provided ranges. The shaper usesdefaultContext
as the starting context.- Parameters:
ranges
- the specified Unicode rangesdefaultContext
- the starting context, such asNumericShaper.Range.EUROPEAN
- Returns:
- a contextual shaper for the specified Unicode ranges.
- Throws:
NullPointerException
- ifranges
ordefaultContext
isnull
- Since:
- 1.7
-
shape
public void shape(char[] text, int start, int count)
Converts the digits in the text that occur between start and start + count.- Parameters:
text
- an array of characters to convertstart
- the index intotext
to start convertingcount
- the number of characters intext
to convert- Throws:
IndexOutOfBoundsException
- if start or start + count is out of boundsNullPointerException
- if text is null
-
shape
public void shape(char[] text, int start, int count, int context)
Converts the digits in the text that occur between start and start + count, using the provided context. Context is ignored if the shaper is not a contextual shaper.- Parameters:
text
- an array of charactersstart
- the index intotext
to start convertingcount
- the number of characters intext
to convertcontext
- the context to which to convert the characters, such asNumericShaper.EUROPEAN
- Throws:
IndexOutOfBoundsException
- if start or start + count is out of boundsNullPointerException
- if text is nullIllegalArgumentException
- if this is a contextual shaper and the specifiedcontext
is not a single valid range.
-
shape
public void shape(char[] text, int start, int count, NumericShaper.Range context)
Converts the digits in the text that occur betweenstart
andstart + count
, using the providedcontext
.Context
is ignored if the shaper is not a contextual shaper.- Parameters:
text
- achar
arraystart
- the index intotext
to start convertingcount
- the number ofchar
s intext
to convertcontext
- the context to which to convert the characters, such asNumericShaper.Range.EUROPEAN
- Throws:
IndexOutOfBoundsException
- ifstart
orstart + count
is out of boundsNullPointerException
- iftext
orcontext
is null- Since:
- 1.7
-
isContextual
public boolean isContextual()
Returns aboolean
indicating whether or not this shaper shapes contextually.- Returns:
true
if this shaper is contextual;false
otherwise.
-
getRanges
public int getRanges()
Returns anint
that ORs together the values for all the ranges that will be shaped.For example, to check if a shaper shapes to Arabic, you would use the following:
if ((shaper.getRanges() & shaper.ARABIC) != 0) { ...
Note that this method supports only the bit mask-based ranges. Call
getRangeSet()
for the enum-based ranges.- Returns:
- the values for all the ranges to be shaped.
-
getRangeSet
public Set<NumericShaper.Range> getRangeSet()
Returns aSet
representing all the Unicode ranges in thisNumericShaper
that will be shaped.- Returns:
- all the Unicode ranges to be shaped.
- Since:
- 1.7
-
hashCode
public int hashCode()
Returns a hash code for this shaper.- Overrides:
hashCode
in classObject
- Returns:
- this shaper's hash code.
- See Also:
Object.hashCode()
-
equals
public boolean equals(Object o)
Returnstrue
if the specified object is an instance ofNumericShaper
and shapes identically to this one, regardless of the range representations, the bit mask or the enum. For example, the following code produces"true"
.NumericShaper ns1 = NumericShaper.getShaper(NumericShaper.ARABIC); NumericShaper ns2 = NumericShaper.getShaper(NumericShaper.Range.ARABIC); System.out.println(ns1.equals(ns2));
- Overrides:
equals
in classObject
- Parameters:
o
- the specified object to compare to thisNumericShaper
- Returns:
true
ifo
is an instance ofNumericShaper
and shapes in the same way;false
otherwise.- See Also:
Object.equals(java.lang.Object)
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/awt/font/numericshaper.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.