Skip to content

@pdfa-lab/fontkit / Path

Class: Path ​

Defined in: src/glyph/path.ts:25

Path objects are returned by glyphs and represent the actual vector outlines for each glyph in the font. Paths can be converted to SVG path data strings, or to functions that can be applied to render the path to a graphics context.

Constructors ​

Constructor ​

new Path(): Path

Defined in: src/glyph/path.ts:30

Returns ​

Path

Properties ​

PropertyModifierTypeDefined in
commandspublicPathCommand[]src/glyph/path.ts:26

Accessors ​

bbox ​

Get Signature ​

get bbox(): Readonly<BoundingBox>

Defined in: src/glyph/path.ts:96

This property represents the path’s bounding box, i.e. the smallest rectangle that contains the entire path shape. This is the exact bounding box, taking into account control points that may be outside the visible shape.

Returns ​

Readonly<BoundingBox>


cbox ​

Get Signature ​

get cbox(): Readonly<BoundingBox>

Defined in: src/glyph/path.ts:75

This property represents the path’s control box. It is like the bounding box, but it includes all points of the path, including control points of bezier segments. It is much faster to compute than the real bounding box, but less accurate if there are control points outside of the visible shape.

Returns ​

Readonly<BoundingBox>

Methods ​

bezierCurveTo() ​

bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y): this

Defined in: src/glyph/path.ts:305

Adds a bezier curve to the path from the current point to the given x, y coordinates using cp1x, cp1y and cp2x, cp2y as control points.

Parameters ​

ParameterType
cp1xnumber
cp1ynumber
cp2xnumber
cp2ynumber
xnumber
ynumber

Returns ​

this


closePath() ​

closePath(): this

Defined in: src/glyph/path.ts:320

Closes the current sub-path by drawing a straight line back to the starting point.

Returns ​

this


lineTo() ​

lineTo(x, y): this

Defined in: src/glyph/path.ts:289

Adds a line to the path from the current point to the given x, y coordinates.

Parameters ​

ParameterType
xnumber
ynumber

Returns ​

this


mapPoints() ​

mapPoints(fn): Path

Defined in: src/glyph/path.ts:220

Applies a mapping function to each point coordinate in the path.

Parameters ​

ParameterTypeDescription
fn(x, y) => [number, number]A transformation callback yielding a new [x, y] tuple.

Returns ​

Path


moveTo() ​

moveTo(x, y): this

Defined in: src/glyph/path.ts:281

Moves the virtual pen to the given x, y coordinates.

Parameters ​

ParameterType
xnumber
ynumber

Returns ​

this


quadraticCurveTo() ​

quadraticCurveTo(cpx, cpy, x, y): this

Defined in: src/glyph/path.ts:297

Adds a quadratic curve to the path from the current point to the given x, y coordinates using cpx, cpy as a control point.

Parameters ​

ParameterType
cpxnumber
cpynumber
xnumber
ynumber

Returns ​

this


rotate() ​

rotate(angle): Path

Defined in: src/glyph/path.ts:265

Rotates the path by the given angle (in radians).

Parameters ​

ParameterType
anglenumber

Returns ​

Path


scale() ​

scale(scaleX, scaleY?): Path

Defined in: src/glyph/path.ts:274

Scales the path coordinates by the specified scaling parameters.

Parameters ​

ParameterTypeDefault value
scaleXnumberundefined
scaleYnumberscaleX

Returns ​

Path


toFunction() ​

toFunction(): (ctx) => void

Defined in: src/glyph/path.ts:42

Compiles the path to a function that can be executed against a given graphics context to render the path.

Returns ​

A function accepting a graphics context.

(ctx) => void


toSVG() ​

toSVG(): string

Defined in: src/glyph/path.ts:59

Converts the path to an SVG path data string.

Returns ​

string


transform() ​

transform(m0, m1, m2, m3, m4, m5): Path

Defined in: src/glyph/path.ts:240

Transforms the path by a standard 2D affine transformation matrix.

Parameters ​

ParameterType
m0number
m1number
m2number
m3number
m4number
m5number

Returns ​

Path


translate() ​

translate(x, y): Path

Defined in: src/glyph/path.ts:258

Translates the path by the given x and y offsets.

Parameters ​

ParameterType
xnumber
ynumber

Returns ​

Path