public final class NumericShaper
extends Object implements Serializable
| java.lang.Object | |
| ↳ | java.awt.font.NumericShaper |
NumericShaper类用于将Latin-1(欧洲)数字转换为其他Unicode十进制数字。 这个类的用户主要是那些希望使用国家数字形式呈现数据的人,但发现使用Latin-1(欧洲)数字在内部表示数据更方便。 这不会解释不推荐使用的数字形状选择器字符(U + 206E)。
通常将NumericShaper实例作为属性应用于具有TextAttribute类的NUMERIC_SHAPING属性的文本。 例如,此代码片段会导致TextLayout在阿拉伯语背景TextLayout欧洲数字变为阿拉伯数字:
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);
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);
位掩码和基于枚举的Unicode范围
此类支持两种不同的编程接口来表示脚本特定数字的Unicode范围:基于位掩码的数字(如NumericShaper.ARABIC )和基于枚举的数字(如ARABIC 。 ORing位掩码为基础的常量可以指定多个范围,例如:
or creating aNumericShaper.ARABIC | NumericShaper.TAMIL
Set with the
NumericShaper.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)
如果两个接口是混合的(包括序列化),则Unicode范围值将映射到可以进行映射的对应端,例如NumericShaper.Range.ARABIC ,其范围为NumericShaper.ARABIC 。 如果指定了任何不可映射的范围值(例如NumericShaper.Range.BALINESE ,则会忽略这些范围。
十进制数字优先
一个Unicode范围可能有多个一组十进制数字。 如果为相同的Unicode范围指定了多个小数位集合,则其中一个集合优先如下。
| Unicode Range | NumericShaper Constants |
Precedence |
|---|---|---|
| Arabic | NumericShaper.ARABICNumericShaper.EASTERN_ARABIC |
NumericShaper.EASTERN_ARABIC |
ARABICEASTERN_ARABIC |
EASTERN_ARABIC |
|
| Tai Tham | TAI_THAM_HORATAI_THAM_THAM |
TAI_THAM_THAM |
Nested classes |
|
|---|---|
枚举 |
NumericShaper.Range |
Constants |
|
|---|---|
int |
ALL_RANGES 标识所有范围,用于完整的上下文整形。 |
int |
ARABIC 标识ARABIC范围和小数基数。 |
int |
BENGALI 标识BENGALI范围和小数基数。 |
int |
DEVANAGARI 标识DEVANAGARI范围和小数基数。 |
int |
EASTERN_ARABIC 标识ARABIC范围和ARABIC_EXTENDED小数基数。 |
int |
ETHIOPIC 标识ETHIOPIC范围和小数基数。 |
int |
EUROPEAN 标识拉丁语-1(欧洲)和扩展范围,以及拉丁语-1(欧洲)小数基数。 |
int |
GUJARATI 标识GUJARATI范围和小数基数。 |
int |
GURMUKHI 标识GURMUKHI范围和小数基数。 |
int |
KANNADA 标识KANNADA范围和小数基数。 |
int |
KHMER 标识KHMER范围和小数基数。 |
int |
LAO 标识LAO范围和小数基数。 |
int |
MALAYALAM 标识MALAYALAM范围和小数基数。 |
int |
MONGOLIAN 标识蒙古文范围和小数点。 |
int |
MYANMAR 标识缅甸范围和小数点。 |
int |
ORIYA 标识ORIYA范围和小数基数。 |
int |
TAMIL 标识TAMIL范围和小数基数。 |
int |
TELUGU 标识TELUGU范围和小数基数。 |
int |
THAI 标识THAI范围和小数基数。 |
int |
TIBETAN 标识TIBETAN范围和小数基数。 |
Public methods |
|
|---|---|
boolean |
equals(Object o) 如果指定的对象是 |
static NumericShaper |
getContextualShaper(Set<NumericShaper.Range> ranges) 返回提供的Unicode范围的上下文整形器。 |
static NumericShaper |
getContextualShaper(int ranges, int defaultContext) 返回提供的unicode范围的上下文整形器。 |
static NumericShaper |
getContextualShaper(Set<NumericShaper.Range> ranges, NumericShaper.Range defaultContext) 返回提供的Unicode范围的上下文整形器。 |
static NumericShaper |
getContextualShaper(int ranges) 返回提供的unicode范围的上下文整形器。 |
Set<NumericShaper.Range> |
getRangeSet() 返回 |
int |
getRanges() 返回一个 |
static NumericShaper |
getShaper(int singleRange) 返回提供的unicode范围的整形器。 |
static NumericShaper |
getShaper(NumericShaper.Range singleRange) 返回提供的Unicode范围的整形器。 |
int |
hashCode() 返回此整形器的散列码。 |
boolean |
isContextual() 返回一个 |
void |
shape(char[] text, int start, int count) 转换文本中在开始和开始+计数之间出现的数字。 |
void |
shape(char[] text, int start, int count, NumericShaper.Range context) 使用提供的 |
void |
shape(char[] text, int start, int count, int context) 使用提供的上下文来转换文本中出现在start和start + count之间的数字。 |
String |
toString() 返回描述此整形器的 |
Inherited methods |
|
|---|---|
java.lang.Object
|
|
int ALL_RANGES
标识所有范围,用于完整的上下文整形。
此常数指定所有基于位掩码的范围。 使用EmunSet.allOf(NumericShaper.Range.class)指定所有基于枚举的范围。
常量值:524287(0x0007ffff)
int EASTERN_ARABIC
标识ARABIC范围和ARABIC_EXTENDED小数基数。
常量值:4(0x00000004)
boolean equals (Object o)
如果指定的对象是NumericShaper的实例并且形状与此实例相同,则返回true ,而不考虑范围表示,位掩码或枚举。 例如,下面的代码产生"true" 。
NumericShaper ns1 = NumericShaper.getShaper(NumericShaper.ARABIC); NumericShaper ns2 = NumericShaper.getShaper(NumericShaper.Range.ARABIC); System.out.println(ns1.equals(ns2));
| Parameters | |
|---|---|
o |
Object: the specified object to compare to this NumericShaper |
| Returns | |
|---|---|
boolean |
true if o is an instance of NumericShaper and shapes in the same way; false otherwise. |
也可以看看:
NumericShaper getContextualShaper (Set<NumericShaper.Range> ranges)
返回提供的Unicode范围的上下文整形器。 如果范围是提供的范围之一,Latin-1(EUROPEAN)数字将转换为与前面文本范围对应的小数位数。
整形器以EUROPEAN作为起始语境,即如果在字符串中的任何强指向性文本之前遇到欧洲数字,则上下文被假定为欧洲,因此数字不会成形。
| Parameters | |
|---|---|
ranges |
Set: the specified Unicode ranges |
| Returns | |
|---|---|
NumericShaper |
a contextual shaper for the specified ranges |
| Throws | |
|---|---|
NullPointerException |
if ranges is null. |
NumericShaper getContextualShaper (int ranges, int defaultContext)
返回提供的unicode范围的上下文整形器。 如果范围是提供的范围之一,Latin-1(EUROPEAN)数字将转换为与前面文本范围相对应的小数位数。 多个范围由一起表示,或者将这些值一起表示,例如NumericShaper.ARABIC | NumericShaper.THAI 。 整形器使用defaultContext作为起始上下文。
| Parameters | |
|---|---|
ranges |
int: the specified Unicode ranges |
defaultContext |
int: the starting context, such as NumericShaper.EUROPEAN |
| Returns | |
|---|---|
NumericShaper |
a shaper for the specified Unicode ranges. |
| Throws | |
|---|---|
IllegalArgumentException |
if the specified defaultContext is not a single valid range. |
NumericShaper getContextualShaper (Set<NumericShaper.Range> ranges, NumericShaper.Range defaultContext)
返回提供的Unicode范围的上下文整形器。 如果范围是提供的范围之一,Latin-1(EUROPEAN)数字将转换为与前面文本范围相对应的小数位数。 整形器使用defaultContext作为起始上下文。
| Parameters | |
|---|---|
ranges |
Set: the specified Unicode ranges |
defaultContext |
NumericShaper.Range: the starting context, such as NumericShaper.Range.EUROPEAN |
| Returns | |
|---|---|
NumericShaper |
a contextual shaper for the specified Unicode ranges. |
| Throws | |
|---|---|
NullPointerException |
if ranges or defaultContext is null |
NumericShaper getContextualShaper (int ranges)
返回提供的unicode范围的上下文整形器。 如果范围是提供的范围之一,Latin-1(EUROPEAN)数字将转换为与前面文本范围对应的小数位数。 多个范围由一起或一起表示,例如NumericShaper.ARABIC | NumericShaper.THAI 。 整形器以EUROPEAN作为起始语境,即如果在字符串中的任何强指向性文本之前遇到欧洲数字,则上下文被假定为欧洲,因此数字不会成形。
| Parameters | |
|---|---|
ranges |
int: the specified Unicode ranges |
| Returns | |
|---|---|
NumericShaper |
a shaper for the specified ranges |
Set<NumericShaper.Range> getRangeSet ()
返回一个 Set表示此 NumericShaper中将被整形的所有Unicode范围。
| Returns | |
|---|---|
Set<NumericShaper.Range> |
all the Unicode ranges to be shaped. |
int getRanges ()
返回一个 int ,将所有将被整形的范围的值进行或 int 。
例如,要检查整形器是否形成阿拉伯语,请使用以下内容:
if ((shaper.getRanges() & shaper.ARABIC) != 0) { ...
请注意,此方法仅支持基于位掩码的范围。 针对基于枚举的范围调用getRangeSet() 。
| Returns | |
|---|---|
int |
the values for all the ranges to be shaped. |
NumericShaper getShaper (int singleRange)
返回提供的unicode范围的整形器。 所有Latin-1(EUROPEAN)数字都转换为相应的十进制Unicode码。
| Parameters | |
|---|---|
singleRange |
int: the specified Unicode range |
| Returns | |
|---|---|
NumericShaper |
a non-contextual numeric shaper |
| Throws | |
|---|---|
IllegalArgumentException |
if the range is not a single range |
NumericShaper getShaper (NumericShaper.Range singleRange)
返回提供的Unicode范围的整形器。 所有Latin-1(EUROPEAN)数字都转换为指定Unicode范围的相应小数位数。
| Parameters | |
|---|---|
singleRange |
NumericShaper.Range: the Unicode range given by a NumericShaper.Range constant. |
| Returns | |
|---|---|
NumericShaper |
a non-contextual NumericShaper. |
| Throws | |
|---|---|
NullPointerException |
if singleRange is null |
int hashCode ()
返回此整形器的散列码。
| Returns | |
|---|---|
int |
this shaper's hash code. |
也可以看看:
boolean isContextual ()
返回一个 boolean指示该整形器是否在上下文中形成。
| Returns | |
|---|---|
boolean |
true if this shaper is contextual; false otherwise. |
void shape (char[] text,
int start,
int count)
转换文本中在开始和开始+计数之间出现的数字。
| Parameters | |
|---|---|
text |
char: an array of characters to convert |
start |
int: the index into text to start converting |
count |
int: the number of characters in text to convert |
| Throws | |
|---|---|
IndexOutOfBoundsException |
if start or start + count is out of bounds |
NullPointerException |
if text is null |
void shape (char[] text,
int start,
int count,
NumericShaper.Range context)
使用提供的context转换文本中出现在start和start + count之间的数字。 如果整形器不是上下文整形器,则忽略Context 。
| Parameters | |
|---|---|
text |
char: a char array |
start |
int: the index into text to start converting |
count |
int: the number of chars in text to convert |
context |
NumericShaper.Range: the context to which to convert the characters, such as NumericShaper.Range.EUROPEAN |
| Throws | |
|---|---|
IndexOutOfBoundsException |
if start or start + count is out of bounds |
NullPointerException |
if text or context is null |
void shape (char[] text,
int start,
int count,
int context)
使用提供的上下文来转换文本中出现在start和start + count之间的数字。 如果整形器不是上下文整形器,则会忽略上下文。
| Parameters | |
|---|---|
text |
char: an array of characters |
start |
int: the index into text to start converting |
count |
int: the number of characters in text to convert |
context |
int: 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 context is not a single valid range. |
String toString ()
返回描述此整形器的String 。 此方法仅用于调试目的。
| Returns | |
|---|---|
String |
a String describing this shaper. |