@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 ​
| Property | Modifier | Type | Defined in |
|---|---|---|---|
commands | public | PathCommand[] | 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 ​
| Parameter | Type |
|---|---|
cp1x | number |
cp1y | number |
cp2x | number |
cp2y | number |
x | number |
y | number |
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 ​
| Parameter | Type |
|---|---|
x | number |
y | number |
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 ​
| Parameter | Type | Description |
|---|---|---|
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 ​
| Parameter | Type |
|---|---|
x | number |
y | number |
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 ​
| Parameter | Type |
|---|---|
cpx | number |
cpy | number |
x | number |
y | number |
Returns ​
this
rotate() ​
rotate(
angle):Path
Defined in: src/glyph/path.ts:265
Rotates the path by the given angle (in radians).
Parameters ​
| Parameter | Type |
|---|---|
angle | number |
Returns ​
Path
scale() ​
scale(
scaleX,scaleY?):Path
Defined in: src/glyph/path.ts:274
Scales the path coordinates by the specified scaling parameters.
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
scaleX | number | undefined |
scaleY | number | scaleX |
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 ​
| Parameter | Type |
|---|---|
m0 | number |
m1 | number |
m2 | number |
m3 | number |
m4 | number |
m5 | number |
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 ​
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns ​
Path