MCPcopy
hub / github.com/processing/p5.js / textToPaths

Method textToPaths

src/type/p5.Font.js:193–210  ·  view source on GitHub ↗

* Returns a flat array of path commands that describe the outlines of a string of text. * * Each command is represented as an array of the form `[type, ...coords]`, where: * - `type` is one of `'M'`, `'L'`, `'Q'`, `'C'`, or `'Z'`, * - `coords` are the numeric values needed for that comma

(str, x, y, width, height, options)

Source from the content-addressed store, hash-verified

191 * }
192 */
193 textToPaths(str, x, y, width, height, options) {
194
195 ({ width, height, options } = this._parseArgs(width, height, options));
196
197 if (!this.data) {
198 throw Error('No font data available for "' + this.name
199 + '"\nTry downloading a local copy of the font file');
200 }
201
202 // lineate and get glyphs/paths for each line
203 let lines = this._lineateAndPathify(str, x, y, width, height, options);
204
205 // flatten into a single array containing all the glyphs
206 let glyphs = lines.map(o => o.glyphs).flat();
207
208 // flatten into a single array with all the path commands
209 return glyphs.map(g => g.path.commands).flat();
210 }
211
212 /**
213 * Returns an array of points outlining a string of text written using the

Callers 3

textToContoursMethod · 0.95
_textToPathPointsMethod · 0.95
typography.jsFile · 0.80

Calls 2

_parseArgsMethod · 0.95
_lineateAndPathifyMethod · 0.95

Tested by

no test coverage detected