Class Span

java.lang.Object
org.ofdrw.layout.element.Span
All Implemented Interfaces:
TextFontInfo
Direct Known Subclasses:
PlaceholderSpan

public class Span extends Object implements TextFontInfo
字体基础单元

用来设置字体样式等

Since:
2020-02-03 02:01:53
Author:
权观宇
  • Constructor Details

    • Span

      protected Span()
    • Span

      public Span(Font font, Double fontSize, String text)
    • Span

      public Span(String text)
  • Method Details

    • getColor

      public int[] getColor()
    • setColor

      public Span setColor(int[] rgb)
      设置字体颜色
      Parameters:
      rgb - 颜色值
      Returns:
      this
    • setColor

      public Span setColor(String color)
      设置 文字颜色
      Parameters:
      color - 颜色值,可以是 16进制值 "#FFFFFF"、 16进制值缩写 "#FF"F、RGB "rgb(255,255,255)"、颜色名称 "white"
      Returns:
      this
    • setColor

      public Span setColor(int r, int g, int b)
      设置字体颜色
      Parameters:
      r - 红
      g - 绿
      b - 懒
      Returns:
      this
    • length

      public int length()
      Returns:
      字符数量
    • getFont

      public Font getFont()
      Description copied from interface: TextFontInfo
      获取字体对象
      Specified by:
      getFont in interface TextFontInfo
      Returns:
      字体对象
    • setFont

      public Span setFont(Font font)
    • getFontSize

      public Double getFontSize()
      Description copied from interface: TextFontInfo
      获取文字字号
      Specified by:
      getFontSize in interface TextFontInfo
      Returns:
      字号,单位毫米mm
    • setFontSize

      public Span setFontSize(Double fontSize)
    • getLetterSpacing

      public Double getLetterSpacing()
      Description copied from interface: TextFontInfo
      获取字间距
      Specified by:
      getLetterSpacing in interface TextFontInfo
      Returns:
      字间距,单位毫米mm
    • setLetterSpacing

      public Span setLetterSpacing(Double letterSpacing)
    • isBold

      public boolean isBold()
    • setBold

      public Span setBold(boolean bold)
      设置是否加粗

      若需要更加细致的控制,可以使用 setWeight(Weight)

      Parameters:
      bold - 是否加粗
      Returns:
      this
    • getWeight

      public org.ofdrw.core.text.text.Weight getWeight()
      获取字体粗细
      Returns:
      字体粗细,可能为null。
    • setWeight

      public Span setWeight(org.ofdrw.core.text.text.Weight weight)
      设置字体粗细
      Parameters:
      weight - 字体粗细
      Returns:
      this
    • isItalic

      public boolean isItalic()
    • setItalic

      public Span setItalic(boolean italic)
    • isUnderline

      public boolean isUnderline()
    • setUnderline

      public Span setUnderline(boolean underline)
      设置 下划线
      Parameters:
      underline - 是否启用下划线
      Returns:
      this
    • setUnderline

      public Span setUnderline(boolean underline, double offset, double width)
      设置下划线
      Parameters:
      underline - 是否启用下划线
      offset - 下划线与文字的偏移量,可以为负值,默认值为1.2,单位毫米。
      width - 下划线线宽,默认为0,为0时默认为字体大小的0.05倍。
      Returns:
      this
    • isFill

      public Boolean isFill()
    • setFill

      public Span setFill(boolean fill)
    • getText

      public String getText()
    • setText

      public Span setText(String text)
    • isIntegrity

      public Boolean isIntegrity()
      元素是否可以拆分

      特殊的: 如果没有或只有一个文字,那么无论如何设置integrity都为不可拆分

      Returns:
      true 可以拆分;false 不能拆分
    • setIntegrity

      public Span setIntegrity(Boolean integrity)
    • glyphList

      public List<TxtGlyph> glyphList()
      获取字体图形列表
      Returns:
      字体图形列表
    • getDeltaX

      public Double[] getDeltaX()
      获取字符X坐标偏移值队列

      队列中的每个值代表后一个文字与前一个文字之间在X方向上的偏移值

      Returns:
      字符在X坐标偏移值队列
    • blockSize

      public Rectangle blockSize()
      Returns:
      不拆分情况下都放在一行内占用的大小
    • split

      public Span[] split(int index)
      切分元素
      Parameters:
      index - 字符坐标
      Returns:
      切分后的两个全新元素
    • setLinebreak

      public Span setLinebreak(boolean linebreak)
      设置Span为占满剩下行空间的元素

      等价于在字符串末尾增加\n,当字符串末尾存在\n 时该参数无效。

      Parameters:
      linebreak - 是否占满剩下行空间 true 标识占满;false标识不占满
      Returns:
      this
    • hasLinebreak

      public boolean hasLinebreak()
      是否是一个占满剩余行空间的Span
      Returns:
      true 标识span会占满剩余的行空间; false 不占满
    • splitLineBreak

      public LinkedList<Span> splitLineBreak()
      获取经过行内换行处理之后的Span列表
      Returns:
      带有占满行剩余内容的Span序列
    • getUnderlineOffset

      public double getUnderlineOffset()
      获取下划线与文字的偏移量
      Returns:
      下划线与文字的偏移量,单位毫米
    • getUnderlineWidth

      public double getUnderlineWidth()
      获取下划线宽度
      Returns:
      下划线宽度, 0表示保持默认,默认为字体大小的0.05倍,单位毫米
    • clone

      public Span clone()
      Overrides:
      clone in class Object