Skip to main content

text

Modules

ModuleDescription
modeling/text文本为每个字符或字符串提供线段集合。这些线段可用于为二维和三维几何图形创建轮廓。注意:仅支持 ASCII 字符。

Typedefs

NameDescription
VectorCharObjectRepresents a character as a list of segments

modeling/text

文本为每个字符或字符串提供线段集合。这些线段可用于为二维和三维几何图形创建轮廓。注意:仅支持 ASCII 字符。

Example

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

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

从ASCII 字符(编码范围 31 至 127) 构造一个 VectorCharObject(矢量字符对象);若该字符不被支持,则会替换为问号。

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], ...], ...]