@mlightcad/mtext-renderer 0.10.0 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +523 -523
- package/dist/index.js +25481 -0
- package/dist/index.umd.cjs +14 -0
- package/dist/mtext-renderer-worker.js +30383 -0
- package/lib/cache/fontCacheManager.d.ts +71 -0
- package/lib/cache/index.d.ts +1 -0
- package/lib/cache/schema.d.ts +27 -0
- package/lib/common/eventManager.d.ts +26 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/utils.d.ts +11 -0
- package/lib/font/baseFont.d.ts +81 -0
- package/lib/font/baseTextShape.d.ts +17 -0
- package/lib/font/charGeometryCache.d.ts +43 -0
- package/lib/font/defaultFontLoader.d.ts +50 -0
- package/lib/font/font.d.ts +25 -0
- package/lib/font/fontFactory.d.ts +31 -0
- package/lib/font/fontLoader.d.ts +58 -0
- package/lib/font/fontManager.d.ts +192 -0
- package/lib/font/index.d.ts +7 -0
- package/lib/font/meshFont.d.ts +138 -0
- package/lib/font/meshFontParser.d.ts +10 -0
- package/lib/font/meshTextShape.d.ts +33 -0
- package/lib/font/normalComputationToggle.d.ts +57 -0
- package/lib/font/shxFont.d.ts +62 -0
- package/lib/font/shxTextShape.d.ts +29 -0
- package/lib/font/threeFont.d.ts +50 -0
- package/lib/index.d.ts +5 -0
- package/lib/renderer/charBoxUtils.d.ts +4 -0
- package/lib/renderer/defaultStyleManager.d.ts +18 -0
- package/lib/renderer/index.d.ts +3 -0
- package/lib/renderer/mtext.d.ts +134 -0
- package/lib/renderer/mtextProcessor.d.ts +249 -0
- package/lib/renderer/styleManager.d.ts +20 -0
- package/lib/renderer/types.d.ts +199 -0
- package/lib/worker/baseRenderer.d.ts +92 -0
- package/lib/worker/index.d.ts +5 -0
- package/lib/worker/mainThreadRenderer.d.ts +49 -0
- package/lib/worker/mtextWorker.d.ts +1 -0
- package/lib/worker/unifiedRenderer.d.ts +69 -0
- package/lib/worker/webWorkerRenderer.d.ts +190 -0
- package/package.json +2 -2
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { FontData as ThreeFontData } from 'three/examples/jsm/loaders/FontLoader.js';
|
|
2
|
+
import { BaseFont } from './baseFont';
|
|
3
|
+
import { FontData } from './font';
|
|
4
|
+
import { MeshTextShape } from './meshTextShape';
|
|
5
|
+
import { ThreeFont } from './threeFont';
|
|
6
|
+
export interface GlyphCommand {
|
|
7
|
+
type: string;
|
|
8
|
+
x?: number;
|
|
9
|
+
y?: number;
|
|
10
|
+
x1?: number;
|
|
11
|
+
y1?: number;
|
|
12
|
+
x2?: number;
|
|
13
|
+
y2?: number;
|
|
14
|
+
}
|
|
15
|
+
interface MeshGlyph {
|
|
16
|
+
ha: number;
|
|
17
|
+
x_min: number;
|
|
18
|
+
x_max: number;
|
|
19
|
+
o?: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Represents the data structure for mesh-based fonts.
|
|
23
|
+
* Extends the base ThreeFontData interface with additional properties specific to mesh fonts.
|
|
24
|
+
*/
|
|
25
|
+
export interface MeshFontData extends ThreeFontData {
|
|
26
|
+
/** A map of glyphs keyed by character */
|
|
27
|
+
glyphs: Record<string, MeshGlyph>;
|
|
28
|
+
/** The full font family name */
|
|
29
|
+
familyName: string;
|
|
30
|
+
/** The font ascender */
|
|
31
|
+
ascender: number;
|
|
32
|
+
/** The font descender */
|
|
33
|
+
descender: number;
|
|
34
|
+
/** Underline position in font units */
|
|
35
|
+
underlinePosition: number;
|
|
36
|
+
/** Underline thickness in font units */
|
|
37
|
+
underlineThickness: number;
|
|
38
|
+
/** Font bounding box */
|
|
39
|
+
boundingBox: {
|
|
40
|
+
xMin: number;
|
|
41
|
+
xMax: number;
|
|
42
|
+
yMin: number;
|
|
43
|
+
yMax: number;
|
|
44
|
+
};
|
|
45
|
+
/** Font resolution (usually unitsPerEm) */
|
|
46
|
+
resolution: number;
|
|
47
|
+
/** Scale factor used to adjust the size of characters when rendering */
|
|
48
|
+
scaleFactor: number;
|
|
49
|
+
/** Original font information table */
|
|
50
|
+
original_font_information: Record<string, string>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Represents a mesh-based font (e.g., TTF, OTF, WOFF).
|
|
54
|
+
* This class extends BaseFont to provide specific functionality for mesh fonts,
|
|
55
|
+
* including character shape generation, scale factor management, and
|
|
56
|
+
* **lazy glyph loading** to reduce memory consumption.
|
|
57
|
+
*/
|
|
58
|
+
export declare class MeshFont extends BaseFont {
|
|
59
|
+
/** Scale factor used to adjust the size of characters */
|
|
60
|
+
protected scaleFactor?: number;
|
|
61
|
+
/** Three.js font instance used for rendering */
|
|
62
|
+
readonly font: ThreeFont;
|
|
63
|
+
/** The type of font (always 'mesh' for this class) */
|
|
64
|
+
readonly type = "mesh";
|
|
65
|
+
/** The parsed font data */
|
|
66
|
+
readonly data: MeshFontData;
|
|
67
|
+
/** Internal opentype.js font instance used for on-demand glyph parsing */
|
|
68
|
+
private readonly opentypeFont;
|
|
69
|
+
/** Glyph cache to limit memory usage */
|
|
70
|
+
private readonly glyphCache;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a new instance of MeshFont.
|
|
73
|
+
* @param fontData - Either a MeshFontData object containing font information or an ArrayBuffer containing raw font data
|
|
74
|
+
*/
|
|
75
|
+
constructor(fontData: FontData);
|
|
76
|
+
/**
|
|
77
|
+
* Parses a mesh font from raw binary data.
|
|
78
|
+
* This function converts raw font data (e.g., TTF, OTF, WOFF) into a MeshFontData object
|
|
79
|
+
* that can be used by the MeshFont class.
|
|
80
|
+
*
|
|
81
|
+
* @param data - The raw font data as an ArrayBuffer
|
|
82
|
+
* @returns An object containing the opentype font and parsed metadata
|
|
83
|
+
*/
|
|
84
|
+
private parseMeshFont;
|
|
85
|
+
/**
|
|
86
|
+
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
87
|
+
* @param char - The character to check
|
|
88
|
+
* @returns True if this font contains glyph of the specified character. Otherwise, return false.
|
|
89
|
+
*/
|
|
90
|
+
hasChar(char: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Return true if this font contains glyph of the specified character code. Otherwise, return false.
|
|
93
|
+
* @param code - The character code to check
|
|
94
|
+
* @returns True if this font contains glyph of the specified character code. Otherwise, return false.
|
|
95
|
+
*/
|
|
96
|
+
hasCode(code: number): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Loads glyph data lazily when requested.
|
|
99
|
+
* Parsed glyphs are cached in an LRU cache to limit memory usage.
|
|
100
|
+
* @param char - The character whose glyph should be loaded
|
|
101
|
+
*/
|
|
102
|
+
private _loadGlyphIfNeeded;
|
|
103
|
+
/**
|
|
104
|
+
* Generates shapes for a text string
|
|
105
|
+
* @param text - The text to generate shapes for
|
|
106
|
+
* @param size - The size of the text
|
|
107
|
+
* @returns Array of shapes representing the text
|
|
108
|
+
*/
|
|
109
|
+
generateShapes(text: string, size: number): import('three').Shape[];
|
|
110
|
+
/**
|
|
111
|
+
* Gets the shape data for a specific character at a given size.
|
|
112
|
+
* @param char - The character to get the shape for
|
|
113
|
+
* @param size - The desired size of the character
|
|
114
|
+
* @returns The shape data for the character, or undefined if not found
|
|
115
|
+
*/
|
|
116
|
+
getCharShape(char: string, size: number): MeshTextShape | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Gets the shape data for a specific character unicode at a given size.
|
|
119
|
+
* @param code - The character unicode to get the shape for
|
|
120
|
+
* @param size - The desired size of the character
|
|
121
|
+
* @returns The shape data for the character unicode, or undefined if not found
|
|
122
|
+
*/
|
|
123
|
+
getCodeShape(code: number, size: number): MeshTextShape | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Gets the scale factor for this font.
|
|
126
|
+
* This is used to adjust the size of characters when rendering.
|
|
127
|
+
* @returns The scale factor as a number
|
|
128
|
+
*/
|
|
129
|
+
getScaleFactor(): number;
|
|
130
|
+
/**
|
|
131
|
+
* Gets the shape to display when a character is not found in the font.
|
|
132
|
+
* Uses "?" as a replacement character.
|
|
133
|
+
* @param size - The desired size of the not found shape
|
|
134
|
+
* @returns The shape data for the not found indicator
|
|
135
|
+
*/
|
|
136
|
+
getNotFoundTextShape(size: number): MeshTextShape;
|
|
137
|
+
}
|
|
138
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MeshFontData } from './meshFont';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a mesh font from raw binary data.
|
|
4
|
+
* This function converts raw font data (e.g., TTF, OTF, WOFF) into a MeshFontData object
|
|
5
|
+
* that can be used by the MeshFont class.
|
|
6
|
+
*
|
|
7
|
+
* @param data - The raw font data as an ArrayBuffer
|
|
8
|
+
* @returns A MeshFontData object containing the parsed font information
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseMeshFont(data: ArrayBuffer): MeshFontData;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BaseTextShape } from './baseTextShape';
|
|
2
|
+
import { MeshFont } from './meshFont';
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a text shape for mesh-based fonts (e.g., TTF, OTF, WOFF).
|
|
6
|
+
* This class extends BaseTextShape to provide specific functionality for mesh fonts,
|
|
7
|
+
* including 3D geometry generation and character width calculation.
|
|
8
|
+
*/
|
|
9
|
+
export declare class MeshTextShape extends BaseTextShape {
|
|
10
|
+
/**
|
|
11
|
+
* Flag to indicate whether the character is found in the font.
|
|
12
|
+
* Used to track if the character exists in the font's glyph set.
|
|
13
|
+
*/
|
|
14
|
+
isFound: boolean;
|
|
15
|
+
private readonly char;
|
|
16
|
+
private readonly font;
|
|
17
|
+
private readonly fontSize;
|
|
18
|
+
constructor(char: string, fontSize: number, font: MeshFont);
|
|
19
|
+
/**
|
|
20
|
+
* Converts the text shape to a THREE.js geometry.
|
|
21
|
+
* This is used for 3D rendering of the text.
|
|
22
|
+
* @returns A THREE.js BufferGeometry representing the text shape
|
|
23
|
+
*/
|
|
24
|
+
toGeometry(): THREE.BufferGeometry;
|
|
25
|
+
/**
|
|
26
|
+
* Calculates the width of a character in the font.
|
|
27
|
+
* @param char - The character to calculate width for
|
|
28
|
+
* @param fontSize - The size of the font in pixels
|
|
29
|
+
* @param font - The mesh font to use
|
|
30
|
+
* @returns The width of the character in pixels
|
|
31
|
+
*/
|
|
32
|
+
private getCharWidth;
|
|
33
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for temporarily disabling `BufferGeometry.computeVertexNormals`.
|
|
3
|
+
*
|
|
4
|
+
* By default, Three.js computes vertex normals for many geometries,
|
|
5
|
+
* which can be unnecessary (e.g., when using `MeshBasicMaterial` that does not require lighting).
|
|
6
|
+
* This class lets you temporarily replace `computeVertexNormals` with a no-op
|
|
7
|
+
* to save CPU time during geometry creation.
|
|
8
|
+
*
|
|
9
|
+
* Example:
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { TextGeometry } from "three/examples/jsm/geometries/TextGeometry.js";
|
|
12
|
+
* import { NormalComputationToggle } from "./NormalComputationToggle";
|
|
13
|
+
*
|
|
14
|
+
* // Create geometry without computing normals
|
|
15
|
+
* const textGeom = NormalComputationToggle.runWithoutNormals(() =>
|
|
16
|
+
* new TextGeometry("Fast!", { font, size: 1, height: 0.2 })
|
|
17
|
+
* );
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class NormalComputationToggle {
|
|
21
|
+
/**
|
|
22
|
+
* Stores the original `computeVertexNormals` method from BufferGeometry.
|
|
23
|
+
*/
|
|
24
|
+
private static originalComputeVertexNormals;
|
|
25
|
+
/**
|
|
26
|
+
* Dummy replacement for `computeVertexNormals` that does nothing.
|
|
27
|
+
*/
|
|
28
|
+
private static dummyComputeVertexNormals;
|
|
29
|
+
/**
|
|
30
|
+
* Disable vertex normal computation globally.
|
|
31
|
+
*
|
|
32
|
+
* After calling this, all calls to `computeVertexNormals`
|
|
33
|
+
* will do nothing until {@link restore} is called.
|
|
34
|
+
*/
|
|
35
|
+
static disable(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Restore the original `computeVertexNormals` implementation.
|
|
38
|
+
*/
|
|
39
|
+
static restore(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Execute a function with normal computation disabled,
|
|
42
|
+
* then automatically restore afterwards.
|
|
43
|
+
*
|
|
44
|
+
* This is the safest way to create geometries without normals.
|
|
45
|
+
*
|
|
46
|
+
* Example:
|
|
47
|
+
* ```ts
|
|
48
|
+
* const geom = NormalComputationToggle.runWithoutNormals(() =>
|
|
49
|
+
* new TextGeometry("World", { font, size: 1, height: 0.2 })
|
|
50
|
+
* );
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param fn - A callback that creates the geometry.
|
|
54
|
+
* @returns The result of the callback, e.g., a geometry.
|
|
55
|
+
*/
|
|
56
|
+
static runWithoutNormals<T>(fn: () => T): T;
|
|
57
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ShxFontData } from '@mlightcad/shx-parser';
|
|
2
|
+
import { BaseFont } from './baseFont';
|
|
3
|
+
import { FontData } from './font';
|
|
4
|
+
import { ShxTextShape } from './shxTextShape';
|
|
5
|
+
/**
|
|
6
|
+
* ShxFont is a class that extends BaseFont and represents a SHX font.
|
|
7
|
+
* It provides methods to generate shapes for text and retrieve character shapes.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ShxFont extends BaseFont {
|
|
10
|
+
/** Internal shx font instance */
|
|
11
|
+
private readonly font;
|
|
12
|
+
readonly type = "shx";
|
|
13
|
+
readonly data: ShxFontData;
|
|
14
|
+
constructor(fontData: FontData);
|
|
15
|
+
/**
|
|
16
|
+
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
17
|
+
* @param char - The character to check
|
|
18
|
+
* @returns True if this font contains glyph of the specified character. Otherwise, return false.
|
|
19
|
+
*/
|
|
20
|
+
hasChar(char: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Return true if this font contains glyph of the specified character code. Otherwise, return false.
|
|
23
|
+
* @param code - The character code to check
|
|
24
|
+
* @returns True if this font contains glyph of the specified character code. Otherwise, return false.
|
|
25
|
+
*/
|
|
26
|
+
hasCode(code: number): boolean;
|
|
27
|
+
generateShapes(text: string, size: number): ShxTextShape[];
|
|
28
|
+
/**
|
|
29
|
+
* SHX font always has fixed scale factor 1.
|
|
30
|
+
* @returns Always return value 1
|
|
31
|
+
*/
|
|
32
|
+
getScaleFactor(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Gets the shape data for a specific character at a given size.
|
|
35
|
+
* If the font type is BIGFONT, please use getCodeShape to get the shape data
|
|
36
|
+
* because the character code for BIGFONT isn't unicode.
|
|
37
|
+
* @param char - The character to get the shape for
|
|
38
|
+
* @param size - The desired size of the character
|
|
39
|
+
* @returns The shape data for the character, or undefined if not found
|
|
40
|
+
*/
|
|
41
|
+
getCharShape(char: string, size: number): ShxTextShape | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the shape data for a specific character code at a given size.
|
|
44
|
+
* The passed code must the code stored in font instead of unicode.
|
|
45
|
+
* - Unicode shx font uses unicode as character code.
|
|
46
|
+
* - Bigfont uses a custom encoding for double-byte characters.
|
|
47
|
+
* @param code - The character code to get the shape for
|
|
48
|
+
* @param size - The desired size of the character
|
|
49
|
+
* @returns The shape data for the character code, or undefined if not found
|
|
50
|
+
*/
|
|
51
|
+
getCodeShape(code: number, size: number): ShxTextShape | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* For an unsupported char, use "?" as a replacement.
|
|
54
|
+
*/
|
|
55
|
+
getNotFoundTextShape(size: number): ShxTextShape | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Gets encoded code of the specified character according to font character encoding
|
|
58
|
+
* @param char - The character to get its code
|
|
59
|
+
* @returns Returns encoded code of the specified character
|
|
60
|
+
*/
|
|
61
|
+
private getCode;
|
|
62
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Point, ShxShape } from '@mlightcad/shx-parser';
|
|
2
|
+
import { BaseTextShape } from './baseTextShape';
|
|
3
|
+
import { ShxFont } from './shxFont';
|
|
4
|
+
import * as THREE from 'three';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a text shape for SHX fonts.
|
|
7
|
+
* This class extends BaseTextShape to provide specific functionality for SHX fonts,
|
|
8
|
+
* including shape data management and dimension calculations.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ShxTextShape extends BaseTextShape {
|
|
11
|
+
/** The shape data for this character */
|
|
12
|
+
private readonly code;
|
|
13
|
+
private readonly shape;
|
|
14
|
+
private readonly font;
|
|
15
|
+
private readonly fontSize;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new instance of ShxTextShape
|
|
18
|
+
* @param code - The character code this shape represents
|
|
19
|
+
* @param shape - The shape data for this character
|
|
20
|
+
*/
|
|
21
|
+
constructor(code: number, fontSize: number, shape: ShxShape, font: ShxFont);
|
|
22
|
+
protected calcWidth(): number;
|
|
23
|
+
offset(offset: Point): ShxTextShape;
|
|
24
|
+
/**
|
|
25
|
+
* Converts the text shape to a THREE.js geometry
|
|
26
|
+
* @returns A THREE.js BufferGeometry representing the text shape
|
|
27
|
+
*/
|
|
28
|
+
toGeometry(): THREE.BufferGeometry<THREE.NormalBufferAttributes>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Shape } from 'three';
|
|
2
|
+
import { Font } from 'three/examples/jsm/loaders/FontLoader.js';
|
|
3
|
+
type Direction = 'ltr' | 'rtl' | 'tb';
|
|
4
|
+
/**
|
|
5
|
+
* Extended Font that fixes inner holes for problematic fonts like SimSun.
|
|
6
|
+
* Certain characters have incorrect inner contours (holes), e.g., 面, 限, 用, 色, 8.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ThreeFont extends Font {
|
|
9
|
+
/**
|
|
10
|
+
* Generates geometry shapes from the given text and size.
|
|
11
|
+
*
|
|
12
|
+
* Algorithm overview:
|
|
13
|
+
* 1. Split the input text into individual characters.
|
|
14
|
+
* 2. For each character:
|
|
15
|
+
* a. Retrieve the glyph data from the font.
|
|
16
|
+
* b. Convert the glyph outline commands into a ShapePath.
|
|
17
|
+
* - 'm' → moveTo
|
|
18
|
+
* - 'l' → lineTo
|
|
19
|
+
* - 'q' → quadraticCurveTo
|
|
20
|
+
* - 'b' → cubic bezierCurveTo
|
|
21
|
+
* c. Apply scaling to match the requested font size.
|
|
22
|
+
* d. Apply offsets for proper placement (supports multiple lines and directions).
|
|
23
|
+
* 3. Handle text direction:
|
|
24
|
+
* - 'ltr': left-to-right
|
|
25
|
+
* - 'rtl': right-to-left (characters reversed)
|
|
26
|
+
* - 'tb': top-to-bottom (vertical layout)
|
|
27
|
+
* 4. Collect all ShapePaths for the text.
|
|
28
|
+
* 5. Convert each ShapePath into one or more Shape objects:
|
|
29
|
+
* a. Sample points along each subPath to approximate geometry.
|
|
30
|
+
* b. Determine which subPaths are outer contours and which are holes:
|
|
31
|
+
* - For each subPath, check if it is fully contained inside another polygon.
|
|
32
|
+
* - Assign the smallest containing polygon as its parent.
|
|
33
|
+
* c. Compute the relative depth of each subPath to handle nested holes.
|
|
34
|
+
* d. Reverse curves if necessary to maintain correct clockwise/counterclockwise winding:
|
|
35
|
+
* - Outer contours: CCW
|
|
36
|
+
* - Holes: CW
|
|
37
|
+
* e. Build Shape objects with holes properly assigned.
|
|
38
|
+
* 6. Return the final array of Shape objects ready for geometry creation.
|
|
39
|
+
*
|
|
40
|
+
* This algorithm ensures that complex characters with multiple independent contours
|
|
41
|
+
* (including intersecting subpaths or holes) are rendered correctly.
|
|
42
|
+
*
|
|
43
|
+
* @param text - input string to convert to shapes
|
|
44
|
+
* @param size - font size in units (default 100)
|
|
45
|
+
* @param direction - text direction ('ltr', 'rtl', 'tb')
|
|
46
|
+
* @returns array of Shape objects with proper holes and contours
|
|
47
|
+
*/
|
|
48
|
+
generateShapes(text: string, size?: number, direction?: Direction): Shape[];
|
|
49
|
+
}
|
|
50
|
+
export {};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CharBox, CharBoxType } from './types';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
export declare function normalizeBox(box?: THREE.Box3): THREE.Box3 | undefined;
|
|
4
|
+
export declare function buildCharBoxesFromObject(objectCharBoxes: CharBox[], matrixWorld: THREE.Matrix4, charBoxType?: CharBoxType): CharBox[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { StyleManager } from './styleManager';
|
|
2
|
+
import { StyleTraits } from './types';
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
/**
|
|
5
|
+
* Class to manage basic text style
|
|
6
|
+
*/
|
|
7
|
+
export declare class DefaultStyleManager implements StyleManager {
|
|
8
|
+
private lineBasicMaterials;
|
|
9
|
+
private meshBasicMaterials;
|
|
10
|
+
unsupportedTextStyles: Record<string, number>;
|
|
11
|
+
getMeshBasicMaterial(traits: StyleTraits): THREE.Material;
|
|
12
|
+
getLineBasicMaterial(traits: StyleTraits): THREE.Material;
|
|
13
|
+
/**
|
|
14
|
+
* Builds a stable material key from traits.
|
|
15
|
+
* Key differs for shader vs basic, ByLayer vs ByEntity.
|
|
16
|
+
*/
|
|
17
|
+
protected buildKey(traits: StyleTraits): string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { FontManager } from '../font';
|
|
2
|
+
import { StyleManager } from './styleManager';
|
|
3
|
+
import { ColorSettings, MTextData, MTextLayout, TextStyle } from './types';
|
|
4
|
+
import * as THREE from 'three';
|
|
5
|
+
/**
|
|
6
|
+
* Represents an AutoCAD MText object in Three.js.
|
|
7
|
+
* This class extends THREE.Object3D to provide MText rendering capabilities,
|
|
8
|
+
* including text layout, alignment, and transformation.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MText extends THREE.Object3D {
|
|
11
|
+
/** The text style configuration for this MText object */
|
|
12
|
+
private _style;
|
|
13
|
+
/** The flag to indicate whether fonts specified in style are loaded */
|
|
14
|
+
private _fontsInStyleLoaded;
|
|
15
|
+
/** The style manager instance for handling text styles */
|
|
16
|
+
private _styleManager;
|
|
17
|
+
/** The font manager instance for handling font operations */
|
|
18
|
+
private _fontManager;
|
|
19
|
+
/** Color settings used to decided font color */
|
|
20
|
+
private _colorSettings;
|
|
21
|
+
/** The bounding box of the entire MText object */
|
|
22
|
+
private _box;
|
|
23
|
+
/** Lazily built layout data (line geometry + char boxes). */
|
|
24
|
+
private _layoutData;
|
|
25
|
+
/** Raw mtext data to draw on demand */
|
|
26
|
+
private _mtextData;
|
|
27
|
+
/**
|
|
28
|
+
* Extracts all unique font names used in an MText string.
|
|
29
|
+
* This function searches for font commands in the format \f{fontname}| or \f{fontname}; and returns a set of unique font names.
|
|
30
|
+
* Font names are converted to lowercase to ensure case-insensitive uniqueness.
|
|
31
|
+
*
|
|
32
|
+
* @param mtext - The MText string to analyze for font names
|
|
33
|
+
* @param removeExtension - Whether to remove font file extensions (e.g., .ttf, .shx) from font names. Defaults to false.
|
|
34
|
+
* @returns A Set containing all unique font names found in the MText string, converted to lowercase
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const mtext = "\\fArial.ttf|Hello\\fTimes New Roman.otf|World";
|
|
38
|
+
* const fonts = getFonts(mtext, true);
|
|
39
|
+
* // Returns: Set(2) { "arial", "times new roman" }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
static getFonts(mtext: string, removeExtension?: boolean): Set<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new instance of MText.
|
|
45
|
+
* @param text - The MText data containing text content and properties
|
|
46
|
+
* @param style - The text style configuration
|
|
47
|
+
* @param styleManager - The style manager instance
|
|
48
|
+
* @param fontManager - The font manager instance
|
|
49
|
+
* @param colorSettings - Color settings used to decided font color
|
|
50
|
+
*/
|
|
51
|
+
constructor(text: MTextData, style: TextStyle, styleManager: StyleManager, fontManager: FontManager, colorSettings?: ColorSettings);
|
|
52
|
+
/**
|
|
53
|
+
* Gets the font manager instance associated with this MText object.
|
|
54
|
+
* @returns The FontManager instance
|
|
55
|
+
*/
|
|
56
|
+
get fontManager(): FontManager;
|
|
57
|
+
/**
|
|
58
|
+
* Remove the current object from its parent and release geometry and material resource used
|
|
59
|
+
* by the current object.
|
|
60
|
+
*/
|
|
61
|
+
dispose(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Draw the MText object. This method loads required fonts on demand and builds the object graph.
|
|
64
|
+
*/
|
|
65
|
+
asyncDraw(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Draw the MText object. This method assumes that fonts needed are loaded. If font needed
|
|
68
|
+
* not found, the default font will be used.
|
|
69
|
+
*/
|
|
70
|
+
syncDraw(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Gets the style manager instance associated with this MText object.
|
|
73
|
+
* @returns The StyleManager instance
|
|
74
|
+
*/
|
|
75
|
+
get styleManager(): StyleManager;
|
|
76
|
+
/**
|
|
77
|
+
* Gets the text style configuration for this MText object.
|
|
78
|
+
* @returns The TextStyle configuration
|
|
79
|
+
*/
|
|
80
|
+
get textStyle(): TextStyle;
|
|
81
|
+
/**
|
|
82
|
+
* Gets or sets the bounding box of this MText object.
|
|
83
|
+
* The bounding box is calculated without considering the transformation matrix.
|
|
84
|
+
* To get the bounding box with transformation, call `applyMatrix4` on this box.
|
|
85
|
+
*/
|
|
86
|
+
get box(): THREE.Box3;
|
|
87
|
+
set box(box: THREE.Box3);
|
|
88
|
+
/** Creates text layout data for cursor/picking/debug usage on demand. */
|
|
89
|
+
createLayoutData(): MTextLayout;
|
|
90
|
+
/**
|
|
91
|
+
* Calculates intersections between a ray and this MText object.
|
|
92
|
+
* Overrides the base THREE.Object3D raycast method to use the text's bounding boxes.
|
|
93
|
+
* @param raycaster - The raycaster to use for intersection testing
|
|
94
|
+
* @param intersects - Array to store intersection results
|
|
95
|
+
*/
|
|
96
|
+
raycast(raycaster: THREE.Raycaster, intersects: THREE.Intersection[]): void;
|
|
97
|
+
/**
|
|
98
|
+
* Loads and processes MText data to create a Three.js object.
|
|
99
|
+
* @param mtextData - The MText data to process
|
|
100
|
+
* @param style - The text style configuration
|
|
101
|
+
* @returns The created Three.js object, or undefined if creation fails
|
|
102
|
+
*/
|
|
103
|
+
private loadMText;
|
|
104
|
+
/**
|
|
105
|
+
* Creates a group of text elements from MText data.
|
|
106
|
+
* @param mtextData - The MText data to process
|
|
107
|
+
* @param style - The text style configuration
|
|
108
|
+
* @returns An object containing the created Three.js object and its height
|
|
109
|
+
*/
|
|
110
|
+
private createMTextGroup;
|
|
111
|
+
/**
|
|
112
|
+
* Calculates the anchor point for text positioning based on alignment and flow direction.
|
|
113
|
+
* @param width - The width of the text
|
|
114
|
+
* @param height - The height of the text
|
|
115
|
+
* @param attachmentPoint - The attachment point for text alignment
|
|
116
|
+
* @param flowDirection - The text flow direction
|
|
117
|
+
* @returns The calculated anchor point coordinates
|
|
118
|
+
*/
|
|
119
|
+
private calculateAnchorPoint;
|
|
120
|
+
/**
|
|
121
|
+
* Recursively calculates bounding boxes for an object and its children.
|
|
122
|
+
* @param object - The Three.js object to process
|
|
123
|
+
* @param boxes - Array to store the calculated bounding boxes
|
|
124
|
+
*/
|
|
125
|
+
private getLayout;
|
|
126
|
+
private updateBoxFromObject;
|
|
127
|
+
/**
|
|
128
|
+
* Remove the specified object from its parent and release geometry and material resource used
|
|
129
|
+
* by the object.
|
|
130
|
+
* @param obj - Input object to dispose
|
|
131
|
+
*/
|
|
132
|
+
private disposeThreeObject;
|
|
133
|
+
private getFontName;
|
|
134
|
+
}
|