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.

new Path()

Constructor method.

Create a new empty path.

Returns:

Path.

EXAMPLE

var path = new mupdf.Path();

Instance methods

getBounds(stroke, transform)

Return a bounding rectangle for the path.

Arguments:
  • strokeFloat The stroke for the path.

  • transform[a,b,c,d,e,f]. The transform matrix for the path.

Returns:

[ulx,uly,lrx,lry] Rectangle.

EXAMPLE

var rect = path.getBounds(1.0, mupdf.Matrix.identity);
moveTo(x, y)

Lift and move the pen to the coordinate.

Arguments:
  • x – X coordinate.

  • y – Y coordinate.

EXAMPLE

path.moveTo(10, 10);
lineTo(x, y)

Draw a line to the coordinate.

Arguments:
  • x – X coordinate.

  • y – Y coordinate.

EXAMPLE

path.lineTo(20,20);
curveTo(x1, y1, x2, y2, x3, y3)

Draw a cubic bezier curve to (x3, y3) using (x1, y1) and (x2, y2) as control points.

Arguments:
  • x1 – X1 coordinate.

  • y1 – Y1 coordinate.

  • x2 – X2 coordinate.

  • y2 – Y2 coordinate.

  • x3 – X3 coordinate.

  • y3 – Y3 coordinate.

EXAMPLE

path.curveTo(0, 0, 10, 10, 100, 100);
curveToV(cx, cy, ex, ey)

Draw a cubic bezier curve to (ex, ey) using the start point and (cx, cy) as control points.

Arguments:
  • cx – CX coordinate.

  • cy – CY coordinate.

  • ex – EX coordinate.

  • ey – EY coordinate.

EXAMPLE

path.curveToV(0, 0, 100, 100);
curveToY(cx, cy, ex, ey)

Draw a cubic bezier curve to (ex, ey) using the (cx, cy) and (ex, ey) as control points.

Arguments:
  • cx – CX coordinate.

  • cy – CY coordinate.

  • ex – EX coordinate.

  • ey – 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, y1, x2, y2)

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

Arguments:
  • x1 – X1 coordinate.

  • y1 – Y1 coordinate.

  • x2 – X2 coordinate.

  • y2 – Y2 coordinate.

EXAMPLE

path.rect(0,0,100,100);
walk(pathWalker)

mutool only

Call moveTo, lineTo, curveTo and closePath methods on the pathWalker object to replay the path.

Arguments:
  • pathWalker – The path walker object. A user definable JavaScript object which can be used to trigger your own functions on the path methods.

Note

A path walker object has callback methods that are called when walk() walks over moveTo, lineTo, curveTo and closePath operators in a Path.

EXAMPLE

var myPathWalker = {
    moveTo: function (x, y) {
        //... do whatever ...
    },
    lineTo: function (x, y) {
        //... do whatever ...
    },
}
transform(transform)

Transform path by the given transform matrix.

Arguments:
  • transform[a,b,c,d,e,f]. The transform matrix for the path.

EXAMPLE

path.transform(mupdf.Matrix.scale(2,2));