@mlightcad/mtext-renderer 0.11.7 → 0.11.9
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/dist/index.js +2924 -2363
- package/dist/index.umd.cjs +8 -8
- package/dist/mtext-renderer-worker.js +3733 -3172
- package/lib/common/lruCache.d.ts +63 -0
- package/lib/font/baseTextShape.d.ts +4 -0
- package/lib/font/charGeometryCache.d.ts +3 -2
- package/lib/font/meshTextShape.d.ts +2 -0
- package/lib/font/shxFont.d.ts +4 -0
- package/lib/font/shxTextShape.d.ts +4 -0
- package/lib/font/textGeometryBuilder.d.ts +47 -0
- package/lib/renderer/mtextProcessor.d.ts +288 -17
- package/package.json +2 -2
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback invoked when an entry is removed from the cache, either because it
|
|
3
|
+
* was evicted to make room for a new entry, replaced by a different value, or
|
|
4
|
+
* cleared explicitly.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam K - The cache key type.
|
|
7
|
+
* @typeParam V - The cache value type.
|
|
8
|
+
*/
|
|
9
|
+
export type LRUCacheEvictHandler<K, V> = (key: K, value: V) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Simple least-recently-used cache with a fixed maximum size.
|
|
12
|
+
*
|
|
13
|
+
* Entries are ordered by access time: {@link get} and {@link set} move a key to
|
|
14
|
+
* the most-recently-used position. When the cache is full, the oldest entry is
|
|
15
|
+
* evicted before inserting a new one.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam K - The cache key type.
|
|
18
|
+
* @typeParam V - The cache value type.
|
|
19
|
+
*/
|
|
20
|
+
export declare class LRUCache<K, V> {
|
|
21
|
+
private readonly maxSize;
|
|
22
|
+
private readonly onEvict?;
|
|
23
|
+
private readonly map;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an LRU cache with the given capacity and optional eviction handler.
|
|
26
|
+
*
|
|
27
|
+
* @param maxSize - Maximum number of entries to retain. Defaults to 4096.
|
|
28
|
+
* @param onEvict - Optional callback invoked for each evicted or replaced value.
|
|
29
|
+
*/
|
|
30
|
+
constructor(maxSize?: number, onEvict?: LRUCacheEvictHandler<K, V>);
|
|
31
|
+
/**
|
|
32
|
+
* Returns the value for `key` and marks it as most recently used.
|
|
33
|
+
*
|
|
34
|
+
* @param key - The cache key to look up.
|
|
35
|
+
* @returns The cached value, or `undefined` if the key is not present.
|
|
36
|
+
*/
|
|
37
|
+
get(key: K): V | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Stores `value` under `key` and marks it as most recently used.
|
|
40
|
+
*
|
|
41
|
+
* If the key already exists, its previous value is passed to {@link onEvict}
|
|
42
|
+
* when the new value differs. If the cache is at capacity, the least recently
|
|
43
|
+
* used entry is evicted before the new entry is inserted.
|
|
44
|
+
*
|
|
45
|
+
* @param key - The cache key to set.
|
|
46
|
+
* @param value - The value to store.
|
|
47
|
+
*/
|
|
48
|
+
set(key: K, value: V): void;
|
|
49
|
+
/**
|
|
50
|
+
* Returns whether `key` exists in the cache without updating its recency.
|
|
51
|
+
*
|
|
52
|
+
* @param key - The cache key to test.
|
|
53
|
+
* @returns True if the key is present; otherwise, false.
|
|
54
|
+
*/
|
|
55
|
+
has(key: K): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Removes all entries from the cache.
|
|
58
|
+
*
|
|
59
|
+
* If an {@link onEvict} handler was provided, it is invoked once per entry
|
|
60
|
+
* before the internal map is cleared.
|
|
61
|
+
*/
|
|
62
|
+
clear(): void;
|
|
63
|
+
}
|
|
@@ -14,4 +14,8 @@ export declare abstract class BaseTextShape extends THREE.Shape {
|
|
|
14
14
|
* @returns A THREE.js BufferGeometry representing the text shape
|
|
15
15
|
*/
|
|
16
16
|
abstract toGeometry(): THREE.BufferGeometry;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the shape has drawable stroke or mesh geometry (not advance-only).
|
|
19
|
+
*/
|
|
20
|
+
hasStrokeGeometry(): boolean;
|
|
17
21
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
/**
|
|
3
3
|
* Manages caching of font character geometries to improve text rendering performance.
|
|
4
|
+
* Uses an LRU policy so memory stays bounded when many (code, size) pairs are loaded.
|
|
4
5
|
*/
|
|
5
6
|
export declare class CharGeometryCache {
|
|
6
|
-
private cache;
|
|
7
|
-
constructor();
|
|
7
|
+
private readonly cache;
|
|
8
|
+
constructor(maxSize?: number);
|
|
8
9
|
/**
|
|
9
10
|
* Returns true if the geometry of the specified character code exists in the cache.
|
|
10
11
|
* Otherwise, returns false.
|
|
@@ -22,6 +22,8 @@ export declare class MeshTextShape extends BaseTextShape {
|
|
|
22
22
|
* @returns A THREE.js BufferGeometry representing the text shape
|
|
23
23
|
*/
|
|
24
24
|
toGeometry(): THREE.BufferGeometry;
|
|
25
|
+
/** @inheritdoc */
|
|
26
|
+
hasStrokeGeometry(): boolean;
|
|
25
27
|
/**
|
|
26
28
|
* Calculates the width of a character in the font.
|
|
27
29
|
* @param char - The character to calculate width for
|
package/lib/font/shxFont.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export declare class ShxFont extends BaseFont {
|
|
|
15
15
|
readonly type = "shx";
|
|
16
16
|
/** Parsed SHX font data used for glyph lookup and layout metrics. */
|
|
17
17
|
readonly data: ShxFontData;
|
|
18
|
+
/** Cached layout-ready {@link ShxTextShape} instances keyed by code and size. */
|
|
19
|
+
private readonly layoutShapeCache;
|
|
20
|
+
/** Cached BIGFONT character encodings keyed by input character. */
|
|
21
|
+
private readonly codeCache;
|
|
18
22
|
/**
|
|
19
23
|
* Creates a new SHX font wrapper.
|
|
20
24
|
* @param fontData - Font metadata and binary SHX data used to initialize the font.
|
|
@@ -13,6 +13,8 @@ export declare class ShxTextShape extends BaseTextShape {
|
|
|
13
13
|
private readonly shape;
|
|
14
14
|
private readonly font;
|
|
15
15
|
private readonly fontSize;
|
|
16
|
+
/** Lazily built geometry for this layout-ready shape instance. */
|
|
17
|
+
private geometry?;
|
|
16
18
|
/**
|
|
17
19
|
* Creates a new SHX text shape wrapper.
|
|
18
20
|
* @param code - The character code represented by this shape.
|
|
@@ -37,4 +39,6 @@ export declare class ShxTextShape extends BaseTextShape {
|
|
|
37
39
|
* @returns A BufferGeometry representing the text shape.
|
|
38
40
|
*/
|
|
39
41
|
toGeometry(): THREE.BufferGeometry<THREE.NormalBufferAttributes>;
|
|
42
|
+
/** @inheritdoc */
|
|
43
|
+
hasStrokeGeometry(): boolean;
|
|
40
44
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* One cached glyph geometry plus the world transform to apply at merge time.
|
|
4
|
+
*/
|
|
5
|
+
export interface TransformedLineGeometryEntry {
|
|
6
|
+
/** The source line-segment geometry for a single glyph. */
|
|
7
|
+
geometry: THREE.BufferGeometry;
|
|
8
|
+
/** The 4×4 transform matrix applied to each vertex before merging. */
|
|
9
|
+
matrix: THREE.Matrix4;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Builds a single line-segment {@link THREE.BufferGeometry} from many transformed glyph sources.
|
|
13
|
+
* Avoids per-character geometry allocation before merge.
|
|
14
|
+
*/
|
|
15
|
+
export declare class TextGeometryBuilder {
|
|
16
|
+
/**
|
|
17
|
+
* Merges indexed or non-indexed line geometries into one non-indexed {@link THREE.BufferGeometry}
|
|
18
|
+
* suitable for {@link THREE.LineSegments}.
|
|
19
|
+
* @param entries Glyph geometries paired with their world transforms.
|
|
20
|
+
* @returns A single non-indexed line geometry containing all transformed segments.
|
|
21
|
+
*/
|
|
22
|
+
static mergeLineGeometries(entries: TransformedLineGeometryEntry[]): THREE.BufferGeometry;
|
|
23
|
+
/**
|
|
24
|
+
* Counts how many line segments a geometry represents.
|
|
25
|
+
* Indexed geometries use index pairs; non-indexed geometries use consecutive position pairs.
|
|
26
|
+
* @param geometry The line geometry to inspect.
|
|
27
|
+
* @returns The number of line segments (each segment is two vertices).
|
|
28
|
+
*/
|
|
29
|
+
private static countLineSegments;
|
|
30
|
+
/**
|
|
31
|
+
* Applies a transform matrix to a single line geometry and returns a new non-indexed copy.
|
|
32
|
+
* @param geometry The source line geometry.
|
|
33
|
+
* @param matrix The transform applied to every vertex.
|
|
34
|
+
* @returns A new non-indexed line geometry with transformed positions.
|
|
35
|
+
*/
|
|
36
|
+
private static applyMatrixToLineGeometry;
|
|
37
|
+
/**
|
|
38
|
+
* Writes transformed line-segment vertices from a source geometry into a flat position buffer.
|
|
39
|
+
* Supports both indexed and non-indexed source geometries.
|
|
40
|
+
* @param geometry The source line geometry.
|
|
41
|
+
* @param matrix The transform applied to each vertex before writing.
|
|
42
|
+
* @param output The destination `Float32Array` (xyz per vertex).
|
|
43
|
+
* @param outputOffset The index in `output` at which writing begins.
|
|
44
|
+
* @returns The next write offset after all segments have been written.
|
|
45
|
+
*/
|
|
46
|
+
private static writeTransformedLineSegments;
|
|
47
|
+
}
|
|
@@ -49,22 +49,39 @@ export interface MTextFormatOptions {
|
|
|
49
49
|
collectCharBoxes?: boolean;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* Converts parsed MText tokens into positioned THREE.js geometry.
|
|
53
|
+
*
|
|
54
|
+
* Owns line breaking, inline/paragraph formatting, stack fractions, alignment,
|
|
55
|
+
* and per-character bounding boxes used for picking.
|
|
53
56
|
*/
|
|
54
57
|
export declare class MTextProcessor {
|
|
58
|
+
/** Active text style (font, height, oblique, big font, etc.). */
|
|
55
59
|
private _style;
|
|
60
|
+
/** Layer/block color resolution settings for ByLayer and ByBlock colors. */
|
|
56
61
|
private _colorSettings;
|
|
62
|
+
/** Factory for mesh and line materials used when flushing geometry batches. */
|
|
57
63
|
private _styleManager;
|
|
64
|
+
/** Resolves font files, glyph shapes, and font-format-specific metrics. */
|
|
58
65
|
private _fontManager;
|
|
66
|
+
/** Layout and formatting options supplied at construction time. */
|
|
59
67
|
private _options;
|
|
68
|
+
/** Accumulated vertical extent of completed lines, excluding the active line. */
|
|
60
69
|
private _totalHeight;
|
|
70
|
+
/** Horizontal pen position within the current visual line. */
|
|
61
71
|
private _hOffset;
|
|
72
|
+
/** Maximum logical pen advance seen across all processed visual lines. */
|
|
62
73
|
private _maxLineAdvance;
|
|
74
|
+
/** Vertical baseline position of the current visual line. */
|
|
63
75
|
private _vOffset;
|
|
76
|
+
/** Number of visual lines processed so far (1-based while rendering). */
|
|
64
77
|
private _lineCount;
|
|
78
|
+
/** THREE.js objects created for the current visual line before alignment. */
|
|
65
79
|
private _currentLineObjects;
|
|
80
|
+
/** Saved {@link RenderContext} snapshots for nested `{}` formatting groups. */
|
|
66
81
|
private _contextStack;
|
|
82
|
+
/** Active inline formatting and font metric state. */
|
|
67
83
|
private _currentContext;
|
|
84
|
+
/** Largest font size encountered on the current visual line. */
|
|
68
85
|
private _maxFontSize;
|
|
69
86
|
/**
|
|
70
87
|
* The current horizontal alignment for the paragraph.
|
|
@@ -76,25 +93,45 @@ export declare class MTextProcessor {
|
|
|
76
93
|
* so it persists until explicitly changed by another paragraph alignment command.
|
|
77
94
|
*/
|
|
78
95
|
private _currentHorizontalAlignment;
|
|
96
|
+
/** Whether the most recently appended char box targeted mesh or line geometry. */
|
|
79
97
|
private _lastCharBoxTarget;
|
|
98
|
+
/** True once a visible glyph has been placed on the current visual line. */
|
|
80
99
|
private _lineHasRenderableChar;
|
|
100
|
+
/**
|
|
101
|
+
* Font size recorded when advancing from an empty line; used to correct
|
|
102
|
+
* vertical position when the first glyph on the next line uses a different height.
|
|
103
|
+
*/
|
|
81
104
|
private _pendingEmptyLineFontSizeAdjust?;
|
|
105
|
+
/** Vertical layout metadata for each completed visual line. */
|
|
82
106
|
private _lineLayouts;
|
|
107
|
+
/** Character indices where automatic visual line breaks occurred. */
|
|
83
108
|
private _lineBreakIndices;
|
|
109
|
+
/** Running count of logical characters emitted into flushed geometry groups. */
|
|
84
110
|
private _processedCharCount;
|
|
111
|
+
/** Line glyph entries collected for batch geometry merge within a style segment. */
|
|
112
|
+
private _lineBatchEntries;
|
|
113
|
+
/** Current paragraph first-line indent in drawing units. */
|
|
85
114
|
private _currentIndent;
|
|
115
|
+
/** Current paragraph left margin in drawing units. */
|
|
86
116
|
private _currentLeftMargin;
|
|
117
|
+
/** Current paragraph right margin in drawing units. */
|
|
87
118
|
private _currentRightMargin;
|
|
88
119
|
/**
|
|
89
120
|
* Construct one instance of this class and initialize some properties with default values.
|
|
90
121
|
* @param style Input text style
|
|
122
|
+
* @param colorSettings Layer/block color resolution settings
|
|
91
123
|
* @param styleManager Input text style manager instance
|
|
92
124
|
* @param fontManager Input font manager instance
|
|
93
125
|
* @param options Input formating options
|
|
94
126
|
*/
|
|
95
127
|
constructor(style: TextStyle, colorSettings: ColorSettings, styleManager: StyleManager, fontManager: FontManager, options: MTextFormatOptions);
|
|
128
|
+
/**
|
|
129
|
+
* Font manager used to resolve glyphs, shapes, and font metrics.
|
|
130
|
+
*/
|
|
96
131
|
get fontManager(): FontManager;
|
|
132
|
+
/** Style manager used to create mesh and line materials. */
|
|
97
133
|
get styleManager(): StyleManager;
|
|
134
|
+
/** Active CAD text style for the entity being rendered. */
|
|
98
135
|
get textStyle(): TextStyle;
|
|
99
136
|
/**
|
|
100
137
|
* Total height of all lines of text
|
|
@@ -180,24 +217,31 @@ export declare class MTextProcessor {
|
|
|
180
217
|
* All of THREE.js objects in current line. It contains objects in all of sections of this line.
|
|
181
218
|
*/
|
|
182
219
|
get currentLineObjects(): THREE.Object3D<THREE.Object3DEventMap>[];
|
|
220
|
+
/** Per-line vertical layout records accumulated during rendering. */
|
|
183
221
|
get lineLayouts(): LineLayout[];
|
|
184
222
|
/**
|
|
185
223
|
* The horizental offset of current character in this line
|
|
186
224
|
*/
|
|
187
225
|
get hOffset(): number;
|
|
226
|
+
/** @param value New horizontal pen position within the current line. */
|
|
188
227
|
set hOffset(value: number);
|
|
189
228
|
/**
|
|
190
229
|
* The vertical offset of current character in this line
|
|
191
230
|
*/
|
|
192
231
|
get vOffset(): number;
|
|
232
|
+
/** @param value New vertical baseline position for the current line. */
|
|
193
233
|
set vOffset(value: number);
|
|
234
|
+
/** Current paragraph first-line indent in drawing units. */
|
|
194
235
|
get currentIndent(): number;
|
|
236
|
+
/** Current paragraph left margin in drawing units. */
|
|
195
237
|
get currentLeftMargin(): number;
|
|
238
|
+
/** Current paragraph right margin in drawing units. */
|
|
196
239
|
get currentRightMargin(): number;
|
|
240
|
+
/** Usable line width after subtracting left and right paragraph margins. */
|
|
197
241
|
get maxLineWidth(): number;
|
|
198
242
|
/**
|
|
199
243
|
* Process text format information
|
|
200
|
-
* @param item
|
|
244
|
+
* @param item Inline formatting command or restore snapshot from the parser.
|
|
201
245
|
*/
|
|
202
246
|
processFormat(item: ChangedProperties): void;
|
|
203
247
|
/**
|
|
@@ -214,6 +258,8 @@ export declare class MTextProcessor {
|
|
|
214
258
|
* - width/height/tracking factors
|
|
215
259
|
* - paragraph alignment and margins
|
|
216
260
|
* - underline/overline/strike-through flags
|
|
261
|
+
*
|
|
262
|
+
* @param changes Full property snapshot to apply to the current render context.
|
|
217
263
|
*/
|
|
218
264
|
private applyPropertyChanges;
|
|
219
265
|
/**
|
|
@@ -272,15 +318,29 @@ export declare class MTextProcessor {
|
|
|
272
318
|
* and starting a new line with indent applied.
|
|
273
319
|
* @param geometries Current text geometries to process
|
|
274
320
|
* @param lineGeometries Current line geometries to process
|
|
321
|
+
* @param meshCharBoxes Mesh char boxes to flush with the current line
|
|
322
|
+
* @param lineCharBoxes Line char boxes to flush with the current line
|
|
275
323
|
* @param group The group to add processed geometries to
|
|
276
324
|
*/
|
|
277
325
|
private startNewParagraph;
|
|
278
326
|
/**
|
|
279
327
|
* Renders one SHX shape glyph for AutoCAD SHAPE entities.
|
|
280
328
|
*
|
|
281
|
-
*
|
|
329
|
+
* @param shapeName Optional SHX shape name from the SHAPE entity.
|
|
330
|
+
* @param shapeNumber Optional SHX shape number from the SHAPE entity.
|
|
331
|
+
* @returns A single styled THREE.js object for the resolved shape, or `undefined` when lookup fails.
|
|
282
332
|
*/
|
|
283
333
|
processShapeGlyph(shapeName?: string, shapeNumber?: number): THREE.Object3D | undefined;
|
|
334
|
+
/**
|
|
335
|
+
* Resolves a SHX shape glyph by name and/or numeric code for SHAPE entities.
|
|
336
|
+
*
|
|
337
|
+
* Name lookup is attempted first; numeric lookup is used when the name is absent
|
|
338
|
+
* or does not match. Unlike MText, failed SHAPE lookups do not fall back to `?`.
|
|
339
|
+
*
|
|
340
|
+
* @param shapeName Optional SHX shape name.
|
|
341
|
+
* @param shapeNumber Optional SHX shape number.
|
|
342
|
+
* @returns Resolved shape and display label, or `undefined` when not found.
|
|
343
|
+
*/
|
|
284
344
|
private resolveShapeGlyph;
|
|
285
345
|
/**
|
|
286
346
|
* Builds geometry for one glyph and appends it to the output buffers.
|
|
@@ -288,47 +348,235 @@ export declare class MTextProcessor {
|
|
|
288
348
|
* @returns Horizontal advance width after width factor and oblique skew.
|
|
289
349
|
*/
|
|
290
350
|
private buildShapeGeometry;
|
|
351
|
+
/**
|
|
352
|
+
* Builds the world transform for one glyph (width factor, oblique, bold, translate).
|
|
353
|
+
*
|
|
354
|
+
* @param charX Horizontal glyph origin in drawing space.
|
|
355
|
+
* @param charY Vertical glyph origin in drawing space.
|
|
356
|
+
* @param charHeight Layout font height used for oblique advance calculation.
|
|
357
|
+
* @returns Composite transform matrix and extra horizontal advance introduced by oblique skew.
|
|
358
|
+
*/
|
|
359
|
+
private buildCharTransformMatrix;
|
|
360
|
+
/**
|
|
361
|
+
* Appends one glyph's geometry to the active batch buffers and optional char boxes.
|
|
362
|
+
*
|
|
363
|
+
* Mesh fonts (`ShapeGeometry`) are transformed immediately; line fonts are queued in
|
|
364
|
+
* {@link _lineBatchEntries} for later merge via {@link TextGeometryBuilder.mergeLineGeometries}.
|
|
365
|
+
*
|
|
366
|
+
* @param shape Source text shape for the glyph.
|
|
367
|
+
* @param label Character label stored on geometry and char boxes.
|
|
368
|
+
* @param canonical Untransformed glyph geometry from the font.
|
|
369
|
+
* @param matrix World transform to apply to the glyph.
|
|
370
|
+
* @param geometries Accumulator for mesh (`ShapeGeometry`) primitives.
|
|
371
|
+
* @param meshCharBoxes Accumulator for mesh-glyph picking boxes.
|
|
372
|
+
* @param lineCharBoxes Accumulator for line-glyph picking boxes.
|
|
373
|
+
*/
|
|
374
|
+
private appendCharGeometry;
|
|
375
|
+
/**
|
|
376
|
+
* Creates a two-point line decoration geometry (underline, overline, strike-through).
|
|
377
|
+
*
|
|
378
|
+
* @param lineGeometries Accumulator for line-based decoration geometry.
|
|
379
|
+
* @param vertices Six floats: start `(x,y,z)` and end `(x,y,z)` in drawing space.
|
|
380
|
+
*/
|
|
381
|
+
private pushDecorationLine;
|
|
291
382
|
/**
|
|
292
383
|
* Render the specified texts
|
|
293
|
-
* @param
|
|
384
|
+
* @param tokens Parsed MText token stream from the parser.
|
|
385
|
+
* @returns A {@link THREE.Group} containing merged line/mesh objects and layout metadata.
|
|
294
386
|
*/
|
|
295
387
|
processText(tokens: Generator<MTextToken>): THREE.Group<THREE.Object3DEventMap>;
|
|
388
|
+
/**
|
|
389
|
+
* Flushes pending geometry and char boxes into a styled THREE.js object on `group`.
|
|
390
|
+
*
|
|
391
|
+
* When only char boxes exist (spaces, empty lines), creates a marker object with
|
|
392
|
+
* layout metadata and no visible geometry.
|
|
393
|
+
*
|
|
394
|
+
* @param geometries Pending mesh geometries for the current style segment.
|
|
395
|
+
* @param lineGeometries Pending line geometries and decorations for the current style segment.
|
|
396
|
+
* @param meshCharBoxes Mesh-glyph char boxes collected since the last flush.
|
|
397
|
+
* @param lineCharBoxes Line-glyph char boxes collected since the last flush.
|
|
398
|
+
* @param group Parent group receiving the created object.
|
|
399
|
+
* @param charBoxType Char-box classification stored on the flushed object.
|
|
400
|
+
*/
|
|
296
401
|
private processGeometries;
|
|
402
|
+
/**
|
|
403
|
+
* Lays out and renders one parser word token, breaking to a new visual line when needed.
|
|
404
|
+
*
|
|
405
|
+
* @param word Character sequence for a single word token.
|
|
406
|
+
* @param geometries Mesh geometry accumulator for the active style segment.
|
|
407
|
+
* @param lineGeometries Line geometry accumulator for the active style segment.
|
|
408
|
+
* @param meshCharBoxes Mesh char-box accumulator.
|
|
409
|
+
* @param lineCharBoxes Line char-box accumulator.
|
|
410
|
+
*/
|
|
297
411
|
private processWord;
|
|
412
|
+
/**
|
|
413
|
+
* Renders an MText stack token (`\S...;`) as fraction, superscript, subscript, or tolerance layout.
|
|
414
|
+
*
|
|
415
|
+
* @param stackData Parser stack payload: `[numerator, denominator, divider]`.
|
|
416
|
+
* @param geometries Mesh geometry accumulator.
|
|
417
|
+
* @param lineGeometries Line geometry accumulator.
|
|
418
|
+
* @param meshCharBoxes Mesh char-box accumulator.
|
|
419
|
+
* @param lineCharBoxes Line char-box accumulator.
|
|
420
|
+
*/
|
|
298
421
|
private processStack;
|
|
422
|
+
/**
|
|
423
|
+
* Records a zero-height char box for a stack fraction divider in logical char order.
|
|
424
|
+
*
|
|
425
|
+
* @param startX Horizontal start of the fraction bar in drawing space.
|
|
426
|
+
* @param currentVOffset Vertical baseline of the stack relative to the main line.
|
|
427
|
+
* @param width Horizontal extent of the fraction bar.
|
|
428
|
+
* @param meshCharBoxes Mesh char-box accumulator.
|
|
429
|
+
* @param lineCharBoxes Line char-box accumulator.
|
|
430
|
+
*/
|
|
299
431
|
private recordStackDivider;
|
|
300
432
|
/**
|
|
301
433
|
* Convert a legacy top-anchored vOffset (used by stack/sub/sup logic) into
|
|
302
434
|
* the current baseline-anchored coordinate system.
|
|
435
|
+
*
|
|
436
|
+
* @param legacyTopAlignedVOffset Vertical position in the legacy top-anchored system.
|
|
437
|
+
* @param fontSize Font size associated with the legacy offset.
|
|
438
|
+
* @returns Baseline-anchored vertical offset for the current layout model.
|
|
303
439
|
*/
|
|
304
440
|
private convertTopAlignedVOffset;
|
|
441
|
+
/**
|
|
442
|
+
* Advances the pen by one space width and optionally records a space char box.
|
|
443
|
+
*
|
|
444
|
+
* @param meshCharBoxes Mesh char-box accumulator.
|
|
445
|
+
* @param lineCharBoxes Line char-box accumulator.
|
|
446
|
+
*/
|
|
305
447
|
private processBlank;
|
|
448
|
+
/**
|
|
449
|
+
* Records the character index where a visual line break occurs.
|
|
450
|
+
*
|
|
451
|
+
* @param meshCharBoxes Optional pending mesh char boxes included in the break index.
|
|
452
|
+
* @param lineCharBoxes Optional pending line char boxes included in the break index.
|
|
453
|
+
*/
|
|
306
454
|
private recordVisualLineBreak;
|
|
455
|
+
/**
|
|
456
|
+
* Appends vertical layout metadata for the current visual line to {@link _lineLayouts}.
|
|
457
|
+
*/
|
|
307
458
|
private recordCurrentLineLayout;
|
|
459
|
+
/**
|
|
460
|
+
* Renders a percent-control-code symbol (`%%...`) or its literal fallback character.
|
|
461
|
+
*
|
|
462
|
+
* @param data Parser payload describing the percent symbol kind and lookup data.
|
|
463
|
+
* @param geometries Mesh geometry accumulator.
|
|
464
|
+
* @param lineGeometries Line geometry accumulator.
|
|
465
|
+
* @param meshCharBoxes Mesh char-box accumulator.
|
|
466
|
+
* @param lineCharBoxes Line char-box accumulator.
|
|
467
|
+
*/
|
|
308
468
|
private processPercentSymbol;
|
|
469
|
+
/**
|
|
470
|
+
* Renders one character glyph, including decorations and line-break handling.
|
|
471
|
+
*
|
|
472
|
+
* Missing glyphs are treated as spaces. When the pen exceeds {@link maxLineWidth},
|
|
473
|
+
* a visual line break is recorded before placement.
|
|
474
|
+
*
|
|
475
|
+
* @param char Character to render.
|
|
476
|
+
* @param geometries Mesh geometry accumulator.
|
|
477
|
+
* @param lineGeometries Line geometry accumulator.
|
|
478
|
+
* @param meshCharBoxes Mesh char-box accumulator.
|
|
479
|
+
* @param lineCharBoxes Line char-box accumulator.
|
|
480
|
+
* @param shapeOverride Optional pre-resolved shape (used by percent symbols and stacks).
|
|
481
|
+
*/
|
|
309
482
|
private processChar;
|
|
483
|
+
/**
|
|
484
|
+
* Applies horizontal alignment to the final visual line after all tokens are processed.
|
|
485
|
+
*/
|
|
310
486
|
private processLastLine;
|
|
487
|
+
/**
|
|
488
|
+
* Initializes line metric state from the current font and default text height.
|
|
489
|
+
*/
|
|
311
490
|
private initLineParams;
|
|
491
|
+
/**
|
|
492
|
+
* Switches the active font family and recomputes derived line metrics.
|
|
493
|
+
*
|
|
494
|
+
* @param fontName Font family name from an inline `\f` command or text style.
|
|
495
|
+
*/
|
|
312
496
|
private changeFont;
|
|
313
497
|
/**
|
|
314
|
-
*
|
|
498
|
+
* Recalculates font scale factor and drawing-space font size from defaults and scale factors.
|
|
499
|
+
*
|
|
500
|
+
* @param newFontHeight Optional absolute font height override in drawing units.
|
|
315
501
|
*/
|
|
316
502
|
private calcuateLineParams;
|
|
317
503
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* @
|
|
504
|
+
* Returns whether a shape contributes visible stroke or mesh geometry for rendering.
|
|
505
|
+
*
|
|
506
|
+
* @param shape Candidate text shape.
|
|
507
|
+
* @param char Character being resolved (spaces may still be renderable when width > 0).
|
|
508
|
+
* @returns `true` when the shape should be drawn instead of replaced with the not-found glyph.
|
|
321
509
|
*/
|
|
322
510
|
private shapeHasStrokeGeometry;
|
|
511
|
+
/**
|
|
512
|
+
* Resolves the best available shape for a percent-control-code symbol.
|
|
513
|
+
*
|
|
514
|
+
* Tries symbol-font lookup codes first, then falls back to the primary font glyph.
|
|
515
|
+
*
|
|
516
|
+
* @param data Parser percent-symbol payload.
|
|
517
|
+
* @returns A renderable text shape for the symbol.
|
|
518
|
+
*/
|
|
323
519
|
private resolvePercentSymbolShape;
|
|
520
|
+
/**
|
|
521
|
+
* Resolves the text shape for one character using primary font, big font, defaults, and symbol fonts.
|
|
522
|
+
*
|
|
523
|
+
* Updates {@link _maxFontSize} when the active font size exceeds the current line maximum.
|
|
524
|
+
* Falls back to the not-found glyph when no renderable geometry is available.
|
|
525
|
+
*
|
|
526
|
+
* @param char Character to resolve.
|
|
527
|
+
* @returns Renderable text shape and the font that supplied it.
|
|
528
|
+
*/
|
|
529
|
+
private resolveCharShape;
|
|
530
|
+
private canProbeFontOwnership;
|
|
531
|
+
private fontHasChar;
|
|
532
|
+
/**
|
|
533
|
+
* Returns the renderable shape for one character, discarding font provenance metadata.
|
|
534
|
+
*
|
|
535
|
+
* @param char Character to resolve.
|
|
536
|
+
* @returns Renderable text shape, or `undefined` when resolution fails entirely.
|
|
537
|
+
*/
|
|
324
538
|
private getCharShape;
|
|
539
|
+
/**
|
|
540
|
+
* Finalizes the current visual line and starts the next one.
|
|
541
|
+
*
|
|
542
|
+
* Records layout metadata, resets horizontal pen state, updates vertical offset,
|
|
543
|
+
* and reapplies paragraph alignment to objects on the completed line.
|
|
544
|
+
*
|
|
545
|
+
* @param collectBreakIndex When `true`, records a char index for automatic wrapping.
|
|
546
|
+
*/
|
|
325
547
|
private advanceToNextLine;
|
|
548
|
+
/**
|
|
549
|
+
* Updates {@link _maxLineAdvance} from the current line's horizontal pen position.
|
|
550
|
+
*/
|
|
326
551
|
private captureCurrentLineAdvance;
|
|
552
|
+
/**
|
|
553
|
+
* Counts logical characters represented by pending char boxes for break-index accounting.
|
|
554
|
+
*
|
|
555
|
+
* Stack char boxes collapse numerator, divider, and denominator into one logical token.
|
|
556
|
+
*
|
|
557
|
+
* @param meshCharBoxes Pending mesh char boxes.
|
|
558
|
+
* @param lineCharBoxes Pending line char boxes.
|
|
559
|
+
* @param charBoxType Classification of the geometry group being flushed.
|
|
560
|
+
* @returns Number of logical characters contributed by the pending boxes.
|
|
561
|
+
*/
|
|
327
562
|
private countFinalCharBoxes;
|
|
563
|
+
/**
|
|
564
|
+
* Corrects vertical offset when the first glyph on a line uses a different font size
|
|
565
|
+
* than the empty line that preceded it.
|
|
566
|
+
*/
|
|
328
567
|
private applyPendingEmptyLineYAdjust;
|
|
568
|
+
/**
|
|
569
|
+
* Chooses whether subsequent char boxes should attach to mesh or line geometry owners.
|
|
570
|
+
*
|
|
571
|
+
* @param meshCharBoxes Mesh char boxes already collected on the current line.
|
|
572
|
+
* @param lineCharBoxes Line char boxes already collected on the current line.
|
|
573
|
+
* @returns Target geometry family for the next char box.
|
|
574
|
+
*/
|
|
329
575
|
private resolveCharBoxTarget;
|
|
330
576
|
/**
|
|
331
|
-
*
|
|
577
|
+
* Applies translation on the specified buffer geometries according to text alignment setting.
|
|
578
|
+
*
|
|
579
|
+
* Translates both geometry vertices and attached char boxes on the current visual line.
|
|
332
580
|
*/
|
|
333
581
|
private processAlignment;
|
|
334
582
|
/**
|
|
@@ -337,22 +585,45 @@ export declare class MTextProcessor {
|
|
|
337
585
|
* AutoCAD uses each font's own space glyph metrics (SHX pen advance or TrueType
|
|
338
586
|
* horizontal advance). A fixed fraction of text height (e.g. 50% for SHX) is only
|
|
339
587
|
* a rough fallback when the font has no space definition.
|
|
588
|
+
*
|
|
589
|
+
* @param font Font family name.
|
|
590
|
+
* @param fontSize Font size in drawing units.
|
|
591
|
+
* @returns Horizontal advance width for one space character.
|
|
340
592
|
*/
|
|
341
593
|
private calculateBlankWidthForFont;
|
|
342
594
|
/**
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
595
|
+
* Converts pending mesh and line geometries into a styled THREE.js object.
|
|
596
|
+
*
|
|
597
|
+
* @param geometries Mesh (`ShapeGeometry`) primitives for the current style segment.
|
|
598
|
+
* @param lineGeometries Line primitives and decorations for the current style segment.
|
|
599
|
+
* @param meshCharBoxes Mesh char boxes to attach to the created object.
|
|
600
|
+
* @param lineCharBoxes Line char boxes to attach to the created object.
|
|
601
|
+
* @param charBoxType Char-box classification stored on the created object.
|
|
602
|
+
* @returns A mesh, line segments object, or small group containing both.
|
|
346
603
|
*/
|
|
347
|
-
private
|
|
604
|
+
private toThreeObject;
|
|
348
605
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* @
|
|
606
|
+
* Multiplies the active font-size scale factor and recomputes line metrics.
|
|
607
|
+
*
|
|
608
|
+
* @param value Relative scale multiplier (for example `0.7` for superscript).
|
|
352
609
|
*/
|
|
353
|
-
private toThreeObject;
|
|
354
610
|
private changeFontSizeScaleFactor;
|
|
611
|
+
/**
|
|
612
|
+
* Sets an absolute font height override and recomputes line metrics.
|
|
613
|
+
*
|
|
614
|
+
* @param value Font height in drawing units.
|
|
615
|
+
*/
|
|
355
616
|
private changeFontHeight;
|
|
617
|
+
/**
|
|
618
|
+
* Resolves the initial text color from entity color settings.
|
|
619
|
+
*
|
|
620
|
+
* @returns Base color as `0xRRGGBB`.
|
|
621
|
+
*/
|
|
356
622
|
private resolveBaseColor;
|
|
623
|
+
/**
|
|
624
|
+
* Builds color settings for material creation from the current render context.
|
|
625
|
+
*
|
|
626
|
+
* @returns Color settings including the active inline color snapshot.
|
|
627
|
+
*/
|
|
357
628
|
private getMaterialColorSettings;
|
|
358
629
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/mtext-renderer",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.9",
|
|
4
4
|
"description": "AutoCAD MText renderer based on Three.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "MLight Lee <mlight.lee@outlook.com>",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@mlightcad/mtext-parser": "^1.5.0",
|
|
47
|
-
"@mlightcad/shx-parser": "^1.4.
|
|
47
|
+
"@mlightcad/shx-parser": "^1.4.5",
|
|
48
48
|
"iconv-lite": "^0.7.0",
|
|
49
49
|
"idb": "^8.0.3",
|
|
50
50
|
"opentype.js": "^2.0.0"
|