new Font(fontData)
Creates a new cached font.
Parameters:
| Name | Type | Description |
|---|---|---|
fontData |
object | The parsed JSON object that defines a THREE font. |
Members
-
:object
glyphCache
-
A mapped cache of generated geometry from font glyphs.
Each entry in the glyph cache is an object with the following properties:
Type Name Description number width The width of the normalised character (0 to 1). Array shapes An array of zero or more THREE.Shapeobjects.Array data The cached geometric data object, normalised to unit size. Array data[n].vertices An array of THREE.Vector3giving the vertices in the shape.Array data[n].contours An array of contours with vertex indices for the outer boundary and internal holes. Array data[n].faces An array of triangular faces, each with three vertex indexes. Type
- object
-
:boolean
isFont <readonly>
-
A flag identifying this object as a font.
Type
- boolean
-
:number
lineHeight
-
The relative vertical distance between font baselines.
Type
- number
-
:number
lineHeightFactor
-
The fraction of the line height to apply.
Type
- number
-
:PD.Font
defaultFont <static>
-
A cut-down font with just numerals and some punctuation.
This font contains just those characters needed to display dimensions lines.
Type
Methods
-
addTextToBRep(brep, face, text [, xform] [, align] [, offset])
-
Adds positioned, scaled and aligned face geometry from a text string.
Parameters:
Name Type Argument Default Description brepPD.BRep The BRep the face belongs to.
facePD.BRep.Face The face to add the glyph into.
textstring The string of characters to represent in the mesh.
xformTHREE.Matrix4 | PD.LocalCoordinates <optional>
A transformation matrix to apply or a set of local coordinates.
alignPD.ALIGN <optional>
0 The alignment of the text relative to the anchor position.
offsetnumber <optional>
0 An optional vertical offset given in font units.
Returns:
Returns this cached font to support method chaining.
- Type
- PD.Font
-
addTextToMeshBuilder(builder, text, matrix [, align] [, offset])
-
Adds positioned, scaled and aligned mesh geometry from a text string.
Parameters:
Name Type Argument Default Description builderPD.MeshBuilder The mesh builder to add the glyph data to.
textstring The string of characters to represent in the mesh.
matrixTHREE.Matrix4 The transformation matrix to multiply the geometry by.
alignPD.ALIGN <optional>
0 The alignment of the text relative to the anchor position.
offsetnumber <optional>
0 An optional vertical offset given in font units.
Returns:
Returns this cached font to support method chaining.
- Type
- PD.Font
-
addTextToPolyMesh(mesh, text, matrix [, align] [, offset])
-
Adds positioned, scaled and aligned mesh geometry from a text string.
Parameters:
Name Type Argument Default Description meshPD.PolyMesh The dynamic mesh to add the text geometry to.
textstring The string of characters to represent in the mesh.
matrixTHREE.Matrix4 The transformation matrix to multiply the geometry by.
alignPD.ALIGN <optional>
0 The alignment of the text relative to the anchor position.
offsetnumber <optional>
0 An optional vertical offset given in font units.
Returns:
Returns this cached font to support method chaining.
- Type
- PD.Font
-
addTextToPolyMeshInLocalCoords(mesh, text, coords [, align] [, offset])
-
Adds positioned, scaled and aligned mesh geometry from a text string.
Parameters:
Name Type Argument Default Description meshPD.PolyMesh The dynamic mesh to add the text geometry to.
textstring The string of characters to represent in the mesh.
coordsPD.LocalCoordinates The local coordinate system to use.
alignPD.ALIGN <optional>
0 The alignment of the text relative to the anchor position.
offsetnumber <optional>
0 An optional vertical offset given in font units.
Returns:
Returns this cached font to support method chaining.
- Type
- PD.Font
-
addTextToShell(shell, poly, text [, xform] [, align] [, offset])
-
Adds positioned, scaled and aligned face geometry from a text string.
Parameters:
Name Type Argument Default Description shellPD.Shell The shell the facet belongs to.
polyPD.Polygon The polygonal facet to add the glyph into.
textstring The string of characters to represent in the mesh.
xformTHREE.Matrix4 | PD.LocalCoordinates <optional>
A transformation matrix to apply or a set of local coordinates.
alignPD.ALIGN <optional>
0 The alignment of the text relative to the anchor position.
offsetnumber <optional>
0 An optional vertical offset given in font units.
Returns:
Returns this cached font to support method chaining.
- Type
- PD.Font
-
generateShapes(text, size)
-
Generates an array of shapes representing the text at the given size.
This works in exactly the same way as the
generateShapes()method on aTHREE.Font. It does not use any cached glyphs, but generates the shapes in the right position within the string and at the given size.Parameters:
Name Type Default Description textstring The string of characters to represent as shapes.
sizenumber 1000 The size of each character shape in model units.
Returns:
Returns an array of shapes representing the text.
- Type
- Array
-
generateTextAsPolygons(text, pos, size, align)
-
Generates an array of polygons from a positioned, scaled and aligned text string.
NOTE: Some characters such as double quotes will actually require two polygons to represent them, so there is not always a direct correspondence between the index of a character in the text string and the resulting polygon.
Parameters:
Name Type Default Description textstring The string of characters to represent as polygons.
posTHREE.Vector3 The anchor position of the text block in model space.
sizeTHREE.Vector2 | number 250 The size of each character as a number or vector, in model units.
alignPD.ALIGN 0 The alignment of the text relative to the anchor position.
Returns:
Returns an array of polygons representing the text.
- Type
- Array
-
generateTextAsShapes(text, pos, size, align)
-
Generates an array of positioned, scaled and aligned text shapes.
Parameters:
Name Type Default Description textstring The string of characters to represent as shapes.
posTHREE.Vector3 The anchor position of the text block in model space.
sizenumber 250 The size of each character shape in model units.
alignPD.ALIGN 0 The alignment of the text relative to the anchor position.
Returns:
Returns an array of shapes representing the text.
- Type
- Array
-
getTextHeight(text)
-
Calculates the total height of all lines in the text string, in font units.
Calculated line heights are given in font units. To obtain the actual height, simply multiply the returned height value by the size of font you want.
Parameters:
Name Type Description textstring A single or multi-line text string to compute the height of.
Returns:
Returns the total line height in font units.
- Type
- number
-
getTextWidth(text)
-
Calculates the width of the widest line in the text string in font units.
Calculated line widths are given in font units. To obtain the actual width, simply multiply the returned width value by the size of font you want.
In order to compute the width of each character, calling this method will also update the cache with the characters in the text.
Parameters:
Name Type Description textstring A single or multi-line text string to compute the width of.
Returns:
Returns the total normalised line width in font units.
- Type
- number
-
initialiseCache(text)
-
Seeds the glyph cache with characters in the given string.
Parameters:
Name Type Description textstring A text string containing the characters to seed the cache with.
Returns:
Returns this cached font to support method chaining.
- Type
- PD.Font