Skip to main content

text

Modules

ModuleDescription
modeling/textTexts provide sets of segments for each character or text strings. The segments can be used to create outlines for both 2D and 3D geometry. Note: Only ASCII characters are supported.

Typedefs

NameDescription
VectorCharObjectRepresents a character as a list of segments

modeling/text

Texts provide sets of segments for each character or text strings. The segments can be used to create outlines for both 2D and 3D geometry. Note: Only ASCII characters are supported.

Example

const { vectorChar, vectorText } = require('@jscad/modeling').text

modeling/text.vectorChar([options], [char])

Construct a VectorCharObject from a ascii character whose code is between 31 and 127, if the character is not supported it is replaced by a question mark.

Kind: static method of modeling/text

ParamTypeDefaultDescription
[options]Object | Stringoptions for construction or ascii character
[options.xOffset]Float0x offset
[options.yOffset]Float0y offset
[options.height]Float21font size (uppercase height)
[options.extrudeOffset]Float0width of the extrusion that will be applied (manually) after the creation of the character
[options.input]String'?'ascii character (ignored/overwrited if provided as seconds parameter)
[char]String'?'ascii character

Example

let vectorCharObject = vectorChar()
let vectorCharObject = vectorChar('A')
let vectorCharObject = vectorChar({ xOffset: 57 }, 'C')
let vectorCharObject = vectorChar({ xOffset: 78, input: '!' })

modeling/text.vectorText([options], [text])

Construct an array of character segments from a ascii string whose characters code is between 31 and 127, if one character is not supported it is replaced by a question mark.

Kind: static method of modeling/text
Returns: Array - characters segments [[[x, y], ...], ...]

ParamTypeDefaultDescription
[options]Object | Stringoptions for construction or ascii string
[options.xOffset]Float0x offset
[options.yOffset]Float0y offset
[options.height]Float21font size (uppercase height)
[options.lineSpacing]Float1.4line spacing expressed as a percentage of font size
[options.letterSpacing]Float1extra letter spacing expressed as a percentage of font size
[options.align]String'left'multi-line text alignment: left, center, right
[options.extrudeOffset]Float0width of the extrusion that will be applied (manually) after the creation of the character
[options.input]String'?'ascii string (ignored/overwrited if provided as seconds parameter)
[text]String'?'ascii string

Example

let textSegments = vectorText()
let textSegments = vectorText('OpenJSCAD')
let textSegments = vectorText({ yOffset: -50 }, 'OpenJSCAD')
let textSegments = vectorText({ yOffset: -80, input: 'OpenJSCAD' })

VectorCharObject

Represents a character as a list of segments

Kind: global typedef
Properties

NameTypeDescription
widthFloatcharacter width
heightFloatcharacter height (uppercase)
segmentsArraycharacter segments [[[x, y], ...], ...]