public final class TextLayout extends Object implements Cloneable
TextLayout是风格字符数据的不可变的图形表示。
它提供以下功能:
一个TextLayout对象可以使用其draw方法渲染。
TextLayout可以直接或通过使用LineBreakMeasurer构建 。 直接构建时,源文本代表一个段落。 LineBreakMeasurer允许将样式文本分解成适合特定宽度的行。 有关更多信息,请参阅LineBreakMeasurer文档。
TextLayout建设逻辑进行如下:
TextAttribute.FONT使用字体,否则通过使用已定义的属性计算默认字体 从TextLayout对象的方法返回的所有图形信息都是相对于TextLayout的起点, TextLayout是TextLayout对象的基线与其左边缘的TextLayout 。 而且,假定传递给TextLayout对象的方法的坐标是相对于TextLayout对象的来源。 客户通常需要在TextLayout对象的坐标系和另一个对象(例如Graphics对象)中的坐标系之间进行TextLayout 。
TextLayout对象由样式文本构建,但它们不保留对其源文本的引用。 因此,以前用于生成TextLayout的文本的更改不会影响TextLayout 。
一对三种方法TextLayout对象( getNextRightHit , getNextLeftHit和hitTestChar )返回的实例TextHitInfo 。 这些TextHitInfo对象中的偏移量相对于TextLayout , 而不是用于创建TextLayout的文本。 类似地,接受TextHitInfo实例作为参数的TextLayout方法期望TextHitInfo对象的偏移量相对于TextLayout ,而不是任何基础文本存储模型。
示例 :
构造和绘制一个TextLayout及其边界矩形:
Graphics2D g = ...;
Point2D loc = ...;
Font font = Font.getFont("Helvetica-bold-italic");
FontRenderContext frc = g.getFontRenderContext();
TextLayout layout = new TextLayout("This is a string", font, frc);
layout.draw(g, (float)loc.getX(), (float)loc.getY());
Rectangle2D bounds = layout.getBounds();
bounds.setRect(bounds.getX()+loc.getX(),
bounds.getY()+loc.getY(),
bounds.getWidth(),
bounds.getHeight());
g.draw(bounds);
测试一个TextLayout (确定哪个字符在特定的图形位置):
Point2D click = ...;
TextHitInfo hit = layout.hitTestChar(
(float) (click.getX() - loc.getX()),
(float) (click.getY() - loc.getY()));
按右箭头按键:
int insertionIndex = ...;
TextHitInfo next = layout.getNextRightHit(insertionIndex);
if (next != null) {
// translate graphics to origin of layout on screen
g.translate(loc.getX(), loc.getY());
Shape[] carets = layout.getCaretShapes(next.getInsertionIndex());
g.draw(carets[0]);
if (carets[1] != null) {
g.draw(carets[1]);
}
}
绘制对应于源文本中的子字符串的选择范围。 所选区域可能不是视觉上连续的:
// selStart, selLimit should be relative to the layout, // not to the source text int selStart = ..., selLimit = ...; Color selectionColor = ...; Shape selection = layout.getLogicalHighlightShape(selStart, selLimit); // selection may consist of disjoint areas // graphics is assumed to be tranlated to origin of layout g.setColor(selectionColor); g.fill(selection);
绘制视觉上连续的选择范围。 选择范围可以对应于源文本中的多个子字符串。 可以使用getLogicalRangesForVisualSelection()获取相应的源文本子串的范围:
TextHitInfo selStart = ..., selLimit = ...; Shape selection = layout.getVisualHighlightShape(selStart, selLimit); g.setColor(selectionColor); g.fill(selection); int[] ranges = getLogicalRangesForVisualSelection(selStart, selLimit); // ranges[0], ranges[1] is the first selection range, // ranges[2], ranges[3] is the second selection range, etc.
注意:字体旋转可以使文本基线旋转,多次运行不同的旋转可能导致基线弯曲或曲折。 为了解决这个(罕见的)可能性,指定了一些API返回度量值并在“基线相对坐标”(例如,上升,前进)中获取参数,而其他API在“标准坐标”(例如getBounds)中。 基线相对坐标中的值将“x”坐标映射到沿着基线的距离(正x沿着基线向前),“y”坐标与“x”处垂直于基线的距离y从基线矢量顺时针旋转90度)。 沿着x轴和y轴测量标准坐标值,在TextLayout的原点为0,0。 每个相关API的文档指示什么值在什么坐标系中。 通常,与测量相关的API处于基准相对坐标,而与显示相关的API处于标准坐标。
LineBreakMeasurer , TextAttribute , TextHitInfo , LayoutPath
| Modifier and Type | Class and Description |
|---|---|
static class |
TextLayout.CaretPolicy
定义确定强插插位置的策略。
|
| Modifier and Type | Field and Description |
|---|---|
static TextLayout.CaretPolicy |
DEFAULT_CARET_POLICY
当客户端未指定策略时,将使用此
CaretPolicy 。
|
| Constructor and Description |
|---|
TextLayout(AttributedCharacterIterator text, FontRenderContext frc)
从一个迭代器构造一个
TextLayout样式文本。
|
TextLayout(String string, Font font, FontRenderContext frc)
构造一个 TextLayout从String和Font 。
|
TextLayout(String string, Map<? extends AttributedCharacterIterator.Attribute,?> attributes, FontRenderContext frc)
构造一个
TextLayout从
String ,并设置一个属性。
|
| Modifier and Type | Method and Description |
|---|---|
protected Object |
clone()
创建一个这个
TextLayout的副本。
|
void |
draw(Graphics2D g2, float x, float y)
在指定的 Graphics2D上下文中指定的位置呈现此TextLayout 。
|
boolean |
equals(Object obj)
返回
true如果指定的
Object是
TextLayout对象,如果指定的
Object等于这个
TextLayout 。
|
boolean |
equals(TextLayout rhs)
如果两个布局相等,则返回
true 。
|
float |
getAdvance()
返回此
TextLayout 。
|
float |
getAscent()
返回此
TextLayout的上升。
|
byte |
getBaseline()
返回此
TextLayout的基准。
|
float[] |
getBaselineOffsets()
返回用于此
TextLayout的基线的偏移数组。
|
Shape |
getBlackBoxBounds(int firstEndpoint, int secondEndpoint)
返回指定范围内的字符的黑框边界。
|
Rectangle2D |
getBounds()
返回此
TextLayout的范围。
|
float[] |
getCaretInfo(TextHitInfo hit)
返回与hit对应的插入符号的
hit 。
|
float[] |
getCaretInfo(TextHitInfo hit, Rectangle2D bounds)
返回与hit对应的插入符号的
hit 。
|
Shape |
getCaretShape(TextHitInfo hit)
返回
Shape代表在指定的打这个的自然边界中插入符号
TextLayout 。
|
Shape |
getCaretShape(TextHitInfo hit, Rectangle2D bounds)
|
Shape[] |
getCaretShapes(int offset)
返回对应于强和弱插入符号的两个路径。
|
Shape[] |
getCaretShapes(int offset, Rectangle2D bounds)
返回对应于强和弱插入符号的两个路径。
|
Shape[] |
getCaretShapes(int offset, Rectangle2D bounds, TextLayout.CaretPolicy policy)
返回对应于强和弱插入符号的两个路径。
|
int |
getCharacterCount()
返回此
TextLayout 。
|
byte |
getCharacterLevel(int index)
返回index处的
index 。
|
float |
getDescent()
返回这个
TextLayout的下降。
|
TextLayout |
getJustifiedLayout(float justificationWidth)
创建一个这个
TextLayout对齐到指定宽度的副本。
|
LayoutPath |
getLayoutPath()
返回LayoutPath,如果布局路径是默认路径,则为null(x映射到advance,y映射到offset)。
|
float |
getLeading()
返回
TextLayout的领先。
|
Shape |
getLogicalHighlightShape(int firstEndpoint, int secondEndpoint)
返回一个
Shape将逻辑选择包围在指定的范围内,扩展到此
TextLayout 。
|
Shape |
getLogicalHighlightShape(int firstEndpoint, int secondEndpoint, Rectangle2D bounds)
返回一个
Shape将逻辑选择包含在指定的范围内,扩展到指定的
bounds 。
|
int[] |
getLogicalRangesForVisualSelection(TextHitInfo firstEndpoint, TextHitInfo secondEndpoint)
返回与视觉选择对应的文本的逻辑范围。
|
TextHitInfo |
getNextLeftHit(int offset)
返回左侧(顶部)的下一个插入符号的命中;
如果没有这样的命中,返回 null 。
|
TextHitInfo |
getNextLeftHit(int offset, TextLayout.CaretPolicy policy)
返回左侧(顶部)的下一个插入符号的命中;
如果没有这样的命中,返回 null 。
|
TextHitInfo |
getNextLeftHit(TextHitInfo hit)
返回左侧(顶部)的下一个插入符号的命中;
如果没有这样的命中,返回 null 。
|
TextHitInfo |
getNextRightHit(int offset)
返回右侧(下)的下一个插入符号的命中;
如果没有这样的命中,返回 null 。
|
TextHitInfo |
getNextRightHit(int offset, TextLayout.CaretPolicy policy)
返回右侧(下)的下一个插入符号的命中;
如果没有这样的命中,返回 null 。
|
TextHitInfo |
getNextRightHit(TextHitInfo hit)
返回右侧(下)的下一个插入符号的命中;
如果没有这样的命中,返回 null 。
|
Shape |
getOutline(AffineTransform tx)
返回一个
Shape代表这个
TextLayout的大纲。
|
Rectangle |
getPixelBounds(FontRenderContext frc, float x, float y)
在给定位置的给定
FontRenderContext的图形中渲染时返回此
TextLayout的像素边界。
|
float |
getVisibleAdvance()
返回此
TextLayout的提前,减去尾随空格。
|
Shape |
getVisualHighlightShape(TextHitInfo firstEndpoint, TextHitInfo secondEndpoint)
返回一个
Shape将视觉选择包围在指定的范围内,扩展到边界。
|
Shape |
getVisualHighlightShape(TextHitInfo firstEndpoint, TextHitInfo secondEndpoint, Rectangle2D bounds)
返回包含指定范围内的视觉选择的路径,扩展为
bounds 。
|
TextHitInfo |
getVisualOtherHit(TextHitInfo hit)
返回指定命中的插入符号对面的命中。
|
protected void |
handleJustify(float justificationWidth)
证明这个布局。
|
int |
hashCode()
返回此
TextLayout的哈希码。
|
TextHitInfo |
hitTestChar(float x, float y)
返回
TextHitInfo对应于指定点。
|
TextHitInfo |
hitTestChar(float x, float y, Rectangle2D bounds)
返回
TextHitInfo对应于指定点。
|
void |
hitToPoint(TextHitInfo hit, Point2D point)
将命中转换为标准坐标中的一个点。
|
boolean |
isLeftToRight()
返回
true如果这
TextLayout有一个左到右的基本方向或
false如果它有一个从右到左的基本方向。
|
boolean |
isVertical()
如果这个
TextLayout是垂直的,则返回
true 。
|
String |
toString()
返回此
TextLayout 。
|
public static final TextLayout.CaretPolicy DEFAULT_CARET_POLICY
CaretPolicy 。
有了这个策略,对方向与线方向相同的角色的打击比反向角色的命中强。
如果角色的方向相同,则角色前缘的命中要强于角色后缘的命中。
public TextLayout(String string, Font font, FontRenderContext frc)
string - 要显示的文字
font - a
Font用于样式文本
frc - 包含有关正确测量文本所需的图形设备信息。
文本测量可能会根据设备分辨率和抗锯齿等属性略有不同。
该参数不指定TextLayout与用户空间之间的TextLayout 。
public TextLayout(String string, Map<? extends AttributedCharacterIterator.Attribute,?> attributes, FontRenderContext frc)
TextLayout从String ,并设置一个属性。
所有文本都使用提供的属性进行风格化。
string必须指定一段文字,因为双向算法需要整个段落。
string - 要显示的文字
attributes - 用于对文本进行样式的属性
frc - 包含有关正确测量文本所需的图形设备的信息。
文本测量可能会根据设备分辨率和抗锯齿等属性略有不同。
该参数不指定TextLayout与用户空间之间的TextLayout 。
public TextLayout(AttributedCharacterIterator text, FontRenderContext frc)
TextLayout 。
迭代器必须指定单个文本段落,因为双向算法需要整个段落。
text - 要显示的样式文本
frc - 包含有关正确测量文本所需的图形设备的信息。
文本测量可能会根据设备分辨率和抗锯齿等属性略有不同。
该参数不指定TextLayout与用户空间之间的TextLayout 。
protected Object clone()
TextLayout的副本。
public TextLayout getJustifiedLayout(float justificationWidth)
TextLayout对齐到指定宽度的副本。
如果这个TextLayout已经被证明是正当的,就会抛出异常。 如果此TextLayout对象的调整率为零,一个TextLayout相同此TextLayout被返回。
justificationWidth - 当对齐线时使用的宽度。
为了获得最佳效果,它不应该与当前的进展情况有太大的不同。
TextLayout对齐到指定的宽度。
Error - 如果这个布局已经被证明是对的,那么会抛出一个错误。
protected void handleJustify(float justificationWidth)
一些代码可能依赖于不可更改的布局。 子类不应该直接调用它,而应该调用getJustifiedLayout,这将在此布局的克隆上调用此方法,保留原始。
justificationWidth - 调整justificationWidth使用的宽度。
为了获得最佳效果,它不应该与当前的进展情况有太大的不同。
getJustifiedLayout(float)
public byte getBaseline()
TextLayout的基准。
基线是Font中定义的值Font ,罗马,中心和悬挂。
上升和下降是相对于这个基线。
baselineOffsets也是相对于这个基线。
TextLayout 。
getBaselineOffsets() , Font
public float[] getBaselineOffsets()
TextLayout的基线的偏移数组。
该数组由Font中定义的值之一进行索引,这些值是罗马,中心和挂起。 这些值是相对于这个TextLayout对象的基线,所以getBaselineOffsets[getBaseline()] == 0 。 将偏移量添加到TextLayout对象的基线的位置,以获取新基线的位置。
TextLayout 。
getBaseline() , Font
public float getAdvance()
TextLayout 。
提前是从原始到最右边(最下方)字符前进的距离。
这是在基线相对坐标。
TextLayout 。
public float getVisibleAdvance()
TextLayout ,减去尾随空格。
这是在基线相对坐标。
TextLayout没有尾随的空格。
getAdvance()
public float getAscent()
TextLayout的上升。
上升是从TextLayout的顶部(右)到基线的距离。
它始终为正或零。
上升足以容纳上标的文本,并且是每个字形的上升,偏移和基线的总和的最大值。
上升是TextLayout中所有文本基线的最大上升。
它在基线相对坐标。
TextLayout的上升。
public float getDescent()
TextLayout的下降。
下降是从基线到TextLayout的底部(左)的TextLayout 。
它始终为正或零。
下降足以适应下标文本,并且是每个字形的下降,偏移和基线之和的最大值。
这是TextLayout中所有文本基线的最大下降。
它在基线相对坐标。
TextLayout的下降。
public float getLeading()
TextLayout的领先。
领先的是这个建议的行间距TextLayout 。
这是在基线相对坐标。
领先的是从领先的血统,并在所有字形向量的计算基准TextLayout 。 算法大致如下:
maxD = 0;
maxDL = 0;
for (GlyphVector g in all glyphvectors) {
maxD = max(maxD, g.getDescent() + offsets[g.getBaseline()]);
maxDL = max(maxDL, g.getDescent() + g.getLeading() +
offsets[g.getBaseline()]);
}
return maxDL - maxD;
TextLayout 。
public Rectangle2D getBounds()
TextLayout的范围。
边界是标准坐标。
由于光栅化效果,此边界可能不会包含TextLayout渲染的所有像素。
这可能与TextLayout的上升,下降,起源或进步TextLayout 。
Rectangle2D这是这个TextLayout的界限。
public Rectangle getPixelBounds(FontRenderContext frc, float x, float y)
FontRenderContext的图形中渲染时,返回此TextLayout的像素边界。
图形渲染方面不一定是一样的FontRenderContext用于创建此TextLayout ,并且可以为null。
如果为空,则FontRenderContext如此TextLayout使用。
frc -
FontRenderContext的
Graphics 。
x - 要呈现这个
TextLayout的x
TextLayout 。
y - 渲染这个
TextLayout的y
TextLayout 。
Rectangle限制将受影响的像素。
GlyphVector.getPixelBounds(java.awt.font.FontRenderContext, float, float)
public boolean isLeftToRight()
true如果这TextLayout有一个左到右的基本方向或false如果它有一个从右到左的基本方向。
TextLayout具有从左到右(LTR)或从右到左(RTL)的基本方向。
基本方向与线上文本的实际方向无关,可能是LTR,RTL或混合。
从左到右的布局默认情况下应该向左摆放。
如果布局在选项卡上,则选项卡从左到右运行,以便逻辑上连续的布局从左到右定位。
RTL布局也是如此。
默认情况下,它们应该向左定位,并且选项卡从左到右运行。
true如果这个TextLayout的基本方向是从左到右;
false否则。
public boolean isVertical()
TextLayout是垂直的,则返回
true 。
true如果这TextLayout是垂直的;
false另外。
public int getCharacterCount()
TextLayout 。
TextLayout 。
public float[] getCaretInfo(TextHitInfo hit, Rectangle2D bounds)
hit 。
数组的第一个元素是插入符号与基线的交集,作为基线的距离。
数组的第二个元素是相对于该点的基线测量的插入符号的反斜率(运行/上升)。
此方法用于信息使用。 要显示getCaretShapes ,最好使用getCaretShapes 。
hit - 这个
TextLayout一个角色的
TextLayout
bounds - bounds插入符号信息的界限。
边界在基线相对坐标。
getCaretShapes(int, Rectangle2D, TextLayout.CaretPolicy) ,
Font.getItalicAngle()
public float[] getCaretInfo(TextHitInfo hit)
hit 。
此方法是一个方便过载getCaretInfo ,并使用此的自然边界TextLayout 。
hit - 在这个
TextLayout一个字符的
TextLayout
public TextHitInfo getNextRightHit(TextHitInfo hit)
hit - 这个布局中一个角色的命中
null 。
public TextHitInfo getNextRightHit(int offset, TextLayout.CaretPolicy policy)
null 。
按照指定的策略确定,指定的偏移量处于右侧的强插销符号。
返回的命中是指定策略确定的两个可能命中之一。
offset - 在此TextLayout插入偏移量。
不能小于0或大于此TextLayout对象的字符数。
policy - 用于选择强
policy的策略
null 。
public TextHitInfo getNextRightHit(int offset)
null 。
按照默认策略确定的指定偏移量,右侧的强插头位于右侧。
返回的命中是由默认策略确定的两个可能的命中中更强的。
offset - 在这个TextLayout插入偏移量。
不能小于0或大于TextLayout对象的字符数。
null 。
public TextHitInfo getNextLeftHit(TextHitInfo hit)
null 。
如果命中字符索引超出范围,则抛出IllegalArgumentException 。
hit - 这个
TextLayout一个字符的
TextLayout 。
null 。
public TextHitInfo getNextLeftHit(int offset, TextLayout.CaretPolicy policy)
null 。
击打位于指定偏移处的强插销符号的左侧,由指定的策略确定。
返回的命中是指定策略确定的两个可能命中之一。
offset -一个插入在该偏移TextLayout 。
不能小于0或大于此TextLayout对象的字符数。
policy - 用于选择强
policy的策略
null 。
public TextHitInfo getNextLeftHit(int offset)
null 。
击打位于指定偏移量的强插销符号左侧,由默认策略确定。
返回的命中是由默认策略确定的两个可能的命中中更强的。
offset -一个插入在该偏移TextLayout 。
不能小于0或大于此TextLayout对象的字符数。
null 。
public TextHitInfo getVisualOtherHit(TextHitInfo hit)
hit - 指定的命中
public Shape getCaretShape(TextHitInfo hit, Rectangle2D bounds)
hit - 生成插入符号的命中
bounds - 用于生成插入符号的TextLayout的范围。
边界在基线相对坐标。
Shape代表插入符号。
返回的形状是标准坐标。
public Shape getCaretShape(TextHitInfo hit)
Shape代表在指定的打这个的自然边界中插入符号
TextLayout 。
hit - 生成插入符号的命中
Shape代表插入符号。
返回的形状是标准坐标。
public byte getCharacterLevel(int index)
index返回字符的index 。
指数-1和characterCount被分配了这个TextLayout的基准水平。
index - 从中获取级别的角色的索引
public Shape[] getCaretShapes(int offset, Rectangle2D bounds, TextLayout.CaretPolicy policy)
offset - 在这
TextLayout一个抵消
bounds - 扩展bounds的范围。
边界在基线相对坐标。
policy - 指定的
CaretPolicy
null 。
返回的形状是标准坐标。
public Shape[] getCaretShapes(int offset, Rectangle2D bounds)
getCaretShapes的方便超载。
offset - 这个
TextLayout一个抵消
bounds - 扩展bounds的范围。
这是在基线相对坐标。
DEFAULT_CARET_POLICY 。
这些是标准坐标。
public Shape[] getCaretShapes(int offset)
getCaretShapes使用默认插入符策略和此TextLayout对象的自然边界。
offset - 在这
TextLayout一个抵消
DEFAULT_CARET_POLICY 。
这些是标准坐标。
public int[] getLogicalRangesForVisualSelection(TextHitInfo firstEndpoint, TextHitInfo secondEndpoint)
firstEndpoint - 视觉范围的终点
secondEndpoint - 视觉范围的另一端点。
该端点可以小于firstEndpoint 。
getVisualHighlightShape(TextHitInfo, TextHitInfo, Rectangle2D)
public Shape getVisualHighlightShape(TextHitInfo firstEndpoint, TextHitInfo secondEndpoint, Rectangle2D bounds)
bounds 。
如果选择包括最左边的(最上面的)位置时,该选择被扩展到的左侧(顶部) bounds 。 如果选择包括最右边(最下)位置,则选择将扩展到边界的右侧(底部)。 选择的高度(垂直线宽度)始终扩展为bounds 。
虽然选择始终是连续的,但逻辑选择的文本在具有混合方向文本的行上可能是不连续的。 可以使用getLogicalRangesForVisualSelection所选文本的逻辑范围。 例如,考虑文本“ABCdef”,大写字母表示从右到左的文本,从右到左的行显示,从0L的视觉选择(“A”的前沿)到3T(尾随'd'的边缘)。 文本显示如下,粗体下划线区域表示选择:
defCBA
逻辑选择范围为0-3,4-6(ABC,ef),因为视觉上连续的文本在逻辑上是不连续的。
还要注意的是,由于布局上的最右边的位置(在'A'的右边)被选中,所以选择被扩展到边界的右边。
firstEndpoint - 视觉选择的一端
secondEndpoint - 视觉选择的另一端
bounds - 扩展选择的边界矩形。
这是在基线相对坐标。
Shape封闭选择。
这是在标准坐标。
getLogicalRangesForVisualSelection(TextHitInfo, TextHitInfo) ,
getLogicalHighlightShape(int, int, Rectangle2D)
public Shape getVisualHighlightShape(TextHitInfo firstEndpoint, TextHitInfo secondEndpoint)
Shape在指定范围内的视觉选择的Shape,扩展到边界。
此方法是一个方便过载getVisualHighlightShape使用此的自然边界TextLayout 。
firstEndpoint - 视觉选择的一端
secondEndpoint - 视觉选择的另一端
Shape封闭选择。
这是在标准坐标。
public Shape getLogicalHighlightShape(int firstEndpoint, int secondEndpoint, Rectangle2D bounds)
Shape将逻辑选择包含在指定的范围内,扩展到指定的bounds 。
如果选择范围包括所述第一逻辑字符,则选择被扩展到的所述部分bounds此开始前TextLayout 。 如果该范围包括最后的逻辑字符,选择被扩展到的所述部分bounds此结束后TextLayout 。 选择的高度(垂直线上的宽度)始终扩展为bounds 。
在具有混合方向文本的行上,选择可以是不连续的。 只有开始和关闭之间逻辑范围内的这些字符才会显示出来。 例如,考虑文本“ABCdef”,其中大写字母表示从右到左的文本,以从右到左的行显示,逻辑选择从0到4(“ABCd”)。 文字显示如下,粗体字用于选择,下划线为扩展名:
defCBA
选择是不连续的,因为所选择的字符在视觉上是不连续的。
还要注意的是,由于该范围包括所述第一逻辑字符(A),选择被扩展到的所述部分bounds的布局,这在这种情况下(右到左线)的右侧部分的开始前bounds 。
firstEndpoint - 要选择的字符范围内的端点
secondEndpoint - 要选择的其他端点的字符范围。
可以低于firstEndpoint 。
范围包括min(firstEndpoint,secondEndpoint)的字符,但不包括max(firstEndpoint,secondEndpoint)。
bounds - 用于扩展选择的边界矩形。
这是在基线相对坐标。
getVisualHighlightShape(TextHitInfo, TextHitInfo, Rectangle2D)
public Shape getLogicalHighlightShape(int firstEndpoint, int secondEndpoint)
Shape将逻辑选择包含在指定范围内,扩展到此TextLayout 。
此方法是一个方便过载getLogicalHighlightShape使用此的自然边界TextLayout 。
firstEndpoint - 要选择的字符范围内的端点
secondEndpoint - 要选择的字符范围的另一个端点。
可以少于firstEndpoint 。
范围包括min(firstEndpoint,secondEndpoint)的字符,但不包括max(firstEndpoint,secondEndpoint)。
Shape封闭选择。
这是在标准坐标。
public Shape getBlackBoxBounds(int firstEndpoint, int secondEndpoint)
firstEndpoint - 字符范围的一端
secondEndpoint - 另一端的字符范围。
可以小于firstEndpoint 。
Shape封闭黑盒边界。
这是在标准坐标。
public TextHitInfo hitTestChar(float x, float y, Rectangle2D bounds)
TextHitInfo对应于指定点。
在TextLayout映射的范围之外的TextLayout地在第一个逻辑字符的前沿或最后一个逻辑字符的后沿,而不管该字符在行中的位置。
只有沿着基准线的方向才被用来做这个评估。
x - 从这个TextLayout的起点的x偏移。
这是在标准坐标。
y - 从这个TextLayout的起点的y偏移。
这是在标准坐标。
bounds -的的界限TextLayout 。
这是在基线相对坐标。
public TextHitInfo hitTestChar(float x, float y)
TextHitInfo对应于指定点。
此方法是一个方便过载hitTestChar使用此的自然边界TextLayout 。
x - 从这个TextLayout的起点的x偏移。
这是在标准坐标。
y - 从这个TextLayout的起点的y偏移。
这是在标准坐标。
public int hashCode()
TextLayout的哈希码。
hashCode在
Object类
TextLayout的哈希码。
Object.equals(java.lang.Object) ,
System.identityHashCode(java.lang.Object)
public boolean equals(Object obj)
true如果指定的
Object是
TextLayout对象,如果指定的
Object等于这个
TextLayout 。
equals在
Object类
obj - 一个
Object以测试平等
true如果指定的Object等于这个TextLayout ;
false否则。
Object.hashCode() , HashMap
public boolean equals(TextLayout rhs)
true 。
如果两个布局以相同的顺序包含相等的符号,则两个布局相等。
rhs -
TextLayout与此
TextLayout进行比较
true如果指定的
TextLayout等于这个
TextLayout 。
public String toString()
TextLayout 。
public void draw(Graphics2D g2, float x, float y)
g2 - 要渲染布局的
Graphics2D上下文
x - 这个TextLayout的原点的X
TextLayout
y - 这个TextLayout的起点的Y
TextLayout
getBounds()
public Shape getOutline(AffineTransform tx)
Shape TextLayout的大纲的
TextLayout 。
tx - 一个可选的AffineTransform适用于这个TextLayout的大纲。
Shape是这个TextLayout的大纲。
这是在标准坐标。
public LayoutPath getLayoutPath()
public void hitToPoint(TextHitInfo hit, Point2D point)
hit - 打击检查。
这必须是TextLayout上的有效命中。
point - 返回点。
点在标准坐标。
IllegalArgumentException - 如果命中对TextLayout无效。
NullPointerException - 如果命中或点为空。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.