- java.lang.Object
- 
- java.awt.font.NumericShaper
 
- 
- All Implemented Interfaces:
- Serializable
 
 public final class NumericShaper extends Object implements Serializable TheNumericShaperclass 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 NumericShaperare typically applied as attributes to text with theNUMERIC_SHAPINGattribute of theTextAttributeclass. For example, this code snippet causes aTextLayoutto 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 Setwith theNumericShaper.Rangeconstants, such as:
 The enum-based ranges are a super set of the bit mask-based ones.EnumSet.of(NumericShaper.Range.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.ARABICfrom/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. NumericShaper constants precedence Unicode Range NumericShaperConstantsPrecedence Arabic NumericShaper.ARABIC
 NumericShaper.EASTERN_ARABICNumericShaper.EASTERN_ARABICNumericShaper.Range.ARABIC
 NumericShaper.Range.EASTERN_ARABICNumericShaper.Range.EASTERN_ARABICTai Tham NumericShaper.Range.TAI_THAM_HORA
 NumericShaper.Range.TAI_THAM_THAMNumericShaper.Range.TAI_THAM_THAM- Since:
- 1.4
- See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classNumericShaper.RangeANumericShaper.Rangerepresents a Unicode range of a script having its own decimal digits.
 - 
Field SummaryFields Modifier and Type Field Description static intALL_RANGESIdentifies all ranges, for full contextual shaping.static intARABICIdentifies the ARABIC range and decimal base.static intBENGALIIdentifies the BENGALI range and decimal base.static intDEVANAGARIIdentifies the DEVANAGARI range and decimal base.static intEASTERN_ARABICIdentifies the ARABIC range and ARABIC_EXTENDED decimal base.static intETHIOPICIdentifies the ETHIOPIC range and decimal base.static intEUROPEANIdentifies the Latin-1 (European) and extended range, and Latin-1 (European) decimal base.static intGUJARATIIdentifies the GUJARATI range and decimal base.static intGURMUKHIIdentifies the GURMUKHI range and decimal base.static intKANNADAIdentifies the KANNADA range and decimal base.static intKHMERIdentifies the KHMER range and decimal base.static intLAOIdentifies the LAO range and decimal base.static intMALAYALAMIdentifies the MALAYALAM range and decimal base.static intMONGOLIANIdentifies the MONGOLIAN range and decimal base.static intMYANMARIdentifies the MYANMAR range and decimal base.static intORIYAIdentifies the ORIYA range and decimal base.static intTAMILIdentifies the TAMIL range and decimal base.static intTELUGUIdentifies the TELUGU range and decimal base.static intTHAIIdentifies the THAI range and decimal base.static intTIBETANIdentifies the TIBETAN range and decimal base.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)Returnstrueif the specified object is an instance ofNumericShaperand shapes identically to this one, regardless of the range representations, the bit mask or the enum.static NumericShapergetContextualShaper(int ranges)Returns a contextual shaper for the provided unicode range(s).static NumericShapergetContextualShaper(int ranges, int defaultContext)Returns a contextual shaper for the provided unicode range(s).static NumericShapergetContextualShaper(Set<NumericShaper.Range> ranges)Returns a contextual shaper for the provided Unicode range(s).static NumericShapergetContextualShaper(Set<NumericShaper.Range> ranges, NumericShaper.Range defaultContext)Returns a contextual shaper for the provided Unicode range(s).intgetRanges()Returns anintthat ORs together the values for all the ranges that will be shaped.Set<NumericShaper.Range>getRangeSet()Returns aSetrepresenting all the Unicode ranges in thisNumericShaperthat will be shaped.static NumericShapergetShaper(int singleRange)Returns a shaper for the provided unicode range.static NumericShapergetShaper(NumericShaper.Range singleRange)Returns a shaper for the provided Unicode range.inthashCode()Returns a hash code for this shaper.booleanisContextual()Returns abooleanindicating whether or not this shaper shapes contextually.voidshape(char[] text, int start, int count)Converts the digits in the text that occur between start and start + count.voidshape(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.voidshape(char[] text, int start, int count, NumericShaper.Range context)Converts the digits in the text that occur betweenstartandstart + count, using the providedcontext.StringtoString()Returns aStringthat describes this shaper.
 
- 
- 
- 
Field Detail- 
EUROPEANpublic static final int EUROPEAN Identifies the Latin-1 (European) and extended range, and Latin-1 (European) decimal base.- See Also:
- Constant Field Values
 
 - 
ARABICpublic static final int ARABIC Identifies the ARABIC range and decimal base.- See Also:
- Constant Field Values
 
 - 
EASTERN_ARABICpublic static final int EASTERN_ARABIC Identifies the ARABIC range and ARABIC_EXTENDED decimal base.- See Also:
- Constant Field Values
 
 - 
DEVANAGARIpublic static final int DEVANAGARI Identifies the DEVANAGARI range and decimal base.- See Also:
- Constant Field Values
 
 - 
BENGALIpublic static final int BENGALI Identifies the BENGALI range and decimal base.- See Also:
- Constant Field Values
 
 - 
GURMUKHIpublic static final int GURMUKHI Identifies the GURMUKHI range and decimal base.- See Also:
- Constant Field Values
 
 - 
GUJARATIpublic static final int GUJARATI Identifies the GUJARATI range and decimal base.- See Also:
- Constant Field Values
 
 - 
ORIYApublic static final int ORIYA Identifies the ORIYA range and decimal base.- See Also:
- Constant Field Values
 
 - 
TAMILpublic static final int TAMIL Identifies the TAMIL range and decimal base.- See Also:
- Constant Field Values
 
 - 
TELUGUpublic static final int TELUGU Identifies the TELUGU range and decimal base.- See Also:
- Constant Field Values
 
 - 
KANNADApublic static final int KANNADA Identifies the KANNADA range and decimal base.- See Also:
- Constant Field Values
 
 - 
MALAYALAMpublic static final int MALAYALAM Identifies the MALAYALAM range and decimal base.- See Also:
- Constant Field Values
 
 - 
THAIpublic static final int THAI Identifies the THAI range and decimal base.- See Also:
- Constant Field Values
 
 - 
LAOpublic static final int LAO Identifies the LAO range and decimal base.- See Also:
- Constant Field Values
 
 - 
TIBETANpublic static final int TIBETAN Identifies the TIBETAN range and decimal base.- See Also:
- Constant Field Values
 
 - 
MYANMARpublic static final int MYANMAR Identifies the MYANMAR range and decimal base.- See Also:
- Constant Field Values
 
 - 
ETHIOPICpublic static final int ETHIOPIC Identifies the ETHIOPIC range and decimal base.- See Also:
- Constant Field Values
 
 - 
KHMERpublic static final int KHMER Identifies the KHMER range and decimal base.- See Also:
- Constant Field Values
 
 - 
MONGOLIANpublic static final int MONGOLIAN Identifies the MONGOLIAN range and decimal base.- See Also:
- Constant Field Values
 
 - 
ALL_RANGESpublic static final int ALL_RANGES Identifies all ranges, for full contextual shaping.This constant specifies all of the bit mask-based ranges. Use EnumSet.allOf(NumericShaper.Range.class)to specify all of the enum-based ranges.- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getShaperpublic 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
 
 - 
getShaperpublic 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 a- NumericShaper.Rangeconstant.
- Returns:
- a non-contextual NumericShaper.
- Throws:
- NullPointerException- if- singleRangeis- null
- Since:
- 1.7
 
 - 
getContextualShaperpublic 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
 
 - 
getContextualShaperpublic 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- if- rangesis- null.
- Since:
- 1.7
 
 - 
getContextualShaperpublic 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 ranges
- defaultContext- the starting context, such as- NumericShaper.EUROPEAN
- Returns:
- a shaper for the specified Unicode ranges.
- Throws:
- IllegalArgumentException- if the specified- defaultContextis not a single valid range.
 
 - 
getContextualShaperpublic 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 usesdefaultContextas the starting context.- Parameters:
- ranges- the specified Unicode ranges
- defaultContext- the starting context, such as- NumericShaper.Range.EUROPEAN
- Returns:
- a contextual shaper for the specified Unicode ranges.
- Throws:
- NullPointerException- if- rangesor- defaultContextis- null
- Since:
- 1.7
 
 - 
shapepublic 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 convert
- start- the index into- textto start converting
- count- the number of characters in- textto convert
- Throws:
- IndexOutOfBoundsException- if start or start + count is out of bounds
- NullPointerException- if text is null
 
 - 
shapepublic 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 characters
- start- the index into- textto start converting
- count- the number of characters in- textto convert
- context- the context to which to convert the characters, such as- NumericShaper.EUROPEAN
- Throws:
- IndexOutOfBoundsException- if start or start + count is out of bounds
- NullPointerException- if text is null
- IllegalArgumentException- if this is a contextual shaper and the specified- contextis not a single valid range.
 
 - 
shapepublic void shape(char[] text, int start, int count, NumericShaper.Range context)Converts the digits in the text that occur betweenstartandstart + count, using the providedcontext.Contextis ignored if the shaper is not a contextual shaper.- Parameters:
- text- a- chararray
- start- the index into- textto start converting
- count- the number of- chars in- textto convert
- context- the context to which to convert the characters, such as- NumericShaper.Range.EUROPEAN
- Throws:
- IndexOutOfBoundsException- if- startor- start + countis out of bounds
- NullPointerException- if- textor- contextis null
- Since:
- 1.7
 
 - 
isContextualpublic boolean isContextual() Returns abooleanindicating whether or not this shaper shapes contextually.- Returns:
- trueif this shaper is contextual;- falseotherwise.
 
 - 
getRangespublic int getRanges() Returns anintthat 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.
 
 - 
getRangeSetpublic Set<NumericShaper.Range> getRangeSet() Returns aSetrepresenting all the Unicode ranges in thisNumericShaperthat will be shaped.- Returns:
- all the Unicode ranges to be shaped.
- Since:
- 1.7
 
 - 
hashCodepublic int hashCode() Returns a hash code for this shaper.- Overrides:
- hashCodein class- Object
- Returns:
- this shaper's hash code.
- See Also:
- Object.hashCode()
 
 - 
equalspublic boolean equals(Object o) Returnstrueif the specified object is an instance ofNumericShaperand 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:
- equalsin class- Object
- Parameters:
- o- the specified object to compare to this- NumericShaper
- Returns:
- trueif- ois an instance of- NumericShaperand shapes in the same way;- falseotherwise.
- See Also:
- Object.equals(java.lang.Object)
 
 
- 
 
-