Path#
A Path object represents vector graphics as drawn by a pen. A path can be either stroked or filled, or used as a clip mask.
CONSTRUCTOR METHODS
INSTANCE METHODS
- getBounds(strokeState: StrokeState, transform: Matrix)#
Return a bounding rectangle for the path.
- Parameters:
stroke – StrokeState. The stroke for the path.
transform – Matrix. The transform matrix for the path.
- Returns:
Rect.
EXAMPLE
var rect = path.getBounds(1.0, mupdfjs.Matrix.identity);
- moveTo(x: number, y: number)#
Lift and move the pen to the coordinate.
- Parameters:
x –
number
. X coordinate.y –
number
. Y coordinate.
EXAMPLE
path.moveTo(10, 10);
- lineTo(x: number, y: number)#
Draw a line to the coordinate.
- Parameters:
x –
number
. X coordinate.y –
number
. Y coordinate.
EXAMPLE
path.lineTo(20,20);
- curveTo(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number)#
Draw a cubic bezier curve to (
x3
,y3
) using (x1
,y1
) and (x2
,y2
) as control points.- Parameters:
x1 –
number
. X1 coordinate.y1 –
number
. Y1 coordinate.x2 –
number
. X2 coordinate.y2 –
number
. Y2 coordinate.x3 –
number
. X3 coordinate.y3 –
number
. Y3 coordinate.
EXAMPLE
path.curveTo(0, 0, 10, 10, 100, 100);
- curveToV(cx: number, cy: number, ex: number, ey: number)#
Draw a cubic bezier curve to (
ex
,ey
) using the start point and (cx
,cy
) as control points.- Parameters:
cx –
number
. CX coordinate.cy –
number
. CY coordinate.ex –
number
. EX coordinate.ey –
number
. EY coordinate.
EXAMPLE
path.curveToV(0, 0, 100, 100);
- curveToY(cx: number, cy: number, ex: number, ey: number)#
Draw a cubic bezier curve to (
ex
,ey
) using the (cx
,cy
) and (ex
,ey
) as control points.- Parameters:
cx –
number
. CX coordinate.cy –
number
. CY coordinate.ex –
number
. EX coordinate.ey –
number
. EY coordinate.
EXAMPLE
path.curveToY(0, 0, 100, 100);
- rect(x1: number, y1: number, x2: number, y2: number)#
Shorthand for sequence:
moveTo
,lineTo
,lineTo
,lineTo
,closePath
to draw a rectangle.- Parameters:
x1 –
number
. X1 coordinate.y1 –
number
. Y1 coordinate.x2 –
number
. X2 coordinate.y2 –
number
. Y2 coordinate.
EXAMPLE
path.rect(0,0,100,100);
- transform(matrix: Matrix)#
Transform path by the given transform matrix.
- Parameters:
matrix – Matrix.
EXAMPLE
path.transform(mupdfjs.Matrix.scale(2,2));
- walk(walker: PathWalker)#
- Parameters:
walker –
PathWalker
. Function with protocol methods, see example below for details.
EXAMPLE
function print(...args) { console.log(args.join(" ")) } var pathPrinter = { moveTo: function (x,y) { print("moveTo", x, y) }, lineTo: function (x,y) { print("lineTo", x, y) }, curveTo: function (x1,y1,x2,y2,x3,y3) { print("curveTo", x1, y1, x2, y2, x3, y3) }, closePath: function () { print("closePath") }, } var traceDevice = { fillPath: function (path, evenOdd, ctm, colorSpace, color, alpha) { print("fillPath", evenOdd, ctm, colorSpace, color, alpha) path.walk(pathPrinter) }, clipPath: function (path, evenOdd, ctm) { print("clipPath", evenOdd, ctm) path.walk(pathPrinter) }, strokePath: function (path, stroke, ctm, colorSpace, color, alpha) { print("strokePath", JSON.stringify(stroke), ctm, colorSpace, color, alpha) path.walk(pathPrinter) }, clipStrokePath: function (path, stroke, ctm) { print("clipStrokePath", JSON.stringify(stroke), ctm) path.walk(pathPrinter) } } var doc = mupdfjs.PDFDocument.openDocument(fs.readFileSync("test.pdf"), "application/pdf") var page = doc.loadPage(0) var device = new mupdfjs.Device(traceDevice) page.run(device, mupdfjs.Matrix.identity)
Code samples
Code samples are in TypeScript and assume that the following requirements are defined in your TypeScript file header as follows:
import * as fs from "fs"
import * as mupdfjs from "mupdf/mupdfjs"