Class CellContentDrawer

java.lang.Object
org.ofdrw.layout.element.canvas.CellContentDrawer
All Implemented Interfaces:
Drawer

public class CellContentDrawer extends Object implements Drawer
类单元格特殊Canvas 绘制器

可以实现类似于单元个效果,用于简化区域占位区块绘制。

Since:
2023-11-13 18:48:53
Author:
权观宇
  • Field Details

    • DEBUG

      public static Boolean DEBUG
      调试开关,在开启后会绘制辅助线
  • Constructor Details

    • CellContentDrawer

      public CellContentDrawer(Canvas canvas)
      通过已有Canvas构造单元格

      注意该方法将会替换Canvas的绘制器为单元格的绘制器。

      Parameters:
      canvas - Canvas
    • CellContentDrawer

      public CellContentDrawer(double x, double y, double width, double height)
      创建单元格
      Parameters:
      x - 左下角x坐标
      y - 左下角y坐标
      width - 宽度
      height - 高度
  • Method Details

    • draw

      public void draw(DrawContext ctx) throws IOException
      单元格内部绘制
      Specified by:
      draw in interface Drawer
      Parameters:
      ctx - 绘制上下文
      Throws:
      IOException - 图形绘制异常
    • getValue

      public String getValue()
      获取单元格文字内容
      Returns:
      单元格文字内容
    • setValue

      public CellContentDrawer setValue(String value)
      设置单元格文字内容
      Parameters:
      value - 单元格文字内容
      Returns:
      this
    • setValue

      public CellContentDrawer setValue(Path imgPath, double w, double h)
      设置图片
      Parameters:
      imgPath - 图片路径,仅支持png、jpg、jpeg、gif、bmp格式
      w - 图片宽度,单位:毫米
      h - 图片高度,单位:毫米
      Returns:
      this
    • setValue

      public CellContentDrawer setValue(Path imgPath) throws IOException
      设置图片

      图片宽度与高度通过 DrawContext.mm(int) } 方法转换为毫米

      Parameters:
      imgPath - 图片路径,仅支持png、jpg、jpeg、gif、bmp格式
      Returns:
      this
      Throws:
      IOException - 图片加载异常
    • getColor

      public String getColor()
      获取单元格颜色
      Returns:
      单元格颜色,格式:#000000、rgb(0,0,0)、rgba(0,0,0,1)
    • setColor

      public CellContentDrawer setColor(String color)
      设置单元格颜色
      Parameters:
      color - 单元格颜色,格式:#000000、rgb(0,0,0)、rgba(0,0,0,1)
      Returns:
      this
    • getFontName

      public String getFontName()
      获取字体名称
      Returns:
      字体名称
    • setFontName

      public CellContentDrawer setFontName(String fontName)
      设置字体名称
      Parameters:
      fontName - 字体名称,仅支持系统安装字体,且不会嵌入到OFD中。
      Returns:
      this
    • getFontSize

      public double getFontSize()
      获取字号
      Returns:
      字号,默认:0.353 (单位:毫米)
    • setFontSize

      public CellContentDrawer setFontSize(double fontSize)
      设置字号
      Parameters:
      fontSize - 字号,默认:3(单位:毫米)
      Returns:
      this
    • getCanvas

      public Canvas getCanvas()
      获取单元格的Canvas对象
      Returns:
      单元格的Canvas对象
    • getTextAlign

      public TextAlign getTextAlign()
      获取 文字对齐方式
      Returns:
      文字对齐方式,默认:左对齐
    • setTextAlign

      public CellContentDrawer setTextAlign(TextAlign textAlign)
      设置 文字对齐方式
      Parameters:
      textAlign - 文字对齐方式
      Returns:
      this
    • getVerticalAlign

      public VerticalAlign getVerticalAlign()
      获取 文字垂直方向浮动方式
      Returns:
      文字垂直方向浮动方式,默认:居中 VerticalAlign.center
    • setVerticalAlign

      public CellContentDrawer setVerticalAlign(VerticalAlign verticalAlign)
      设置 文字垂直方向浮动方式
      Parameters:
      verticalAlign - 文字垂直方向浮动方式
      Returns:
      this
    • getLineSpace

      public Double getLineSpace()
      获取 行间距
      Returns:
      行间距,默认值 0.6mm
    • setLineSpace

      public CellContentDrawer setLineSpace(Double lineSpace)
      设置 行间距
      Parameters:
      lineSpace - 行间距
      Returns:
      this
    • getBlob

      @Deprecated public Boolean getBlob()
      Deprecated.
      单词错误 getBold() 是否加粗
      Returns:
      是否加粗,默认:不加粗
    • setBlob

      @Deprecated public CellContentDrawer setBlob(Boolean bolb)
      Deprecated.
      单词错误 setBold(Boolean)

      设置 是否加粗

      Parameters:
      bolb - 是否加粗
      Returns:
      this
    • getBold

      public Boolean getBold()
      是否加粗
      Returns:
      是否加粗,默认:不加粗
    • setBold

      public CellContentDrawer setBold(Boolean bold)
      设置 是否加粗
      Parameters:
      bold - 是否加粗
      Returns:
      this
    • getItalic

      public Boolean getItalic()
      是否斜体
      Returns:
      true - 斜体、false - 正常
    • setItalic

      public CellContentDrawer setItalic(Boolean italic)
      设置 是否斜体
      Parameters:
      italic - 是否斜体,true - 斜体、false - 正常
      Returns:
      this
    • getLetterSpacing

      public Double getLetterSpacing()
      获取 文字之间的间距
      Returns:
      文字之间的间距,默认为:0
    • setLetterSpacing

      public CellContentDrawer setLetterSpacing(Double letterSpacing)
      设置 文字之间的间距
      Parameters:
      letterSpacing - 文字之间的间距,可以为负数,默认为:0。
      Returns:
      this
    • getImgPath

      public Path getImgPath()
      获取图片路径
      Returns:
      图片路径,可能为空。
    • getImgWidth

      public double getImgWidth()
      获取图片高度
      Returns:
      图片高度,可能为0。
    • getImgHeight

      public double getImgHeight()
      获取图片宽度
      Returns:
      图片宽度,可能为0。
    • setUnderline

      public CellContentDrawer setUnderline(boolean underline)
      设置是否开启下划线
      Parameters:
      underline - true - 启下划线,false - 禁用下划线
      Returns:
      this
    • getUnderline

      public boolean getUnderline()
      获取是否开启下划线
      Returns:
      true - 启下划线,false - 不启用下划线
    • setDeleteLine

      public CellContentDrawer setDeleteLine(boolean deleteLine)
      设置是否开启删除线
      Parameters:
      deleteLine - true - 启删除线,false - 禁用删除线
      Returns:
      this
    • getDeleteLine

      public boolean getDeleteLine()
      获取是否开启删除线
      Returns:
      true - 启删除线,false - 禁用删除线
    • getFontWeight

      public String getFontWeight()
      获取字体宽度
      Returns:
      字体宽度,遵循 CSS3标准,可选值为 normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
    • setFontWeight

      public void setFontWeight(String fontWeight)
      设置字体宽度
      Parameters:
      fontWeight - 字体宽度,应遵循 CSS3标准,可选值为 normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
    • setFont

      public CellContentDrawer setFont(String fontName, Path fontPath)
      设置单元格绘制器使用的外部字体

      注意OFDRW不会提供任何字体裁剪功能,您的字体文件将直接加入OFD文件中,这可能造成文件体积剧增。

      Parameters:
      fontName - 字体名称,如“思源宋体”
      fontPath - 字体文件所在路径
      Returns:
      this