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

Path()#

Create a new empty path.

Returns:

Path.

EXAMPLE

var path = new mupdfjs.Path();

INSTANCE METHODS

getBounds(strokeState: StrokeState, transform: Matrix)#

Return a bounding rectangle for the path.

Parameters:
  • strokeStrokeState. The stroke for the path.

  • transformMatrix. 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:
  • xnumber. X coordinate.

  • ynumber. Y coordinate.

EXAMPLE

path.moveTo(10, 10);
lineTo(x: number, y: number)#

Draw a line to the coordinate.

Parameters:
  • xnumber. X coordinate.

  • ynumber. 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:
  • x1number. X1 coordinate.

  • y1number. Y1 coordinate.

  • x2number. X2 coordinate.

  • y2number. Y2 coordinate.

  • x3number. X3 coordinate.

  • y3number. 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:
  • cxnumber. CX coordinate.

  • cynumber. CY coordinate.

  • exnumber. EX coordinate.

  • eynumber. 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:
  • cxnumber. CX coordinate.

  • cynumber. CY coordinate.

  • exnumber. EX coordinate.

  • eynumber. EY coordinate.

EXAMPLE

path.curveToY(0, 0, 100, 100);
closePath()#

Close the path by drawing a line to the last moveTo().

EXAMPLE

path.closePath();
rect(x1: number, y1: number, x2: number, y2: number)#

Shorthand for sequence: moveTo, lineTo, lineTo, lineTo, closePath to draw a rectangle.

Parameters:
  • x1number. X1 coordinate.

  • y1number. Y1 coordinate.

  • x2number. X2 coordinate.

  • y2number. Y2 coordinate.

EXAMPLE

path.rect(0,0,100,100);
transform(matrix: Matrix)#

Transform path by the given transform matrix.

Parameters:

matrixMatrix.

EXAMPLE

path.transform(mupdfjs.Matrix.scale(2,2));
walk(walker: PathWalker)#
Parameters:

walkerPathWalker. 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"