跳到主要内容

Path

declare class Path {}

The Path class encapsulates compound (multiple contour) geometric paths consisting of straight line segments, quadratic curves. It can be drawn with canvas.drawPath(path, paint), either filled or stroked (based on the paint's Style), or it can be used for clipping or to draw text on a path.

Instance Method

constructor

declare class Path {
constructor()
constructor(path: Path)
}
  • Description

    Create a new path

arcTo

declare class Path {
arcTo(oval:Rect, startAngle: number, sweepAngle: number): void
arcTo(oval: Rect, startAngle: number, sweepAngle: number, forceMoveTo: boolean): void
}
  • Description

    Append the specified arc to the path as a new contour.

addRect

declare class Path {
addRect(rect: Rect, dir: Path.Direction): void
addRect(left: number, top: number, right: number, bottom: number, dir: Path.Direction): void
}
  • Description

    Add a closed rectangle contour to the path

addOval

declare class Path {
addOval(oval: Rect, dir: Path.Direction): void
}
  • Description

    Add a closed oval contour to the path

addCircle

declare class Path {
addCircle(x: number, y: number, radius: number, dir: Path.Direction): void
}
  • Description

    Add a closed circle contour to the path

addArc

declare class Path {
addArc(oval:Rect, startAngle: number, sweepAngle: number): void
}
  • Description

    Add the specified arc to the path as a new contour.

addPath

declare class Path {
addPath(src: Path): void
}
  • Description

    Add a copy of src to the path

addPath

declare class Path {
addPath(src: Path, matrix: Matrix): void
}
  • Description

    Add a copy of src to the path, transformed by matrix

addPath

declare class Path {
addPath(src: Path, dx: number, dy: number): void
}
  • Description

    Add a copy of src to the path, offset by (dx,dy)

addRoundRect

declare class Path {
addRoundRect(rect: Rect, radii: number[], dir: Path.Direction): void
addRoundRect(rect: Rect, rx: number, ry: number, dir: Path.Direction): void
}
  • Description

    Add a closed round-rectangle contour to the path

offset

declare class Path {
offset(dx: number, dy: number): void
offset(dx: number, dy: number, dst: Path): void
}
  • Description

    Offset the path by (dx,dy)

setLastPoint

declare class Path {
setLastPoint(dx: number, dy: number): void
}
  • Description

    Sets the last point of the path.

transform

declare class Path {
transform(matrix: Matrix): void
}
  • Description

    Transform the points in this path by matrix.

transform

declare class Path {
transform(matrix: Matrix, dst: Path): void
}
  • Description

    Transform the points in this path by matrix, and write the answer into dst.

quadTo

declare class Path {
quadTo(x1: number, y1: number, x2: number, y2: number): void
}
  • Description

    Add a quadratic bezier from the last point, approaching control point (x1,y1), and ending at (x2,y2).

rQuadTo

declare class Path {
rQuadTo(dx1: number, dy1: number, dx2: number, dy2: number): void
}
  • Description

    Same as quadTo, but the coordinates are considered relative to the last point on this contour.

reWind

declare class Path {
reWind(): void
}
  • Description

    Rewinds the path: clears any lines and curves from the path but keeps the internal data structure for faster reuse.

reset

declare class Path {
reset(): void
}
  • Description

    Clear any lines and curves from the path, making it empty.

isEmpty

declare class Path {
isEmpty(): boolean
}
  • Description

    Returns true if the path is empty (contains no lines or curves).

isRect

declare class Path {
isRect(rect: Rect): boolean
}
  • Description

    Returns true if the path specifies a rectangle.

close

declare class Path {
close(): void
}
  • Description

    Close the current contour.

moveTo

declare class Path {
moveTo(x: number, y: number): void
}
  • Description

    Set the beginning of the next contour to the point (x,y).

rMoveTo

declare class Path {
rMoveTo(dx: number, dy: number): void
}
  • Description

    Set the beginning of the next contour relative to the last point on the previous contour.

lineTo

declare class Path {
lineTo(x: number, y: number): void
}
  • Description

    Add a line from the last point to the specified point (x,y).

rLineTo

declare class Path {
rLineTo(dx: number, dy: number): void
}
  • Description

    Same as lineTo, but the coordinates are considered relative to the last point on this contour.

cubicTo

declare class Path {
cubicTo(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): void
}
  • Description

    Add a cubic bezier from the last point, approaching control points (x1,y1) and (x2,y2), and ending at (x3,y3).

rCubicTo

declare class Path {
rCubicTo(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): void
}
  • Description

    Same as cubicTo, but the coordinates are considered relative to the current point on this contour.

Path.Direction

Direction

enum Direction {
CW, CCW
}

Static Property

CW

declare enum Direction {
CW
}
  • Description

    clockwise.

CCW

declare enum Direction {
CCW
}
  • Description

    counter-clockwise.

Path.FillType

FillType

enum Direction {
WINDING, EVEN_ODD, INVERSE_WINDING, INVERSE_EVEN_ODD
}

Static Property

WINDING

declare enum FillType {
WINDING
}
  • Description

    Specifies that "inside" is computed by a non-zero sum of signed edge crossings.

EVEN_ODD

declare enum FillType {
EVEN_ODD
}
  • Description

    Specifies that "inside" is computed by an odd number of edge crossings.

INVERSE_WINDING

declare enum FillType {
INVERSE_WINDING
}
  • Description

    Same as WINDING, but draws outside of the path, rather than inside.

INVERSE_EVEN_ODD

declare enum FillType {
INVERSE_EVEN_ODD
}
  • Description

    Same as EVEN_ODD, but draws outside of the path, rather than inside.