此插件模仿 HTML5 CanvasRenderingContext2D。
此插件的目标是提供一种方法,使当前的 canvas 实现能够直接打印到 PDF 中。
- Source:
Members
(inner) ctx :object
- Source:
- Default Value:
- {}
Type:
- object
(inner) ctxStack :array
- Source:
- Default Value:
- []
Type:
- array
(inner) fillStyle
- Source:
- Default Value:
- #000000
Properties:
Name | Type | Description |
---|---|---|
value |
color | gradient | pattern | 绘制颜色。默认值为 #000000 |
设置或返回用于填充绘制的颜色、渐变或图案
(inner) lastBreak :number
- Source:
- Default Value:
- 0
Type:
- number
(inner) lineCap
- Source:
- Default Value:
- butt
Properties:
Name | Type | Description |
---|---|---|
lineCap |
butt | round | square | butt 在每条线的末端添加一个平边 |
设置或返回线条末端的样式
(inner) lineDashOffset
- Source:
- Default Value:
- 0.0
一个浮点数,指定线条虚线偏移量的数值。默认值为 0.0。
(inner) lineWidth
- Source:
- Default Value:
- 1
Properties:
Name | Type | Description |
---|---|---|
lineWidth |
number | 当前线条宽度,以像素为单位 |
设置或返回当前线条宽度
(inner) margin :number|Array.<number>
- Source:
- Default Value:
- [0, 0, 0, 0]
在自动分页时获取或设置页面边距。当 autoPaging 关闭时没有效果。
Type:
- number | Array.<number>
(inner) miterLimit
- Source:
- Default Value:
- 10
一个数字,指定在坐标空间单位中的斜接限制比率。零、负、无穷大和 NaN 值被忽略。默认值为 10.0。
(inner) pageBreaks :number
- Source:
- Default Value:
- 0
页面断开的位置。
Type:
- number
(inner) pageWrapXEnabled :boolean
- Source:
- Default Value:
- false
Type:
- boolean
(inner) pageWrapYEnabled :boolean
- Source:
- Default Value:
- true
Type:
- boolean
(inner) path :array
- Source:
- Default Value:
- []
Type:
- array
(inner) posX :number
- Source:
- Default Value:
- 0
Type:
- number
(inner) posY :number
- Source:
- Default Value:
- 0
Type:
- number
(inner) strokeStyle
- Source:
- Default Value:
- #000000
Properties:
Name | Type | Description |
---|---|---|
color |
color | 一个 CSS 颜色值,表示绘制的线条颜色。默认值为 #000000(不支持 context2d) |
gradient |
gradient | 一个渐变对象(线性或径向)用于创建渐变线条(不支持 context2d) |
pattern |
pattern | 一个图案对象,用于创建图案线条(不支持 context2d) |
设置或返回用于线条的颜色、渐变或图案
Methods
(inner) arc(x, y, radius, startAngle, endAngle, counterclockwise)
- Source:
arc() 方法创建弧/曲线 (用于创建圆形或圆形的一部分)。
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The x-coordinate of the center of the circle |
y |
Number | The y-coordinate of the center of the circle |
radius |
Number | The radius of the circle |
startAngle |
Number | 起始角度,以弧度为单位(0 是圆弧的 3 点位置) |
endAngle |
Number | 结束角度,以弧度为单位 |
counterclockwise |
Boolean | 可选。指定绘制是否应为逆时针或顺时针。默认值为 false,表示顺时针,而 true 表示逆时针。 |
(inner) arcTo(x1, y1, x2, y2, radius)
- Source:
arcTo() 方法在画布上创建两个切线之间的弧/曲线。
Parameters:
Name | Type | Description |
---|---|---|
x1 |
Number | 第一个切线的 x 坐标 |
y1 |
Number | 第一个切线的 y 坐标 |
x2 |
Number | 第二个切线的 x 坐标 |
y2 |
Number | 第二个切线的 y 坐标 |
radius |
弧的半径 |
(inner) beginPath()
- Source:
beginPath() 方法开始一条路径,或重置当前路径。
(inner) bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
- Source:
bezierCurveTo() 方法通过使用指定的控制点来向当前路径添加一个点,这些控制点代表一个三次贝塞尔曲线。
三次贝塞尔曲线需要三个点。前两个点是控制点,用于三次贝塞尔计算,最后一个点是曲线的终点。曲线的起点是当前路径中的最后一个点。如果路径不存在,请使用 beginPath() 和 moveTo() 方法定义起点。
Parameters:
Name | Type | Description |
---|---|---|
cp1x |
Number | 第一个贝塞尔控制点的 x 坐标 |
cp1y |
Number | 第一个贝塞尔控制点的 y 坐标 |
cp2x |
Number | 第二个贝塞尔控制点的 x 坐标 |
cp2y |
Number | 第二个贝塞尔控制点的 y 坐标 |
x |
Number | 曲线的终点 x 坐标 |
y |
Number | 曲线的终点 y 坐标 |
(inner) clearRect(x, y, w, h)
- Source:
我们不能清除已经写入 PDF 的 PDF 命令,所以我们使用白色代替。
作为一个特殊情况,读取一个特殊标志(ignoreClearRect),如果它被设置,则什么都不做。
这会导致所有对 clearRect() 的调用都无效,并保持画布透明。
这个标志存储在 save/restore 上下文中,并与其他绘图状态以相同的方式管理。
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | 矩形左上角的 x 坐标 |
y |
Number | 矩形左上角的 y 坐标 |
w |
Number | 要清除的矩形的宽度,以像素为单位 |
h |
Number | 要清除的矩形的高度,以像素为单位 |
(inner) clip()
- Source:
clip() 方法从原始画布中剪裁任何形状和大小的区域。
(inner) closePath()
- Source:
closePath() 方法从当前点到起始点创建一条路径。
(inner) createArc()
- Source:
返回一个对象数组,这些对象表示贝塞尔曲线,这些曲线近似于以原点为中心的圆弧,从 startAngle 到 endAngle(弧度),半径为指定值。
每个贝塞尔曲线是一个包含四个点的对象,其中 x1,y1 和 x4,y4 是弧的终点,x2,y2 和 x3,y3 是三次贝塞尔的控制点。
(inner) fillRect(x, y, w, h)
- Source:
fillRect() 方法绘制一个“填充”矩形。填充的默认颜色是黑色。
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | 矩形左上角的 x 坐标 |
y |
Number | 矩形左上角的 y 坐标 |
w |
Number | 矩形的宽度,以像素为单位 |
h |
Number | 矩形的高度,以像素为单位 |
(inner) fillText(text, x, y, maxWidth)
- Source:
fillText() 方法在画布上绘制填充文本。文本的默认颜色是黑色。
Parameters:
Name | Type | Description |
---|---|---|
text |
String | 指定要绘制在画布上的文本 |
x |
Number | 文本开始绘制的 x 坐标(相对于画布) |
y |
Number | 文本开始绘制的 y 坐标(相对于画布) |
maxWidth |
Number | 可选。文本的最大允许宽度,以像素为单位 |
(inner) getLineDash() → {Array}
- Source:
获取当前的线虚线模式。
Returns:
一个数字数组,指定交替绘制线条和间隙的距离(以坐标空间单位为单位)。如果设置的元素为奇数,则数组元素会被复制并连接。例如,设置线虚线为 [5, 15, 25] 将返回 [5, 15, 25, 5, 15, 25]。
- Type
- Array
(inner) lineTo(x, y)
- Source:
lineTo() 方法添加一个新点并创建一条线到该点(从最后一个指定的点开始)。
Parameters:
Name | Type | Description |
---|---|---|
x |
要创建线的 x 坐标 |
|
y |
要创建线的 y 坐标 |
(inner) measureText(text) → {Number}
- Source:
measureText() 方法返回一个包含指定文本宽度的对象,以像素为单位。
Parameters:
Name | Type | Description |
---|---|---|
text |
String | 要测量的文本 |
Returns:
- Type
- Number
(inner) moveTo(x, y)
- Source:
moveTo() 方法将路径移动到画布上的指定点,不创建线条。
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | 要移动路径的 x 坐标 |
y |
Number | 要移动路径的 y 坐标 |
(inner) quadraticCurveTo(cpx, cpy, x, y)
- Source:
quadraticCurveTo() 方法通过使用指定的控制点添加一个点,这些控制点表示二次贝塞尔曲线。
二次贝塞尔曲线需要两个点。第一个点是控制点,用于二次贝塞尔计算,第二个点是曲线的结束点。曲线的起点是当前路径中的最后一个点。如果路径不存在,请使用 beginPath() 和 moveTo() 方法定义起点。
Parameters:
Name | Type | Description |
---|---|---|
cpx |
Number | 贝塞尔控制点的 x 坐标 |
cpy |
Number | 贝塞尔控制点的 y 坐标 |
x |
Number | 曲线的结束点 x 坐标 |
y |
Number | 曲线的结束点 y 坐标 |
(inner) rect(x, y, w, h)
- Source:
rect() 方法创建一个矩形。
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | 矩形左上角的 x 坐标 |
y |
Number | 矩形左上角的 y 坐标 |
w |
Number | 矩形的宽度,以像素为单位 |
h |
Number | 矩形的高度,以像素为单位 |
(inner) restore()
- Source:
返回之前保存的路径状态和属性
(inner) rotate(angle)
- Source:
从度数转换为弧度:degreesMath.PI/180。
例如:要旋转 5 度,请指定以下内容:5Math.PI/180
Parameters:
Name | Type | Description |
---|---|---|
angle |
Number | 旋转角度,以弧度为单位。 |
(inner) save()
- Source:
保存当前上下文的状态
(inner) scale(scalewidth, scaleheight)
- Source:
scale() 方法缩放当前绘制,变大或变小。
Parameters:
Name | Type | Description |
---|---|---|
scalewidth |
Number | 缩放当前绘制(1=100%,0.5=50%,2=200%,等等) |
scaleheight |
Number | 缩放当前绘制的高度(1=100%,0.5=50%,2=200%,等等) |
(inner) setLineDash()
- Source:
它使用一个值数组,这些值指定交替的线条长度和间隙,这些值描述了图案。
(inner) setTransform(a, b, c, d, e, f)
- Source:
每个画布对象都有一个当前变换矩阵。
setTransform() 方法将当前变换重置为单位矩阵,然后使用相同的参数运行 transform()。
换句话说,setTransform() 方法允许您缩放、旋转、移动和倾斜当前上下文。
Parameters:
Name | Type | Description |
---|---|---|
a |
Number | Horizontal scaling |
b |
Number | Horizontal skewing |
c |
Number | Vertical skewing |
d |
Number | Vertical scaling |
e |
Number | Horizontal moving |
f |
Number | Vertical moving |
(inner) stroke()
- Source:
stroke() 方法实际上绘制了您使用所有那些 moveTo() 和 lineTo() 方法定义的路径。默认颜色是黑色。
(inner) strokeRect(x, y, w, h)
- Source:
strokeRect() 方法绘制一个矩形(无填充)。默认的描边颜色是黑色。
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | 矩形左上角的 x 坐标 |
y |
Number | 矩形左上角的 y 坐标 |
w |
Number | 矩形的宽度,以像素为单位 |
h |
Number | 矩形的高度,以像素为单位 |
(inner) strokeText(text, x, y, maxWidth)
- Source:
strokeText() 方法在画布上绘制文本(无填充)。默认文本颜色为黑色。
Parameters:
Name | Type | Description |
---|---|---|
text |
String | 指定要绘制在画布上的文本 |
x |
Number | 文本开始绘制的 x 坐标(相对于画布) |
y |
Number | 文本开始绘制的 y 坐标(相对于画布) |
maxWidth |
Number | 可选。文本的最大允许宽度,以像素为单位 |
(inner) toDataURL()
- Source:
(inner) transform(a, b, c, d, e, f)
- Source:
每个画布对象都有一个当前变换矩阵。
transform() 方法替换当前变换矩阵。它将当前变换矩阵与描述的矩阵相乘:
a c e
b d f
0 0 1
换句话说,transform() 方法允许您缩放、旋转、移动和倾斜当前上下文。
Parameters:
Name | Type | Description |
---|---|---|
a |
Number | Horizontal scaling |
b |
Number | Horizontal skewing |
c |
Number | Vertical skewing |
d |
Number | Vertical scaling |
e |
Number | Horizontal moving |
f |
Number | Vertical moving |
(inner) translate(x, y)
- Source:
translate() 方法重新映射画布上的 (0,0) 位置。
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | 要添加到水平(x)坐标的值 |
y |
Number | 要添加到垂直(y)坐标的值 |