Class: VectorFont

PD. VectorFont


new VectorFont()

Generates text using a customisable vector-based font.

Use this class to generate lines that represent text within a model. Whilst you can also use normal fonts to generate text, this method is much more light-weight and creates an effect similar to older-style blueprints and pen-plotter output.

Author:
  • drajmarsh

Methods


this.aspectRatio(aspect [, charSpacing] [, wordSpacing]) <static>

Gets/sets the aspect ratio of text characters.

Parameters:
Name Type Argument Description
aspect number

The aspect ratio as a decimal value (0.1 - 10.0).

charSpacing number <optional>

The relative width of the spacing between each character (0.1 - 10.0).

wordSpacing number <optional>

The relative width of the spacing between each word (0.1 - 10.0).

Returns:

Returns this line font to support method chaining.

Type
PD.VectorFont

this.averageKerning( [value]) <static>

Gets/sets the average horizontal kerning between characters. This value defaults to 1.40 times the character size.

Parameters:
Name Type Argument Description
value number <optional>

An optional new value for the kerning to (0.1 - 10.0).

Returns:

Returns the kerning value or this line font to support method chaining.

Type
number | PD.VectorFont

this.fontSize( [value]) <static>

Gets/sets the character size of the font in model units.

This value defaults to 100mm and is effectively the height from the bottom to top in thE local Y axis of each character.

Parameters:
Name Type Argument Description
value number <optional>

An optional new value for the font size in model units.

Returns:

Returns the character size or this line font to support method chaining.

Type
number | PD.VectorFont

this.generateText(text [, align] [, axis]) <static>

Generates a series of line segments that represent the given text.

Each line segment contains two or more sequentially connected [x,y,z] vector arrays. You don't have to worry about closed loops as any that are will automatically append their first point at the end.

Parameters:
Name Type Argument Description
text string

The text string to display. This is limited to the 7-bit ANSI character set (0-128). !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`{|}~.

align PD.ALIGN <optional>

The alignment of the text, defaults to 0 (LEFT aligned and sitting on baseline).

axis PD.AxisArray <optional>

The local coordinates to use for positioning and rotating the text, defaults to the origin.

Returns:

Returns An array of line segments defining the text.

Type
Array.<Array.<Array.<number>>>
Example
const vec_font = new PD.VectorFont();
const local_axis = vec_font.localAxis();
local_axis.rotateX(PD.Utils.HALF_PI);
local_axis.setOrigin(0, 0, 500);

const text_lines = vec_font.generateText('This is some text.', PD.ALIGN.CENTER);
CAD.addWires(text_lines);

this.getTextWidth(text) <static>

Retrieves the width of the vector text within the model. The width is always given in relative units, being the effective number of characters wide.

Parameters:
Name Type Description
text string

The string to calculate the width of.

Returns:

Returns the width of the text in relative units.

Type
number

this.italicSlant( [value]) <static>

Gets/sets the level of italic slant in the X axis.

Parameters:
Name Type Argument Description
value number <optional>

An optional value to set the slant to (-1.0 to 1.0).

Returns:

Returns the italic slant or this line font to support method chaining.

Type
number | PD.VectorFont

this.lineHeight( [value]) <static>

Gets/sets the vertical distance between each text line.

This value is given as a multiplier of the character size and defaults to 2.

Parameters:
Name Type Argument Description
value number <optional>

An optional new value for the line height.

Returns:

Returns the character size or this line font to support method chaining.

Type
number | PD.VectorFont

this.resetMetrics() <static>

Resets all font style variable to their default values.

Returns:

Returns this line font to support method chaining.

Type
PD.VectorFont

this.wordSpacing( [value]) <static>

Gets/sets the horizontal spacing between words. This value defaults to 0.8 times the character size.

Parameters:
Name Type Argument Description
value number <optional>

An optional new value for the word spacing to (0.1 - 10.0).

Returns:

Returns the word spacing or this line font to support method chaining.

Type
number | PD.VectorFont