@mlightcad/mtext-renderer 0.11.1 → 0.11.3
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 +1 -1
- package/dist/index.js +2085 -1848
- package/dist/index.umd.cjs +8 -8
- package/dist/mtext-renderer-worker.js +3243 -3046
- package/lib/cache/fontCacheManager.d.ts +7 -0
- package/lib/font/fontLoader.d.ts +2 -0
- package/lib/font/fontManager.d.ts +33 -4
- package/lib/renderer/mtextProcessor.d.ts +2 -0
- package/lib/renderer/shxSymbolControlCodes.d.ts +8 -33
- package/lib/worker/unifiedRenderer.d.ts +19 -1
- package/package.json +12 -2
|
@@ -25,6 +25,13 @@ export declare class FontCacheManager {
|
|
|
25
25
|
* @returns The font data if found, undefined otherwise
|
|
26
26
|
*/
|
|
27
27
|
get(fileName: string): Promise<FontData | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Finds a font in the cache by primary name or alias.
|
|
30
|
+
* Font names may include or omit a file extension (e.g. `romans` or `romans.shx`).
|
|
31
|
+
* @param fontName The font name or alias to look up
|
|
32
|
+
* @returns The font data if found, undefined otherwise
|
|
33
|
+
*/
|
|
34
|
+
find(fontName: string): Promise<FontData | undefined>;
|
|
28
35
|
/**
|
|
29
36
|
* Deletes a font from the cache
|
|
30
37
|
* @param fileName The font file name (key)
|
package/lib/font/fontLoader.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface FontInfo {
|
|
|
15
15
|
* https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings
|
|
16
16
|
*/
|
|
17
17
|
encoding?: string;
|
|
18
|
+
/** Where this font entry comes from */
|
|
19
|
+
source?: 'remote' | 'cache';
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* Represents the status of a font loading operation
|
|
@@ -128,7 +128,8 @@ export declare class FontManager {
|
|
|
128
128
|
setFontLoader(fontLoader: FontLoader): void;
|
|
129
129
|
/**
|
|
130
130
|
* Retrieves information about all available fonts in the system.
|
|
131
|
-
*
|
|
131
|
+
* Merges remote font metadata with fonts stored in IndexedDB (cache-only
|
|
132
|
+
* entries are included; remote entries win when names collide).
|
|
132
133
|
* @returns Promise that resolves to an array of FontInfo objects
|
|
133
134
|
* @throws {Error} If font metadata cannot be loaded from the CDN
|
|
134
135
|
*/
|
|
@@ -149,6 +150,27 @@ export declare class FontManager {
|
|
|
149
150
|
* @returns Promise that resolves to an array of font load statuses
|
|
150
151
|
*/
|
|
151
152
|
loadFontsByNames(names: string | readonly string[]): Promise<FontLoadStatus[]>;
|
|
153
|
+
/**
|
|
154
|
+
* Parses a user-uploaded font file, registers it for rendering, and stores
|
|
155
|
+
* it in IndexedDB when {@link enableFontCache} is true.
|
|
156
|
+
*
|
|
157
|
+
* Supported formats: `.shx`, `.ttf`, `.otf`, `.woff`.
|
|
158
|
+
*
|
|
159
|
+
* @param data - Font file contents or a browser `File` selected by the user
|
|
160
|
+
* @param fileName - Font file name (e.g. `custom.shx`, `simkai.ttf`). Required when `data` is an `ArrayBuffer`
|
|
161
|
+
* @param aliases - Optional alias names for the font (e.g. AutoCAD style names)
|
|
162
|
+
* @param encoding - Optional character encoding for SHX bigfonts
|
|
163
|
+
* @returns Promise that resolves to the font load status
|
|
164
|
+
*/
|
|
165
|
+
cacheFont(data: ArrayBuffer | File, fileName?: string, aliases?: string[], encoding?: string): Promise<FontLoadStatus>;
|
|
166
|
+
/**
|
|
167
|
+
* Loads a font from IndexedDB by primary name or alias.
|
|
168
|
+
* No-op when {@link enableFontCache} is false.
|
|
169
|
+
*
|
|
170
|
+
* @param fontName - Font name or alias (with or without file extension)
|
|
171
|
+
* @returns True if the font was found in cache and registered for rendering
|
|
172
|
+
*/
|
|
173
|
+
loadFontFromCache(fontName: string): Promise<boolean>;
|
|
152
174
|
/**
|
|
153
175
|
* Loads the specified fonts from URLs
|
|
154
176
|
* @param urls - URLs of font files to load.
|
|
@@ -198,10 +220,14 @@ export declare class FontManager {
|
|
|
198
220
|
*/
|
|
199
221
|
getCharShapeFromDefaults(char: string, size: number): BaseTextShape | undefined;
|
|
200
222
|
/**
|
|
201
|
-
* Gets the text shape from configured GDT / symbol fonts (e.g. `amgdt.shx`)
|
|
202
|
-
*
|
|
223
|
+
* Gets the text shape from configured GDT / symbol fonts (e.g. `amgdt.shx`)
|
|
224
|
+
* by font-internal character code.
|
|
225
|
+
*
|
|
226
|
+
* AutoCAD `%%` symbols resolve against SHX code points (e.g. 126, 129, 132),
|
|
227
|
+
* not Unicode text semantics. Use {@link BaseFont.getCodeShape} so BIGFONT and
|
|
228
|
+
* Unicode SHX fonts are queried consistently.
|
|
203
229
|
*/
|
|
204
|
-
|
|
230
|
+
getCodeShapeFromSymbolFonts(code: number, size: number): BaseTextShape | undefined;
|
|
205
231
|
/**
|
|
206
232
|
* Gets the scale factor for a specific font
|
|
207
233
|
* @param fontName - The name of the font
|
|
@@ -241,6 +267,9 @@ export declare class FontManager {
|
|
|
241
267
|
* Loads all fonts from the cache
|
|
242
268
|
*/
|
|
243
269
|
getAllFontsFromCache(): Promise<void>;
|
|
270
|
+
private cachedFontDataToFontInfo;
|
|
271
|
+
private resolveUploadedFontType;
|
|
272
|
+
private buildUploadedFontAliases;
|
|
244
273
|
/**
|
|
245
274
|
* Registers a loaded font under its primary name and all aliases.
|
|
246
275
|
*/
|
|
@@ -305,6 +305,7 @@ export declare class MTextProcessor {
|
|
|
305
305
|
private processBlank;
|
|
306
306
|
private recordVisualLineBreak;
|
|
307
307
|
private recordCurrentLineLayout;
|
|
308
|
+
private processPercentSymbol;
|
|
308
309
|
private processChar;
|
|
309
310
|
private processLastLine;
|
|
310
311
|
private initLineParams;
|
|
@@ -319,6 +320,7 @@ export declare class MTextProcessor {
|
|
|
319
320
|
* @returns Return the text shape of the specified character
|
|
320
321
|
*/
|
|
321
322
|
private shapeHasStrokeGeometry;
|
|
323
|
+
private resolvePercentSymbolShape;
|
|
322
324
|
private getCharShape;
|
|
323
325
|
private advanceToNextLine;
|
|
324
326
|
private captureCurrentLineAdvance;
|
|
@@ -1,46 +1,21 @@
|
|
|
1
|
+
import { PercentSymbolData } from '@mlightcad/mtext-parser';
|
|
1
2
|
/**
|
|
2
3
|
* AutoCAD percent-sign symbol codes (`%%c`, `%%d`, `%%p`) and their SHX
|
|
3
4
|
* symbol-font code points.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* such as `amgdt.shx` using legacy
|
|
9
|
-
*
|
|
10
|
-
* References:
|
|
11
|
-
* - AutoCAD "Text Symbols and Special Characters"
|
|
12
|
-
* - AutoCAD "Control Codes and Special Characters" (`%%nnn`)
|
|
13
|
-
* - Legacy SHX convention: 127 = degree, 128 = plus/minus, 129 = diameter
|
|
14
|
-
* - Modern `amgdt.shx`: degree at 126/176, ± at 177, diameter at U+2205 (∅);
|
|
15
|
-
* code 130 = angle (∠). Legacy bytes 127–128 must not be used when CJK mesh
|
|
16
|
-
* fonts in the fallback chain expose unrelated glyphs at those code points.
|
|
6
|
+
* When {@link MTextParserOptions.yieldPercentSymbols} is enabled, the parser
|
|
7
|
+
* emits {@link TokenType.PERCENT_SYMBOL} tokens for these codes. AutoCAD itself
|
|
8
|
+
* does not rely on the Unicode expansions in the primary text font; it resolves
|
|
9
|
+
* the symbols through GDT / symbol SHX fonts such as `amgdt.shx` using legacy
|
|
10
|
+
* control-code code points.
|
|
17
11
|
*/
|
|
18
12
|
export type AutoCadPercentSymbolCode = 'c' | 'd' | 'p';
|
|
19
13
|
/**
|
|
20
14
|
* Ordered SHX byte-code candidates for each named AutoCAD percent symbol.
|
|
21
|
-
* Earlier entries are preferred when present in the symbol-font fallback chain
|
|
22
15
|
* Earlier entries are preferred when present in {@link FontManager.symbolFonts}.
|
|
23
16
|
*/
|
|
24
17
|
export declare const AUTOCAD_PERCENT_SYMBOL_CONTROL_CODES: Readonly<Record<AutoCadPercentSymbolCode, readonly number[]>>;
|
|
25
18
|
/**
|
|
26
|
-
* Returns
|
|
27
|
-
*/
|
|
28
|
-
export declare function isAutoCadPercentSymbolChar(char: string): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Returns whether a character likely came from an AutoCAD numeric percent code
|
|
31
|
-
* (`%%ddd`) expanded by mtext-parser into {@link String.fromCharCode}.
|
|
32
|
-
*
|
|
33
|
-
* AutoCAD resolves these byte-oriented SHX code points from GDT / symbol fonts
|
|
34
|
-
* (e.g. `amgdt.shx`), not from the primary text font—even when the text font
|
|
35
|
-
* defines a glyph at the same code (as with `txt.shx` at code 132).
|
|
36
|
-
*/
|
|
37
|
-
export declare function isAutoCadNumericPercentControlCodeChar(char: string): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Returns ordered SHX control-code characters to try in symbol-font fallbacks
|
|
40
|
-
* for an AutoCAD percent-symbol Unicode expansion.
|
|
41
|
-
*/
|
|
42
|
-
export declare function getShxControlCodeCandidates(char: string): readonly string[];
|
|
43
|
-
/**
|
|
44
|
-
* @deprecated Use {@link getShxControlCodeCandidates} instead.
|
|
19
|
+
* Returns ordered font code points to try for a parser-emitted percent symbol.
|
|
45
20
|
*/
|
|
46
|
-
export declare function
|
|
21
|
+
export declare function getPercentSymbolLookupCodes(data: PercentSymbolData): readonly number[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DefaultFontsPreset } from '../font';
|
|
1
|
+
import { DefaultFontsPreset, FontLoadStatus } from '../font';
|
|
2
2
|
import { StyleManager } from '../renderer';
|
|
3
3
|
import { ColorSettings, MTextData, ShapeData, TextStyle } from '../renderer/types';
|
|
4
4
|
import { MTextObject } from './baseRenderer';
|
|
@@ -12,6 +12,8 @@ export declare class UnifiedRenderer {
|
|
|
12
12
|
private mainThreadRenderer;
|
|
13
13
|
private renderer;
|
|
14
14
|
private defaultMode;
|
|
15
|
+
private workerConfig;
|
|
16
|
+
private webWorkerConfigured;
|
|
15
17
|
/**
|
|
16
18
|
* Constructor
|
|
17
19
|
*
|
|
@@ -20,6 +22,8 @@ export declare class UnifiedRenderer {
|
|
|
20
22
|
* when render mode is 'worker'.
|
|
21
23
|
*/
|
|
22
24
|
constructor(defaultMode?: RenderMode, workerConfig?: WebWorkerRendererConfig);
|
|
25
|
+
private ensureWebWorkerRenderer;
|
|
26
|
+
private activateWebWorkerRenderer;
|
|
23
27
|
/**
|
|
24
28
|
* Sets one new style manager to override the default style manager.
|
|
25
29
|
*
|
|
@@ -85,6 +89,20 @@ export declare class UnifiedRenderer {
|
|
|
85
89
|
name: string[];
|
|
86
90
|
}>;
|
|
87
91
|
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Parse and cache a user-uploaded font file in IndexedDB.
|
|
94
|
+
* Always runs on the main-thread {@link FontManager} so the cache is shared
|
|
95
|
+
* with the web worker renderer.
|
|
96
|
+
*/
|
|
97
|
+
cacheFont(data: ArrayBuffer | File, fileName?: string, aliases?: string[], encoding?: string): Promise<FontLoadStatus>;
|
|
98
|
+
/**
|
|
99
|
+
* Terminate web workers and release their memory.
|
|
100
|
+
*
|
|
101
|
+
* The unified renderer keeps working on the main thread. Workers are
|
|
102
|
+
* recreated lazily the next time worker rendering is requested.
|
|
103
|
+
* Safe to call when no workers were created.
|
|
104
|
+
*/
|
|
105
|
+
terminateWorkers(): void;
|
|
88
106
|
/**
|
|
89
107
|
* Clean up resources
|
|
90
108
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/mtext-renderer",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "AutoCAD MText renderer based on Three.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "MLight Lee <mlight.lee@outlook.com>",
|
|
@@ -24,6 +24,16 @@
|
|
|
24
24
|
"README.md",
|
|
25
25
|
"package.json"
|
|
26
26
|
],
|
|
27
|
+
"nx": {
|
|
28
|
+
"targets": {
|
|
29
|
+
"build": {
|
|
30
|
+
"outputs": [
|
|
31
|
+
"{projectRoot}/dist",
|
|
32
|
+
"{projectRoot}/lib"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
27
37
|
"keywords": [
|
|
28
38
|
"autocad",
|
|
29
39
|
"mtext",
|
|
@@ -33,7 +43,7 @@
|
|
|
33
43
|
"3d-text"
|
|
34
44
|
],
|
|
35
45
|
"dependencies": {
|
|
36
|
-
"@mlightcad/mtext-parser": "^1.
|
|
46
|
+
"@mlightcad/mtext-parser": "^1.5.0",
|
|
37
47
|
"@mlightcad/shx-parser": "^1.3.4",
|
|
38
48
|
"iconv-lite": "^0.7.0",
|
|
39
49
|
"idb": "^8.0.3",
|