textpath
Renderer agnostic utility for drawing text along a path.
Getting started
The ES2015 way
To add the dependency to your project, run
npm install --save textpath
To use in your code, type
;
The vanilla JavaScript way
Include the following script tag in your HTML:
API
textPath
To render text to a CanvasRenderingContext2D, use something like the following code:
var canvas = document;var ctx = canvas; var path = 20 33 40 31 60 30 80 31 100 33; { return ctxwidth;} { ctx; ctx; ctx; ctx; ctx;} ;
Parameters
text
string Text to draw along thepath
.path
Array<Array<number>> Path represented in coordinate pairs.measure
Function Function that takes a text as argument and returns the width of the provided text.draw
Function Function that takes a letter, its x coordinate, y coordinate and angle (in radians) as arguments. It is typically used to draw the provided letter to a canvas.textAlign
string Text alignment along the path. One of 'left', 'center', 'right'. (optional, default'center'
)