@mlightcad/mtext-renderer 0.4.7 → 0.4.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/LICENSE +21 -0
- package/README.md +36 -55
- package/dist/index.js +1120 -965
- package/dist/index.umd.cjs +2 -2
- package/dist/mtext-renderer-worker.js +18595 -0
- package/lib/cache/fontCacheManager.d.ts +0 -1
- package/lib/cache/schema.d.ts +0 -1
- package/lib/font/baseFont.d.ts +0 -1
- package/lib/font/defaultFontLoader.d.ts +0 -1
- package/lib/font/fontFactory.d.ts +0 -1
- package/lib/font/fontManager.d.ts +24 -5
- package/lib/font/meshFont.d.ts +0 -1
- package/lib/font/meshFontParser.d.ts +0 -1
- package/lib/font/shxFont.d.ts +0 -1
- package/lib/font/shxTextShape.d.ts +0 -1
- package/lib/renderer/mtext.d.ts +1 -1
- package/lib/renderer/mtextProcessor.d.ts +0 -1
- package/lib/worker/baseRenderer.d.ts +1 -1
- package/lib/worker/mainThreadRenderer.d.ts +1 -3
- package/lib/worker/unifiedRenderer.d.ts +5 -3
- package/lib/worker/webWorkerRenderer.d.ts +17 -3
- package/package.json +18 -23
- package/dist/assets/mtextWorker-BlkfNPdt.js +0 -7
- package/lib/worker/base-renderer.d.ts +0 -50
- package/lib/worker/main-thread-renderer.d.ts +0 -30
- package/lib/worker/mtext-worker.d.ts +0 -1
- package/lib/worker/unified-renderer.d.ts +0 -41
- package/lib/worker/web-worker-renderer.d.ts +0 -115
- package/lib/worker/worker-manager.d.ts +0 -113
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 mlight-lee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ will be stored in local IndexedDB to improve performance. Default value is true.
|
|
|
26
26
|
- `fontLoaded`: Triggered when a font is successfully loaded
|
|
27
27
|
|
|
28
28
|
**Public Methods:**
|
|
29
|
-
- `
|
|
29
|
+
- `getAvaiableFonts()`: Retrieve metadata of available fonts from the configured loader
|
|
30
|
+
- `loadFontsByNames(names)`: Loads fonts by logical names (e.g., 'simsun', 'arial')
|
|
30
31
|
- `getCharShape(char, fontName, size)`: Gets text shape for a character
|
|
31
32
|
- `getFontScaleFactor(fontName)`: Gets scale factor for a font
|
|
32
33
|
- `getNotFoundTextShape(size)`: Gets shape for not found indicator
|
|
@@ -35,7 +36,9 @@ will be stored in local IndexedDB to improve performance. Default value is true.
|
|
|
35
36
|
|
|
36
37
|
### FontLoader & DefaultFontLoader
|
|
37
38
|
|
|
38
|
-
Interface for font loading operations. The default implementation [DefaultFontLoader](./src/font/defaultFontLoader.ts) uses a [CDN-based font repository](https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/fonts/). It loads font metadata from a JSON file and provides access to available fonts.
|
|
39
|
+
Interface for font loading operations. The default implementation [DefaultFontLoader](./src/font/defaultFontLoader.ts) uses a [CDN-based font repository](https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/fonts/). It loads font metadata from a JSON file and provides access to available fonts.
|
|
40
|
+
|
|
41
|
+
You do NOT need to create `DefaultFontLoader` yourself anymore. `FontManager` manages a loader instance internally. If you want to customize font loading, implement `FontLoader` and set it via `FontManager.instance.setFontLoader(customLoader)`.
|
|
39
42
|
|
|
40
43
|
**Public Methods:**
|
|
41
44
|
- `load(fontNames)`: Loads specified fonts into the system
|
|
@@ -95,8 +98,6 @@ Defines the common rendering contract for producing Three.js objects from MText
|
|
|
95
98
|
|
|
96
99
|
**Public Methods:**
|
|
97
100
|
- `renderMText(mtextContent, textStyle, colorSettings?)`: Render MText content into a Three.js object hierarchy
|
|
98
|
-
- `loadFonts(fonts)`: Ensure specified fonts are available to the renderer
|
|
99
|
-
- `getAvailableFonts()`: Retrieve list of fonts that can be used by the renderer
|
|
100
101
|
- `destroy()`: Release any resources owned by the renderer
|
|
101
102
|
|
|
102
103
|
### MTextObject Interface
|
|
@@ -112,8 +113,6 @@ Renders MText content directly in the main thread. This is the simplest renderer
|
|
|
112
113
|
|
|
113
114
|
**Public Methods:**
|
|
114
115
|
- `renderMText(mtextContent, textStyle, colorSettings?)`: Render MText directly in the main thread
|
|
115
|
-
- `loadFonts(fonts)`: Load fonts in the main thread
|
|
116
|
-
- `getAvailableFonts()`: Get available fonts from the main thread
|
|
117
116
|
- `destroy()`: Cleanup resources
|
|
118
117
|
|
|
119
118
|
### WebWorkerRenderer (MTextWorkerManager)
|
|
@@ -125,8 +124,6 @@ Manages communication with MText Web Workers for parallel text rendering. This r
|
|
|
125
124
|
|
|
126
125
|
**Public Methods:**
|
|
127
126
|
- `renderMText(mtextContent, textStyle, colorSettings?)`: Render MText using worker pool
|
|
128
|
-
- `loadFonts(fonts)`: Load fonts in all workers
|
|
129
|
-
- `getAvailableFonts()`: Get available fonts from workers
|
|
130
127
|
- `terminate()`: Terminate all workers
|
|
131
128
|
- `destroy()`: Cleanup all resources
|
|
132
129
|
|
|
@@ -148,8 +145,6 @@ A flexible renderer that can switch between main thread and Web Worker rendering
|
|
|
148
145
|
- `switchMode(mode)`: Switch between main thread and worker rendering modes
|
|
149
146
|
- `getMode()`: Get current rendering mode
|
|
150
147
|
- `renderMText(mtextContent, textStyle, colorSettings?)`: Render using current mode
|
|
151
|
-
- `loadFonts(fonts)`: Load fonts using current mode
|
|
152
|
-
- `getAvailableFonts()`: Get available fonts using current mode
|
|
153
148
|
- `destroy()`: Clean up all resources
|
|
154
149
|
|
|
155
150
|
### MTextWorker
|
|
@@ -158,6 +153,7 @@ The actual Web Worker implementation that handles MText rendering tasks. This wo
|
|
|
158
153
|
|
|
159
154
|
**Features:**
|
|
160
155
|
- Independent font and style management
|
|
156
|
+
- Can preload fonts on demand via a `loadFonts` message to avoid redundant concurrent loads
|
|
161
157
|
- Efficient object serialization for transfer to main thread
|
|
162
158
|
- Support for transferable objects to minimize memory copying
|
|
163
159
|
- Error handling and response management
|
|
@@ -166,17 +162,9 @@ The actual Web Worker implementation that handles MText rendering tasks. This wo
|
|
|
166
162
|
Main class for rendering AutoCAD MText content. Extends THREE.Object3D to integrate with Three.js scene graph.
|
|
167
163
|
|
|
168
164
|
**Public Properties:**
|
|
169
|
-
- `content`: MText content configuration including text, height, width, and position
|
|
170
|
-
- `style`: Text style configuration including font, color, and text generation flags
|
|
171
165
|
- `fontManager`: Reference to FontManager instance for font operations
|
|
172
166
|
- `styleManager`: Reference to StyleManager instance for style operations
|
|
173
167
|
|
|
174
|
-
**Public Methods:**
|
|
175
|
-
- `update()`: Updates the text rendering based on current content and style
|
|
176
|
-
- `setContent(content)`: Updates the text content
|
|
177
|
-
- `setStyle(style)`: Updates the text style
|
|
178
|
-
- `dispose()`: Cleans up resources when the MText instance is no longer needed
|
|
179
|
-
|
|
180
168
|
## Class Diagram
|
|
181
169
|
|
|
182
170
|
```mermaid
|
|
@@ -334,41 +322,40 @@ classDiagram
|
|
|
334
322
|
|
|
335
323
|
```typescript
|
|
336
324
|
import * as THREE from 'three';
|
|
337
|
-
import {
|
|
325
|
+
import { FontManager, MText, StyleManager } from '@mlightcad/mtext-renderer';
|
|
338
326
|
|
|
339
327
|
// Initialize core components
|
|
340
328
|
const fontManager = FontManager.instance;
|
|
341
329
|
const styleManager = new StyleManager();
|
|
342
|
-
const fontLoader = new DefaultFontLoader();
|
|
343
330
|
|
|
344
|
-
//
|
|
345
|
-
await
|
|
331
|
+
// Preload a font
|
|
332
|
+
await fontManager.loadFontsByNames(['simsun']);
|
|
346
333
|
|
|
347
334
|
// Create MText content
|
|
348
335
|
const mtextContent = {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
336
|
+
text: '{\\fArial|b0|i0|c0|p34;Hello World}',
|
|
337
|
+
height: 0.1,
|
|
338
|
+
width: 0,
|
|
339
|
+
position: new THREE.Vector3(0, 0, 0),
|
|
353
340
|
};
|
|
354
341
|
|
|
355
342
|
// Create MText instance with style
|
|
356
343
|
const mtext = new MText(
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
344
|
+
mtextContent,
|
|
345
|
+
{
|
|
346
|
+
name: 'Standard',
|
|
347
|
+
standardFlag: 0,
|
|
348
|
+
fixedTextHeight: 0.1,
|
|
349
|
+
widthFactor: 1,
|
|
350
|
+
obliqueAngle: 0,
|
|
351
|
+
textGenerationFlag: 0,
|
|
352
|
+
lastHeight: 0.1,
|
|
353
|
+
font: 'Standard',
|
|
354
|
+
bigFont: '',
|
|
355
|
+
color: 0xffffff,
|
|
356
|
+
},
|
|
357
|
+
styleManager,
|
|
358
|
+
fontManager
|
|
372
359
|
);
|
|
373
360
|
|
|
374
361
|
// Add to Three.js scene
|
|
@@ -385,10 +372,7 @@ import { MainThreadRenderer } from '@mlightcad/mtext-renderer';
|
|
|
385
372
|
// Create main thread renderer
|
|
386
373
|
const renderer = new MainThreadRenderer();
|
|
387
374
|
|
|
388
|
-
//
|
|
389
|
-
await renderer.loadFonts(['simsun', 'arial']);
|
|
390
|
-
|
|
391
|
-
// Render MText content
|
|
375
|
+
// Render MText content (fonts are loaded on demand during rendering)
|
|
392
376
|
const mtextObject = await renderer.renderMText(
|
|
393
377
|
mtextContent,
|
|
394
378
|
textStyle,
|
|
@@ -405,12 +389,12 @@ scene.add(mtextObject);
|
|
|
405
389
|
import { WebWorkerRenderer } from '@mlightcad/mtext-renderer';
|
|
406
390
|
|
|
407
391
|
// Create worker renderer with custom pool size
|
|
408
|
-
const workerRenderer = new WebWorkerRenderer(4); // 4 workers
|
|
392
|
+
const workerRenderer = new WebWorkerRenderer({ poolSize: 4 }); // 4 workers
|
|
409
393
|
|
|
410
|
-
//
|
|
411
|
-
await workerRenderer.loadFonts(['simsun', 'arial']);
|
|
394
|
+
// Optionally preload fonts once via a coordinator to avoid duplicate concurrent loads
|
|
395
|
+
// await workerRenderer.loadFonts(['simsun', 'arial']);
|
|
412
396
|
|
|
413
|
-
// Render MText content using workers
|
|
397
|
+
// Render MText content using workers (fonts will be loaded on demand if not preloaded)
|
|
414
398
|
const mtextObject = await workerRenderer.renderMText(
|
|
415
399
|
mtextContent,
|
|
416
400
|
textStyle,
|
|
@@ -432,10 +416,7 @@ import { UnifiedRenderer } from '@mlightcad/mtext-renderer';
|
|
|
432
416
|
// Create unified renderer starting in main thread mode
|
|
433
417
|
const unifiedRenderer = new UnifiedRenderer('main');
|
|
434
418
|
|
|
435
|
-
//
|
|
436
|
-
await unifiedRenderer.loadFonts(['simsun', 'arial']);
|
|
437
|
-
|
|
438
|
-
// Render using main thread
|
|
419
|
+
// Render using main thread (fonts loaded on demand)
|
|
439
420
|
let mtextObject = await unifiedRenderer.renderMText(
|
|
440
421
|
mtextContent,
|
|
441
422
|
textStyle,
|
|
@@ -447,8 +428,8 @@ scene.add(mtextObject);
|
|
|
447
428
|
// Switch to worker mode for heavy rendering tasks
|
|
448
429
|
unifiedRenderer.switchMode('worker');
|
|
449
430
|
|
|
450
|
-
//
|
|
451
|
-
await unifiedRenderer.loadFonts(['simsun', 'arial']);
|
|
431
|
+
// Optionally preload fonts in workers to avoid duplicates
|
|
432
|
+
// await unifiedRenderer.loadFonts(['simsun', 'arial']);
|
|
452
433
|
|
|
453
434
|
// Render using workers
|
|
454
435
|
mtextObject = await unifiedRenderer.renderMText(
|