java.awt.font
Class NumericShaper

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.font.NumericShaper
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable

public final class NumericShaper
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Serializable sample code for java.io.Serializable definition code for java.io.Serializable

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 NUMERIC_SHAPING sample code for java.awt.font.TextAttribute.NUMERIC_SHAPING definition code for java.awt.font.TextAttribute.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 preceeding text is Arabic, or
   // shape European digits to TAMIL digits if preceeding text is Tamil, or
   // leave European digits alone if there is no preceeding text, or 
   // preceeding text is neither Arabic nor Tamil
   NumericShaper shaper = 
      NumericShaper.getContextualShaper(NumericShaper.ARABIC | 
                                              NumericShaper.TAMIL,
                                              NumericShaper.EUROPEAN);
   shaper.shape(text. start, count);
 

Since:
1.4
See Also:
Serialized Form

Field Summary
static int ALL_RANGES sample code for java.awt.font.NumericShaper.ALL_RANGES definition code for java.awt.font.NumericShaper.ALL_RANGES
          Identifies all ranges, for full contextual shaping.
static int ARABIC sample code for java.awt.font.NumericShaper.ARABIC definition code for java.awt.font.NumericShaper.ARABIC
          Identifies the ARABIC range and decimal base.
static int BENGALI sample code for java.awt.font.NumericShaper.BENGALI definition code for java.awt.font.NumericShaper.BENGALI
          Identifies the BENGALI range and decimal base.
static int DEVANAGARI sample code for java.awt.font.NumericShaper.DEVANAGARI definition code for java.awt.font.NumericShaper.DEVANAGARI
          Identifies the DEVANAGARI range and decimal base.
static int EASTERN_ARABIC sample code for java.awt.font.NumericShaper.EASTERN_ARABIC definition code for java.awt.font.NumericShaper.EASTERN_ARABIC
          Identifies the ARABIC range and ARABIC_EXTENDED decimal base.
static int ETHIOPIC sample code for java.awt.font.NumericShaper.ETHIOPIC definition code for java.awt.font.NumericShaper.ETHIOPIC
          Identifies the ETHIOPIC range and decimal base.
static int EUROPEAN sample code for java.awt.font.NumericShaper.EUROPEAN definition code for java.awt.font.NumericShaper.EUROPEAN
          Identifies the Latin-1 (European) and extended range, and Latin-1 (European) decimal base.
static int GUJARATI sample code for java.awt.font.NumericShaper.GUJARATI definition code for java.awt.font.NumericShaper.GUJARATI
          Identifies the GUJARATI range and decimal base.
static int GURMUKHI sample code for java.awt.font.NumericShaper.GURMUKHI definition code for java.awt.font.NumericShaper.GURMUKHI
          Identifies the GURMUKHI range and decimal base.
static int KANNADA sample code for java.awt.font.NumericShaper.KANNADA definition code for java.awt.font.NumericShaper.KANNADA
          Identifies the KANNADA range and decimal base.
static int KHMER sample code for java.awt.font.NumericShaper.KHMER definition code for java.awt.font.NumericShaper.KHMER
          Identifies the KHMER range and decimal base.
static int LAO sample code for java.awt.font.NumericShaper.LAO definition code for java.awt.font.NumericShaper.LAO
          Identifies the LAO range and decimal base.
static int MALAYALAM sample code for java.awt.font.NumericShaper.MALAYALAM definition code for java.awt.font.NumericShaper.MALAYALAM
          Identifies the MALAYALAM range and decimal base.
static int MONGOLIAN sample code for java.awt.font.NumericShaper.MONGOLIAN definition code for java.awt.font.NumericShaper.MONGOLIAN
          Identifies the MONGOLIAN range and decimal base.
static int MYANMAR sample code for java.awt.font.NumericShaper.MYANMAR definition code for java.awt.font.NumericShaper.MYANMAR
          Identifies the MYANMAR range and decimal base.
static int ORIYA sample code for java.awt.font.NumericShaper.ORIYA definition code for java.awt.font.NumericShaper.ORIYA
          Identifies the ORIYA range and decimal base.
static int TAMIL sample code for java.awt.font.NumericShaper.TAMIL definition code for java.awt.font.NumericShaper.TAMIL
          Identifies the TAMIL range and decimal base.
static int TELUGU sample code for java.awt.font.NumericShaper.TELUGU definition code for java.awt.font.NumericShaper.TELUGU
          Identifies the TELUGU range and decimal base.
static int THAI sample code for java.awt.font.NumericShaper.THAI definition code for java.awt.font.NumericShaper.THAI
          Identifies the THAI range and decimal base.
static int TIBETAN sample code for java.awt.font.NumericShaper.TIBETAN definition code for java.awt.font.NumericShaper.TIBETAN
          Identifies the TIBETAN range and decimal base.
 
Method Summary
 boolean equals sample code for java.awt.font.NumericShaper.equals(java.lang.Object) definition code for java.awt.font.NumericShaper.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  o)
          Returns true if the specified object is an instance of NumericShaper and shapes identically to this one.
static NumericShaper sample code for java.awt.font.NumericShaper definition code for java.awt.font.NumericShaper getContextualShaper sample code for java.awt.font.NumericShaper.getContextualShaper(int) definition code for java.awt.font.NumericShaper.getContextualShaper(int) (int ranges)
          Returns a contextual shaper for the provided unicode range(s).
static NumericShaper sample code for java.awt.font.NumericShaper definition code for java.awt.font.NumericShaper getContextualShaper sample code for java.awt.font.NumericShaper.getContextualShaper(int, int) definition code for java.awt.font.NumericShaper.getContextualShaper(int, int) (int ranges, int defaultContext)
          Returns a contextual shaper for the provided unicode range(s).
 int getRanges sample code for java.awt.font.NumericShaper.getRanges() definition code for java.awt.font.NumericShaper.getRanges() ()
          Returns an int that ORs together the values for all the ranges that will be shaped.
static NumericShaper sample code for java.awt.font.NumericShaper definition code for java.awt.font.NumericShaper getShaper sample code for java.awt.font.NumericShaper.getShaper(int) definition code for java.awt.font.NumericShaper.getShaper(int) (int singleRange)
          Returns a shaper for the provided unicode range.
 int hashCode sample code for java.awt.font.NumericShaper.hashCode() definition code for java.awt.font.NumericShaper.hashCode() ()
          Returns a hash code for this shaper.
 boolean isContextual sample code for java.awt.font.NumericShaper.isContextual() definition code for java.awt.font.NumericShaper.isContextual() ()
          Returns a boolean indicating whether or not this shaper shapes contextually.
 void shape sample code for java.awt.font.NumericShaper.shape(char[], int, int) definition code for java.awt.font.NumericShaper.shape(char[], int, int) (char[] text, int start, int count)
          Converts the digits in the text that occur between start and start + count.
 void shape sample code for java.awt.font.NumericShaper.shape(char[], int, int, int) definition code for java.awt.font.NumericShaper.shape(char[], int, int, int) (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.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.awt.font.NumericShaper.toString() definition code for java.awt.font.NumericShaper.toString() ()
          Returns a String that describes this shaper.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

EUROPEAN sample code for java.awt.font.NumericShaper.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 sample code for java.awt.font.NumericShaper.ARABIC

public static final int ARABIC
Identifies the ARABIC range and decimal base.

See Also:
Constant Field Values

EASTERN_ARABIC sample code for java.awt.font.NumericShaper.EASTERN_ARABIC

public static final int EASTERN_ARABIC
Identifies the ARABIC range and ARABIC_EXTENDED decimal base.

See Also:
Constant Field Values

DEVANAGARI sample code for java.awt.font.NumericShaper.DEVANAGARI

public static final int DEVANAGARI
Identifies the DEVANAGARI range and decimal base.

See Also:
Constant Field Values

BENGALI sample code for java.awt.font.NumericShaper.BENGALI

public static final int BENGALI
Identifies the BENGALI range and decimal base.

See Also:
Constant Field Values

GURMUKHI sample code for java.awt.font.NumericShaper.GURMUKHI

public static final int GURMUKHI
Identifies the GURMUKHI range and decimal base.

See Also:
Constant Field Values

GUJARATI sample code for java.awt.font.NumericShaper.GUJARATI

public static final int GUJARATI
Identifies the GUJARATI range and decimal base.

See Also:
Constant Field Values

ORIYA sample code for java.awt.font.NumericShaper.ORIYA

public static final int ORIYA
Identifies the ORIYA range and decimal base.

See Also:
Constant Field Values

TAMIL sample code for java.awt.font.NumericShaper.TAMIL

public static final int TAMIL
Identifies the TAMIL range and decimal base. Tamil does not have a decimal digit 0 so Latin-1 (European) 0 is used.

See Also:
Constant Field Values

TELUGU sample code for java.awt.font.NumericShaper.TELUGU

public static final int TELUGU
Identifies the TELUGU range and decimal base.

See Also:
Constant Field Values

KANNADA sample code for java.awt.font.NumericShaper.KANNADA

public static final int KANNADA
Identifies the KANNADA range and decimal base.

See Also:
Constant Field Values

MALAYALAM sample code for java.awt.font.NumericShaper.MALAYALAM

public static final int MALAYALAM
Identifies the MALAYALAM range and decimal base.

See Also:
Constant Field Values

THAI sample code for java.awt.font.NumericShaper.THAI

public static final int THAI
Identifies the THAI range and decimal base.

See Also:
Constant Field Values

LAO sample code for java.awt.font.NumericShaper.LAO

public static final int LAO
Identifies the LAO range and decimal base.

See Also:
Constant Field Values

TIBETAN sample code for java.awt.font.NumericShaper.TIBETAN

public static final int TIBETAN
Identifies the TIBETAN range and decimal base.

See Also:
Constant Field Values

MYANMAR sample code for java.awt.font.NumericShaper.MYANMAR

public static final int MYANMAR
Identifies the MYANMAR range and decimal base.

See Also:
Constant Field Values

ETHIOPIC sample code for java.awt.font.NumericShaper.ETHIOPIC

public static final int ETHIOPIC
Identifies the ETHIOPIC range and decimal base.

See Also:
Constant Field Values

KHMER sample code for java.awt.font.NumericShaper.KHMER

public static final int KHMER
Identifies the KHMER range and decimal base.

See Also:
Constant Field Values

MONGOLIAN sample code for java.awt.font.NumericShaper.MONGOLIAN

public static final int MONGOLIAN
Identifies the MONGOLIAN range and decimal base.

See Also:
Constant Field Values

ALL_RANGES sample code for java.awt.font.NumericShaper.ALL_RANGES

public static final int ALL_RANGES
Identifies all ranges, for full contextual shaping.

See Also:
Constant Field Values
Method Detail

getShaper sample code for java.awt.font.NumericShaper.getShaper(int) definition code for java.awt.font.NumericShaper.getShaper(int)

public static NumericShaper sample code for java.awt.font.NumericShaper definition code for java.awt.font.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 sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the range is not a single range

getContextualShaper sample code for java.awt.font.NumericShaper.getContextualShaper(int) definition code for java.awt.font.NumericShaper.getContextualShaper(int)

public static NumericShaper sample code for java.awt.font.NumericShaper definition code for java.awt.font.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 preceeding 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 sample code for java.awt.font.NumericShaper.getContextualShaper(int, int) definition code for java.awt.font.NumericShaper.getContextualShaper(int, int)

public static NumericShaper sample code for java.awt.font.NumericShaper definition code for java.awt.font.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 preceeding 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.

shape sample code for java.awt.font.NumericShaper.shape(char[], int, int) definition code for java.awt.font.NumericShaper.shape(char[], int, int)

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 convert
start - the index into text to start converting
count - the number of characters in text to convert

shape sample code for java.awt.font.NumericShaper.shape(char[], int, int, int) definition code for java.awt.font.NumericShaper.shape(char[], int, int, int)

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 characters
start - the index into text to start converting
count - the number of characters in text to convert
context - the context to which to convert the characters, such as NumericShaper.EUROPEAN

isContextual sample code for java.awt.font.NumericShaper.isContextual() definition code for java.awt.font.NumericShaper.isContextual()

public boolean isContextual()
Returns a boolean indicating whether or not this shaper shapes contextually.

Returns:
true if this shaper is contextual; false otherwise.

getRanges sample code for java.awt.font.NumericShaper.getRanges() definition code for java.awt.font.NumericShaper.getRanges()

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) { ...

Returns:
the values for all the ranges to be shaped.

hashCode sample code for java.awt.font.NumericShaper.hashCode() definition code for java.awt.font.NumericShaper.hashCode()

public int hashCode()
Returns a hash code for this shaper.

Overrides:
hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
this shaper's hash code.
See Also:
Object.hashCode() sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode()

equals sample code for java.awt.font.NumericShaper.equals(java.lang.Object) definition code for java.awt.font.NumericShaper.equals(java.lang.Object)

public boolean equals(Object sample code for java.lang.Object definition code for java.lang.Object  o)
Returns true if the specified object is an instance of NumericShaper and shapes identically to this one.

Overrides:
equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) in class Object sample code for java.lang.Object definition code for java.lang.Object
Parameters:
o - the specified object to compare to this NumericShaper
Returns:
true if o is an instance of NumericShaper and shapes in the same way; false otherwise.
See Also:
Object.equals(java.lang.Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object)

toString sample code for java.awt.font.NumericShaper.toString() definition code for java.awt.font.NumericShaper.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns a String that describes this shaper. This method is used for debugging purposes only.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a String describing this shaper.