| |
|
| java.lang.Object java.awt.font.NumericShaper
NumericShaper | final public class NumericShaper implements java.io.Serializable(Code) | | The NumericShaper 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 the
TextAttribute.NUMERIC_SHAPING NUMERIC_SHAPING attribute
of the TextAttribute class.
For example, this code snippet causes a TextLayout 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
of NumericShaper , 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);
since: 1.4 |
Field Summary | |
final public static int | ALL_RANGES Identifies all ranges, for full contextual shaping. | final public static int | ARABIC Identifies the ARABIC range and decimal base. | final public static int | BENGALI Identifies the BENGALI range and decimal base. | final public static int | DEVANAGARI Identifies the DEVANAGARI range and decimal base. | final public static int | EASTERN_ARABIC Identifies the ARABIC range and ARABIC_EXTENDED decimal base. | final public static int | ETHIOPIC Identifies the ETHIOPIC range and decimal base. | final public static int | EUROPEAN Identifies the Latin-1 (European) and extended range, and
Latin-1 (European) decimal base. | final public static int | GUJARATI Identifies the GUJARATI range and decimal base. | final public static int | GURMUKHI Identifies the GURMUKHI range and decimal base. | final public static int | KANNADA Identifies the KANNADA range and decimal base. | final public static int | KHMER Identifies the KHMER range and decimal base. | final public static int | LAO Identifies the LAO range and decimal base. | final public static int | MALAYALAM Identifies the MALAYALAM range and decimal base. | final public static int | MONGOLIAN Identifies the MONGOLIAN range and decimal base. | final public static int | MYANMAR Identifies the MYANMAR range and decimal base. | final public static int | ORIYA Identifies the ORIYA range and decimal base. | final public static int | TAMIL Identifies the TAMIL range and decimal base. | final public static int | TELUGU Identifies the TELUGU range and decimal base. | final public static int | THAI Identifies the THAI range and decimal base. | final public static int | TIBETAN Identifies the TIBETAN range and decimal base. |
Method Summary | |
public boolean | equals(Object o) Returns true if the specified object is an instance of
NumericShaper and shapes identically to this one. | public static NumericShaper | getContextualShaper(int ranges) Returns a contextual shaper for the provided unicode range(s). | public static NumericShaper | getContextualShaper(int ranges, int defaultContext) Returns a contextual shaper for the provided unicode range(s). | public int | getRanges() Returns an int 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) { ... | public static NumericShaper | getShaper(int singleRange) Returns a shaper for the provided unicode range. | public int | hashCode() Returns a hash code for this shaper. | public boolean | isContextual() Returns a boolean indicating whether or not
this shaper shapes contextually. | public void | shape(char[] text, int start, int count) Converts the digits in the text that occur between start and
start + count. | 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. | public String | toString() Returns a String that describes this shaper. |
ALL_RANGES | final public static int ALL_RANGES(Code) | | Identifies all ranges, for full contextual shaping.
|
ARABIC | final public static int ARABIC(Code) | | Identifies the ARABIC range and decimal base.
|
BENGALI | final public static int BENGALI(Code) | | Identifies the BENGALI range and decimal base.
|
DEVANAGARI | final public static int DEVANAGARI(Code) | | Identifies the DEVANAGARI range and decimal base.
|
EASTERN_ARABIC | final public static int EASTERN_ARABIC(Code) | | Identifies the ARABIC range and ARABIC_EXTENDED decimal base.
|
ETHIOPIC | final public static int ETHIOPIC(Code) | | Identifies the ETHIOPIC range and decimal base.
|
EUROPEAN | final public static int EUROPEAN(Code) | | Identifies the Latin-1 (European) and extended range, and
Latin-1 (European) decimal base.
|
GUJARATI | final public static int GUJARATI(Code) | | Identifies the GUJARATI range and decimal base.
|
GURMUKHI | final public static int GURMUKHI(Code) | | Identifies the GURMUKHI range and decimal base.
|
KANNADA | final public static int KANNADA(Code) | | Identifies the KANNADA range and decimal base.
|
KHMER | final public static int KHMER(Code) | | Identifies the KHMER range and decimal base.
|
LAO | final public static int LAO(Code) | | Identifies the LAO range and decimal base.
|
MALAYALAM | final public static int MALAYALAM(Code) | | Identifies the MALAYALAM range and decimal base.
|
MONGOLIAN | final public static int MONGOLIAN(Code) | | Identifies the MONGOLIAN range and decimal base.
|
MYANMAR | final public static int MYANMAR(Code) | | Identifies the MYANMAR range and decimal base.
|
ORIYA | final public static int ORIYA(Code) | | Identifies the ORIYA range and decimal base.
|
TAMIL | final public static int TAMIL(Code) | | Identifies the TAMIL range and decimal base. Tamil does not have a
decimal digit 0 so Latin-1 (European) 0 is used.
|
TELUGU | final public static int TELUGU(Code) | | Identifies the TELUGU range and decimal base.
|
THAI | final public static int THAI(Code) | | Identifies the THAI range and decimal base.
|
TIBETAN | final public static int TIBETAN(Code) | | Identifies the TIBETAN range and decimal base.
|
equals | public boolean equals(Object o)(Code) | | Returns true if the specified object is an instance of
NumericShaper and shapes identically to this one.
Parameters: o - the specified object to compare to thisNumericShaper true if o is an instanceof NumericShaper and shapes in the same way;false otherwise. See Also: java.lang.Object.equals(java.lang.Object) |
getContextualShaper | public static NumericShaper getContextualShaper(int ranges)(Code) | | 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 a shaper for the specified ranges |
getContextualShaper | public static NumericShaper getContextualShaper(int ranges, int defaultContext)(Code) | | 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 Parameters: defaultContext - the starting context, such as NumericShaper.EUROPEAN a shaper for the specified Unicode ranges. throws: IllegalArgumentException - if the specifieddefaultContext is not a single valid range. |
getRanges | public int getRanges()(Code) | | Returns an int 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) { ...
the values for all the ranges to be shaped. |
getShaper | public static NumericShaper getShaper(int singleRange)(Code) | | 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 a non-contextual numeric shaper throws: IllegalArgumentException - if the range is not a single range |
isContextual | public boolean isContextual()(Code) | | Returns a boolean indicating whether or not
this shaper shapes contextually.
true if this shaper is contextual; false otherwise. |
shape | public void shape(char[] text, int start, int count)(Code) | | Converts the digits in the text that occur between start and
start + count.
Parameters: text - an array of characters to convert Parameters: start - the index into text to start converting Parameters: count - the number of characters in text to convert throws: IndexOutOfBoundsException - if start or start + count isout of bounds throws: NullPointerException - if text is null |
shape | public void shape(char[] text, int start, int count, int context)(Code) | | 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 Parameters: start - the index into text to startconverting Parameters: count - the number of characters in text to convert Parameters: context - the context to which to convert the characters, such as NumericShaper.EUROPEAN throws: IndexOutOfBoundsException - if start or start + count isout of bounds throws: NullPointerException - if text is null throws: IllegalArgumentException - if this is a contextual shaperand the specified context is not a single validrange. |
toString | public String toString()(Code) | | Returns a String that describes this shaper. This method
is used for debugging purposes only.
a String describing this shaper. |
|
|
|