Text
Vector text generation from JSCAD’s built-in stroke font. Produces arrays of 2D line segments that can be extruded or used as path outlines. Useful for engraving labels, generating decorative text, or building text-based parametric models.
See also:
vectorText
Section titled “vectorText”function vectorText( options: { xOffset?: number; yOffset?: number; height?: number; lineSpacing?: number; letterSpacing?: number; align?: 'left' | 'center' | 'right'; extrudeOffset?: number; }, input: string ): Path2[]Generate vector outlines for a string of text using the built-in font.
Returns an array of Path2 objects — one open path per stroke in the text. The paths can be extruded with extrudeLinear or rendered as 2D outlines. Each character is approximately 1 unit tall; scale with transforms.scale.
Parameters:
| Name | Type | Description |
|---|---|---|
options |
— | Text options. |
options.xOffset |
— | Starting X offset. Default 0. |
options.yOffset |
— | Starting Y offset. Default 0. |
options.height |
— | Character height in units. Default 1. |
options.lineSpacing |
— | Spacing between lines as a multiplier of height. Default 1.4. |
options.letterSpacing |
— | Additional space between characters. Default 1. |
options.align |
— | Horizontal alignment: ‘left’, ‘center’, or ‘right’. Default ‘left’. |
options.extrudeOffset |
— | Extrusion offset for stroke width. Default 0. |
input |
— | The text string to render (may include newlines). |
Returns: Array of Path2 strokes forming the text outlines.
const { vectorText } = jscad.textconst { extrudeLinear } = jscad.extrusionsconst { union } = jscad.booleansconst { scale } = jscad.transformsasync function main({ message }) { const paths = vectorText({ height: 10, align: 'center' }, message) const letters = paths.map(p => extrudeLinear({ height: 2 }, p)) return union(...letters)}See also:
vectorChar
Section titled “vectorChar”function vectorChar( options: { xOffset?: number; yOffset?: number; height?: number; extrudeOffset?: number; }, input: string ): { width: number; paths: Path2[] }Generate vector outlines for a single character using the built-in font.
Returns the character width and its stroke paths. Useful when you need precise control over character placement or spacing.
Parameters:
| Name | Type | Description |
|---|---|---|
options |
— | Character options. |
options.xOffset |
— | Starting X offset. Default 0. |
options.yOffset |
— | Starting Y offset. Default 0. |
options.height |
— | Character height in units. Default 1. |
options.extrudeOffset |
— | Extrusion offset for stroke width. Default 0. |
input |
— | A single character to render. |
Returns: Object with the character advance width and its Path2 stroke array.
const { vectorChar } = jscad.textconst { extrudeLinear } = jscad.extrusionsconst { union } = jscad.booleansasync function main() { const { width, paths } = vectorChar({ height: 10 }, 'A') return union(...paths.map(p => extrudeLinear({ height: 2 }, p)))}See also: