Class OFDPageGraphics2D
在 PageGraphics2D 中所有接口参数单位均为 毫米(mm)。
- Since:
- 2023-01-18 10:07:52
- Author:
- 权观宇
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionaddImageResource(BufferedImage image) 把位图登记为文档图片资源voidaddRenderingHints(Map<?, ?> hints) 添加绘制器参数(为了兼容接口,无实际用途)voidappendPageBlock(PageBlockType block) 在当前页面内容容器(CT_PageBlock)尾部追加一个页块对象voidclearRect(int x, int y, int width, int height) 使用背景色填充矩形区域void设置裁剪区域voidclipRect(int x, int y, int width, int height) 设置矩形裁剪区域voidcopyArea(int x, int y, int width, int height, int dx, int dy) 复制矩形区域create()复制当前绘制上下文为新的上下文voiddispose()销毁绘制上下文void绘制图形voiddrawArc(int x, int y, int width, int height, int startAngle, int arcAngle) 在矩形区域内绘制圆弧voiddrawGlyphVector(GlyphVector g, float x, float y) 在指定位置上绘制绘制图形路径数据,voiddrawImage(BufferedImage img, BufferedImageOp op, int x, int y) 在画布指定位置绘制图像,在绘制前将会使用BufferedImageOp过滤图像booleandrawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) 绘制图片内某个矩形区域 到 画布的某个指定矩形区域booleandrawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) 绘制图片内某个矩形区域 到 画布的某个指定矩形区域,图片将会缩放适应目标区域booleandrawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) 在指定矩形区域内绘制图片booleandrawImage(Image img, int x, int y, int width, int height, ImageObserver observer) 将图片绘制于指定矩形区域内booleandrawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) 在指定位置绘制图片booleandrawImage(Image img, int x, int y, ImageObserver observer) 在指定坐标位置上绘制图片booleandrawImage(Image img, AffineTransform xform, ImageObserver obs) 通过变换矩阵在指定位置绘制图像voiddrawLine(int x1, int y1, int x2, int y2) 画线voiddrawOval(int x, int y, int width, int height) 使用当前颜色在矩形区域内描边椭圆形voiddrawPolygon(int[] xPoints, int[] yPoints, int nPoints) 使用当前颜色和描边属性描边多边形voiddrawPolyline(int[] xPoints, int[] yPoints, int nPoints) 绘制折线voiddrawRect(int x, int y, int width, int height) 描边矩形voiddrawRenderableImage(RenderableImage img, AffineTransform xform) 通过变换矩阵在指定位置绘制图像voiddrawRenderedImage(RenderedImage img, AffineTransform xform) 通过变换矩阵在指定位置绘制图像voiddrawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) 绘制圆角矩形voiddrawString(String str, float x, float y) 使用当前的 字体(Font) 以及 画笔参数(Paint) 在指定位置上绘制文字voiddrawString(String str, int x, int y) 使用当前的 字体(Font) 以及 画笔参数(Paint) 在指定位置上绘制文字voiddrawString(AttributedCharacterIterator iterator, float x, float y) 使用迭代器绘制文字图形voiddrawString(AttributedCharacterIterator iterator, int x, int y) 使用迭代器绘制文字图形void填充图形voidfillArc(int x, int y, int width, int height, int startAngle, int arcAngle) 在矩形区域内填充扇形voidfillOval(int x, int y, int width, int height) 使用当前颜色在矩形区域内填充椭圆形voidfillPolygon(int[] xPoints, int[] yPoints, int nPoints) 使用当前颜色填充多边形voidfillRect(int x, int y, int width, int height) 填充矩形区域voidfillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) 填充圆角矩形获取背景颜色getClip()获取裁剪区域获取裁剪区域的外接矩形大小getColor()返回前景色获取像素合成模式获取设备图形配置对象取得当前页所属文档对象getFont()获取当前字体获取特定字体的字体规格获取绘制上下文中的字体绘制上下文取得当前页所属的文档工作目录getPaint()获取绘制参数getRenderingHint(RenderingHints.Key hintKey) 获取绘制器参数值(为了兼容接口,无实际用途)获取当前绘制器参数信息(为了兼容接口,无实际用途)获取描边属性返回当前的变换矩阵boolean检查在设备空间内容 指定的矩形区域是否与 指定形状存在交集。生成页面所在文档内的新对象 IDvoidrotate(double theta) 绕原点旋转画布voidrotate(double theta, double x, double y) 绕指定点旋转画布voidscale(double sx, double sy) 坐标缩放voidsetBackground(Color color) 设置背景颜色voidsetClip(int x, int y, int width, int height) 设置矩形裁剪区域void设置裁剪区域void设置前景色voidsetComposite(Composite comp) 设置像素合成模式void设置绘图上下文的字体void设置绘制参数voidsetPaintMode 不实现voidsetRenderingHint(RenderingHints.Key hintKey, Object hintValue) 设置绘制器参数voidsetRenderingHints(Map<?, ?> hints) 替换绘制器参数(为了兼容接口,无实际用途)void设置描边属性void设置变换矩阵voidsetXORMode(Color c1) setXORMode 不实现voidshear(double shx, double shy) 切变trans(AffineTransform tx) 转为AWT变换矩阵AffineTransform为 OFD 类型变换矩阵ST_Arrayvoid图形变换voidtranslate(double tx, double ty) 平移原点voidtranslate(int x, int y) 平移原点坐标Methods inherited from class Graphics2D
draw3DRect, fill3DRectMethods inherited from class Graphics
create, drawBytes, drawChars, drawPolygon, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toString
-
Field Details
-
pageID
页面在页树中的对象ID
-
-
Method Details
-
draw
-
drawString
使用当前的 字体(Font) 以及 画笔参数(Paint) 在指定位置上绘制文字文字将转换为图形路径绘制填充在OFD页面上
第一个文字的基线坐标为传入的(x,y)参数位置。
文字绘制的将被裁剪矩阵(clip)、变换矩阵影响。
- Specified by:
drawStringin classGraphics2D- Parameters:
str- 待绘制文字序列x- 首个文字基线X坐标y- 首个文字基线Y坐标
-
drawString
使用当前的 字体(Font) 以及 画笔参数(Paint) 在指定位置上绘制文字文字将转换为图形路径绘制填充在OFD页面上
第一个文字的基线坐标为传入的(x,y)参数位置。
文字绘制的将被裁剪矩阵(clip)、变换矩阵影响。
- Specified by:
drawStringin classGraphics2D- Parameters:
str- 待绘制文字序列x- 首个文字基线X坐标y- 首个文字基线Y坐标
-
drawString
使用迭代器绘制文字图形文字图形的绘制将绘制将受到画笔参数(Paint) 、被裁剪矩阵(clip)、变换矩阵影响(CTM)。
第一个文字图形的基线坐标为传入的(x,y)参数位置。
- Specified by:
drawStringin classGraphics2D- Parameters:
iterator- 待绘制文本的迭代器x- 首个文字基线X坐标y- 首个文字基线Y坐标
-
drawString
使用迭代器绘制文字图形文字图形的绘制将绘制将受到画笔参数(Paint) 、被裁剪矩阵(clip)、变换矩阵影响(CTM)。
第一个文字图形的基线坐标为传入的(x,y)参数位置。
- Specified by:
drawStringin classGraphics2D- Parameters:
iterator- 待绘制文本的迭代器x- 首个文字基线X坐标y- 首个文字基线Y坐标
-
drawGlyphVector
在指定位置上绘制绘制图形路径数据,图形的绘制将绘制将受到画笔参数(Paint) 、被裁剪矩阵(clip)、变换矩阵影响(CTM)。
第一个文字的基线坐标为传入的(x,y)参数位置。
- Specified by:
drawGlyphVectorin classGraphics2D- Parameters:
g- 路径向量数据x- 图形绘制位置X坐标y- 图形绘制位置Y坐标
-
drawImage
在指定坐标位置上绘制图片绘制的图片大小为图元原始大小
-
drawImage
将图片绘制于指定矩形区域内 -
drawImage
在指定位置绘制图片图片保持原有大小,图片的透明部分将会使用指定颜色填充
-
drawImage
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) 在指定矩形区域内绘制图片图片将伸缩至矩形区域大小,图片的透明部分将会使用指定颜色填充
-
drawImage
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) 绘制图片内某个矩形区域 到 画布的某个指定矩形区域,图片将会缩放适应目标区域- Specified by:
drawImagein classGraphics- Parameters:
img- 待绘制图片dx1- 画布内 矩形左上角 X坐标(目的坐标)dy1- 画布内 矩形左上角 Y坐标(目的坐标)dx2- 画布内 矩形右下角 X坐标(目的坐标)dy2- 画布内 矩形右下角 Y坐标(目的坐标)sx1- 图片内 矩形左上角 X坐标(源坐标)sy1- 图片内 矩形左上角 Y坐标(源坐标)sx2- 图片内 矩形右下角 X坐标(源坐标)sy2- 图片内 矩形右下角 Y坐标(源坐标)observer- 忽略- Returns:
- 固定值 true
-
drawImage
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) 绘制图片内某个矩形区域 到 画布的某个指定矩形区域图片将会缩放适应目标区域,图片的透明部分将会使用指定颜色填充
- Specified by:
drawImagein classGraphics- Parameters:
img- 待绘制图片dx1- 画布内 矩形左上角 X坐标(目的坐标)dy1- 画布内 矩形左上角 Y坐标(目的坐标)dx2- 画布内 矩形右下角 X坐标(目的坐标)dy2- 画布内 矩形右下角 Y坐标(目的坐标)sx1- 图片内 矩形左上角 X坐标(源坐标)sy1- 图片内 矩形左上角 Y坐标(源坐标)sx2- 图片内 矩形右下角 X坐标(源坐标)sy2- 图片内 矩形右下角 Y坐标(源坐标)bgcolor- 背景颜色,用于填充透明部分observer- 忽略- Returns:
- 固定值 true
-
drawImage
通过变换矩阵在指定位置绘制图像- Specified by:
drawImagein classGraphics2D- Parameters:
img- 待绘制的图像(可渲染图像接口)xform- 变换矩阵,指定图像绘制方式obs- 忽略- Returns:
- true
-
drawImage
在画布指定位置绘制图像,在绘制前将会使用BufferedImageOp过滤图像等价于
img1 = op.filter(img, null); drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);- Specified by:
drawImagein classGraphics2D- Parameters:
img- 待绘制图像op- 图片渲染前的过滤器x- 图片左上角X坐标y- 图片左上角Y坐标
-
drawRenderedImage
通过变换矩阵在指定位置绘制图像- Specified by:
drawRenderedImagein classGraphics2D- Parameters:
img- 待绘制的图像(可渲染图像接口)xform- 变换矩阵,指定图像绘制方式
-
drawRenderableImage
通过变换矩阵在指定位置绘制图像- Specified by:
drawRenderableImagein classGraphics2D- Parameters:
img- 待绘制的图像(可渲染图像接口)xform- 变换矩阵,指定图像绘制方式
-
fill
-
hit
检查在设备空间内容 指定的矩形区域是否与 指定形状存在交集。onStroke 为false,表示检查指定形状整体是否与指定矩形相交。
onStroke 为true,表示检查指定形状的描边整体是否与指定矩形相交。
- Specified by:
hitin classGraphics2D- Parameters:
rect- 矩形区域s- 待检查的图形形状onStroke- 相交检查方式,true - 描边区域是否相交; false - 整个形状是否相交- Returns:
- true - 相交;false - 不相交
-
getDeviceConfiguration
获取设备图形配置对象- Specified by:
getDeviceConfigurationin classGraphics2D- Returns:
- OFD页面虚拟图形配置对象
-
setComposite
设置像素合成模式该方法原用于在设备绘制图像时,当前绘制的像素与原位置上已经存在的像素颜色的合成方式。 OFD中没有对应的合成效果,仅做兼容性实现。
- Specified by:
setCompositein classGraphics2D- Parameters:
comp- 合成方式
-
setPaint
设置绘制参数- Specified by:
setPaintin classGraphics2D- Parameters:
paint- 设置画笔颜色,用于填充和描边
-
setStroke
设置描边属性- Specified by:
setStrokein classGraphics2D- Parameters:
s- 描边属性参数
-
setRenderingHint
设置绘制器参数- Specified by:
setRenderingHintin classGraphics2D- Parameters:
hintKey- 参数名hintValue- 参数值
-
getRenderingHint
获取绘制器参数值(为了兼容接口,无实际用途)- Specified by:
getRenderingHintin classGraphics2D- Parameters:
hintKey- 参数名- Returns:
- 可能为空
-
setRenderingHints
替换绘制器参数(为了兼容接口,无实际用途)- Specified by:
setRenderingHintsin classGraphics2D- Parameters:
hints- 新参数
-
addRenderingHints
添加绘制器参数(为了兼容接口,无实际用途)- Specified by:
addRenderingHintsin classGraphics2D- Parameters:
hints- 键值对
-
getRenderingHints
获取当前绘制器参数信息(为了兼容接口,无实际用途)- Specified by:
getRenderingHintsin classGraphics2D- Returns:
- 参数信息(只读)
-
create
-
getColor
-
setColor
-
setPaintMode
-
setXORMode
setXORMode 不实现- Specified by:
setXORModein classGraphics- Parameters:
c1- the XOR alternation color
-
getFont
-
setFont
-
getFontMetrics
获取特定字体的字体规格- Specified by:
getFontMetricsin classGraphics- Parameters:
f- 特定字体- Returns:
- 字体规格
-
getClipBounds
获取裁剪区域的外接矩形大小- Specified by:
getClipBoundsin classGraphics- Returns:
- 裁剪区域外接矩形,可能为null
-
clipRect
-
setClip
-
getClip
-
clip
设置裁剪区域若已经存在裁剪区域,那么新的裁剪区域与旧的裁剪区域取交集。
- Specified by:
clipin classGraphics2D- Parameters:
s- 裁剪区域,如果为 null 则清除裁剪区域
-
setClip
-
copyArea
public void copyArea(int x, int y, int width, int height, int dx, int dy) 复制矩形区域- Specified by:
copyAreain classGraphics- Parameters:
x- the x coordinate of the source rectangle.y- the y coordinate of the source rectangle.width- the width of the source rectangle.height- the height of the source rectangle.dx- the horizontal distance to copy the pixels.dy- the vertical distance to copy the pixels.
-
drawLine
-
fillRect
-
drawRect
-
clearRect
-
drawRoundRect
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) 绘制圆角矩形- Specified by:
drawRoundRectin classGraphics- Parameters:
x- 矩形左上角X坐标y- 矩形左上角Y坐标width- 矩形宽度height- 矩形高度arcWidth- 水平圆角半径arcHeight- 垂直圆角半径
-
fillRoundRect
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) 填充圆角矩形- Specified by:
fillRoundRectin classGraphics- Parameters:
x- 矩形左上角X坐标y- 矩形左上角Y坐标width- 矩形宽度height- 矩形高度arcWidth- 水平圆角半径arcHeight- 垂直圆角半径
-
drawOval
-
fillOval
-
drawArc
-
fillArc
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) 在矩形区域内填充扇形注意:0度位于时钟3点钟位置,正数角度表示顺时针旋转,负数为逆时针,圆形位于矩形中心。
圆弧起点和终点为圆心
-
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) 绘制折线注意绘制的折线是一个不闭合的图形
- Specified by:
drawPolylinein classGraphics- Parameters:
xPoints- 折点 X坐标 序列yPoints- 折点 Y坐标 序列nPoints- 折点总数
-
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) 使用当前颜色和描边属性描边多边形- Specified by:
drawPolygonin classGraphics- Parameters:
xPoints- 多边形 X坐标 序列yPoints- 多边形 Y坐标 序列nPoints- 多边形点数量
-
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) 使用当前颜色填充多边形- Specified by:
fillPolygonin classGraphics- Parameters:
xPoints- 多边形 X坐标 序列yPoints- 多边形 Y坐标 序列nPoints- 多边形点数量
-
translate
public void translate(int x, int y) 平移原点坐标- Specified by:
translatein classGraphics2D- Parameters:
x- x方向的平移距离y- y方向的平移距离
-
translate
public void translate(double tx, double ty) 平移原点- Specified by:
translatein classGraphics2D- Parameters:
tx- x方向的平移距离ty- y方向的平移距离
-
rotate
public void rotate(double theta) 绕原点旋转画布- Specified by:
rotatein classGraphics2D- Parameters:
theta- 旋转角度,计算方式为theta = angle * Math.PI / 180,负数表示逆时针。
-
rotate
public void rotate(double theta, double x, double y) 绕指定点旋转画布等价于
translate(x, y); rotate(theta); translate(-x, -y);- Specified by:
rotatein classGraphics2D- Parameters:
theta- 旋转角度,计算方式为theta = angle * Math.PI / 180,负数表示逆时针。x- 旋转点X坐标y- 旋转点Y坐标
-
scale
public void scale(double sx, double sy) 坐标缩放- Specified by:
scalein classGraphics2D- Parameters:
sx- 缩放当前绘图的宽度 (1=100%, 0.5=50%, 2=200%, 依次类推)sy- 缩放当前绘图的高度 (1=100%, 0.5=50%, 2=200%, 依次类推)
-
shear
public void shear(double shx, double shy) 切变- Specified by:
shearin classGraphics2D- Parameters:
shx- X方向切变角度shy- Y方向切变角度
-
transform
图形变换- Specified by:
transformin classGraphics2D- Parameters:
tx- 变换矩阵
-
setTransform
设置变换矩阵- Specified by:
setTransformin classGraphics2D- Parameters:
tx- 变换矩阵
-
getTransform
返回当前的变换矩阵- Specified by:
getTransformin classGraphics2D- Returns:
- 变换矩阵
-
getPaint
-
getComposite
获取像素合成模式该属性只是为了兼容AWT接口保留,并无实际用途。
- Specified by:
getCompositein classGraphics2D- Returns:
- 获取像素合成模式
-
setBackground
设置背景颜色- Specified by:
setBackgroundin classGraphics2D- Parameters:
color- 该颜色将用于clearRect清空区域
-
getBackground
-
getStroke
获取描边属性- Specified by:
getStrokein classGraphics2D- Returns:
- 描述属性
BasicStroke
-
getFontRenderContext
获取绘制上下文中的字体绘制上下文- Specified by:
getFontRenderContextin classGraphics2D- Returns:
- 字体绘制上下文
-
dispose
-
appendPageBlock
在当前页面内容容器(CT_PageBlock)尾部追加一个页块对象供其他绘制管线(如 PDF 转换的文字对象输出)按内容流顺序追加
等图元, 保证与invalid reference
TextObjectfill(Shape)、draw(Shape)产生的路径对象在 z-order 上严格一致。 追加操作不受当前绘制属性(画笔、描边、变换矩阵)影响,调用方负责自行给出图元的坐标与属性。- Parameters:
block- 待追加的页块对象,为 null 时忽略
-
newObjectId
生成页面所在文档内的新对象 ID供通过
appendPageBlock(PageBlockType)追加图元的调用方分配对象 ID, 与fill/draw/drawImage生成的图元共用同一套 ID 空间。- Returns:
- 文档内唯一的新对象 ID
-
getOfdDir
取得当前页所属的文档工作目录供需要写入页面注释(如
Annots/)等非页面内容资源的调用方使用; 文档打包时整目录入包,因此写入该目录下的文件会随文档一起输出。- Returns:
- 文档工作目录
-
getDocument
-
addImageResource
把位图登记为文档图片资源供需要引用图片资源但又不直接绘制图片的调用方使用(例如水印单元缩略图)。
- Parameters:
image- 位图(非空)- Returns:
- 图片资源 ID
- Throws:
IOException- 编码或写盘失败
-
trans
转为AWT变换矩阵AffineTransform为 OFD 类型变换矩阵ST_Array- Parameters:
tx- AWT变换矩阵- Returns:
- OFD ST_Array
-