public class Span extends Object implements TextFontInfo
用来设置字体样式等
| Modifier | Constructor and Description |
|---|---|
protected |
Span() |
|
Span(Font font,
Double fontSize,
String text) |
|
Span(String text) |
| Modifier and Type | Method and Description |
|---|---|
Rectangle |
blockSize() |
Span |
clone() |
int[] |
getColor() |
Double[] |
getDeltaX()
获取字符X坐标偏移值队列
|
Font |
getFont()
获取字体对象
|
Double |
getFontSize()
获取文字字号
|
Double |
getLetterSpacing()
获取字间距
|
String |
getText() |
double |
getUnderlineOffset()
获取下划线与文字的偏移量
|
double |
getUnderlineWidth()
获取下划线宽度
|
org.ofdrw.core.text.text.Weight |
getWeight()
获取字体粗细
|
List<TxtGlyph> |
glyphList()
获取字体图形列表
|
boolean |
hasLinebreak()
是否是一个占满剩余行空间的Span
|
boolean |
isBold() |
Boolean |
isFill() |
Boolean |
isIntegrity()
元素是否可以拆分
|
boolean |
isItalic() |
boolean |
isUnderline() |
int |
length() |
Span |
setBold(boolean bold)
设置是否加粗
|
Span |
setColor(int[] rgb)
设置字体颜色
|
Span |
setColor(int r,
int g,
int b)
设置字体颜色
|
Span |
setColor(String color)
设置 文字颜色
|
Span |
setFill(boolean fill) |
Span |
setFont(Font font) |
Span |
setFontSize(Double fontSize) |
Span |
setIntegrity(Boolean integrity) |
Span |
setItalic(boolean italic) |
Span |
setLetterSpacing(Double letterSpacing) |
Span |
setLinebreak(boolean linebreak)
设置Span为占满剩下行空间的元素
|
Span |
setText(String text) |
Span |
setUnderline(boolean underline)
设置 下划线
|
Span |
setUnderline(boolean underline,
double offset,
double width)
设置下划线
|
Span |
setWeight(org.ofdrw.core.text.text.Weight weight)
设置字体粗细
|
Span[] |
split(int index)
切分元素
|
LinkedList<Span> |
splitLineBreak()
获取经过行内换行处理之后的Span列表
|
protected Span()
public Span(String text)
public int[] getColor()
public Span setColor(int[] rgb)
rgb - 颜色值public Span setColor(String color)
color - 颜色值,可以是 16进制值 "#FFFFFF"、 16进制值缩写 "#FF"F、RGB "rgb(255,255,255)"、颜色名称 "white"public Span setColor(int r, int g, int b)
r - 红g - 绿b - 懒public int length()
public Font getFont()
TextFontInfogetFont in interface TextFontInfopublic Double getFontSize()
TextFontInfogetFontSize in interface TextFontInfopublic Double getLetterSpacing()
TextFontInfogetLetterSpacing in interface TextFontInfopublic boolean isBold()
public Span setBold(boolean bold)
若需要更加细致的控制,可以使用 setWeight(Weight)
bold - 是否加粗public org.ofdrw.core.text.text.Weight getWeight()
public Span setWeight(org.ofdrw.core.text.text.Weight weight)
weight - 字体粗细public boolean isItalic()
public Span setItalic(boolean italic)
public boolean isUnderline()
public Span setUnderline(boolean underline)
underline - 是否启用下划线public Span setUnderline(boolean underline, double offset, double width)
underline - 是否启用下划线offset - 下划线与文字的偏移量,可以为负值,默认值为1.2,单位毫米。width - 下划线线宽,默认为0,为0时默认为字体大小的0.05倍。public Boolean isFill()
public Span setFill(boolean fill)
public String getText()
public Boolean isIntegrity()
特殊的: 如果没有或只有一个文字,那么无论如何设置integrity都为不可拆分
public Double[] getDeltaX()
队列中的每个值代表后一个文字与前一个文字之间在X方向上的偏移值
public Rectangle blockSize()
public Span[] split(int index)
index - 字符坐标public Span setLinebreak(boolean linebreak)
等价于在字符串末尾增加\n,当字符串末尾存在\n 时该参数无效。
linebreak - 是否占满剩下行空间 true 标识占满;false标识不占满public boolean hasLinebreak()
public LinkedList<Span> splitLineBreak()
public double getUnderlineOffset()
public double getUnderlineWidth()
Copyright © 2026. All rights reserved.