@mlightcad/mtext-renderer 0.10.16 → 0.11.1
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/README.md +3 -3
- package/dist/index.js +13878 -9713
- package/dist/index.umd.cjs +8 -7
- package/dist/mtext-renderer-worker.js +34372 -30345
- package/lib/font/baseFont.d.ts +4 -0
- package/lib/font/defaultFontLoader.d.ts +2 -2
- package/lib/font/defaultFontsPresets.d.ts +29 -0
- package/lib/font/fontLoader.d.ts +1 -1
- package/lib/font/fontManager.d.ts +81 -7
- package/lib/font/index.d.ts +1 -0
- package/lib/font/meshFont.d.ts +9 -0
- package/lib/font/shxFont.d.ts +8 -0
- package/lib/renderer/index.d.ts +1 -0
- package/lib/renderer/mtext.d.ts +7 -1
- package/lib/renderer/mtextProcessor.d.ts +20 -0
- package/lib/renderer/percentControlCodes.d.ts +5 -0
- package/lib/renderer/shape.d.ts +25 -0
- package/lib/renderer/shxSymbolControlCodes.d.ts +46 -0
- package/lib/renderer/types.d.ts +19 -0
- package/lib/worker/baseRenderer.d.ts +10 -2
- package/lib/worker/mainThreadRenderer.d.ts +4 -2
- package/lib/worker/unifiedRenderer.d.ts +17 -2
- package/lib/worker/webWorkerRenderer.d.ts +8 -2
- package/package.json +4 -4
package/lib/font/baseFont.d.ts
CHANGED
|
@@ -60,6 +60,10 @@ export declare abstract class BaseFont {
|
|
|
60
60
|
* @returns The shape data for the character code, or undefined if not found
|
|
61
61
|
*/
|
|
62
62
|
abstract getCodeShape(code: number, size: number): BaseTextShape | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Gets a named SHX shape glyph when supported by the font implementation.
|
|
65
|
+
*/
|
|
66
|
+
getShapeByName(_name: string, _size: number): BaseTextShape | undefined;
|
|
63
67
|
/**
|
|
64
68
|
* Gets the scale factor for this font.
|
|
65
69
|
* This is used to adjust the size of characters when rendering.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FontInfo, FontLoader, FontLoadStatus } from './fontLoader';
|
|
2
2
|
/**
|
|
3
3
|
* Default implementation of the FontLoader interface.
|
|
4
|
-
* This class provides font loading functionality using [this font repository](https://
|
|
4
|
+
* This class provides font loading functionality using [this font repository](https://cdn.jsdelivr.net/gh/mlightcad/cad-data/fonts/).
|
|
5
5
|
* It loads font metadata from a JSON file and provides access to available fonts.
|
|
6
6
|
*/
|
|
7
7
|
export declare class DefaultFontLoader implements FontLoader {
|
|
@@ -42,7 +42,7 @@ export declare class DefaultFontLoader implements FontLoader {
|
|
|
42
42
|
* @param fontNames - Array of font names to load
|
|
43
43
|
* @returns Promise that resolves to an array of FontLoadStatus objects
|
|
44
44
|
*/
|
|
45
|
-
load(fontNames: string[]): Promise<FontLoadStatus[]>;
|
|
45
|
+
load(fontNames: readonly string[]): Promise<FontLoadStatus[]>;
|
|
46
46
|
/**
|
|
47
47
|
* Build one font map. The key is font name. The value is font info.
|
|
48
48
|
*/
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preset names for common AutoCAD-era default font fallback chains.
|
|
3
|
+
*
|
|
4
|
+
* Third-party DWG viewers often mirror fonts that were widely bundled or
|
|
5
|
+
* referenced during the AutoCAD R12/R14 era, then simplified in later releases.
|
|
6
|
+
*/
|
|
7
|
+
export type DefaultFontsPreset =
|
|
8
|
+
/** SHX symbol fonts plus mesh CJK fallback (library default). */
|
|
9
|
+
'minimal'
|
|
10
|
+
/** Classic R12/R14 stack: SHX basics, GB big font, then mesh CJK and AMGDT. */
|
|
11
|
+
| 'r12r14'
|
|
12
|
+
/** Later-era stack: hztxt big font with simsun and AMGDT symbols. */
|
|
13
|
+
| 'modern'
|
|
14
|
+
/** Western SHX fonts plus simsun and AMGDT; no CJK-specific SHX big fonts. */
|
|
15
|
+
| 'international'
|
|
16
|
+
/** Broad CJK coverage: both GB big-font SHX files plus common mesh fallbacks. */
|
|
17
|
+
| 'cjk';
|
|
18
|
+
/**
|
|
19
|
+
* Predefined text-font fallback chains (primary / big-font substitutes and CJK
|
|
20
|
+
* mesh fallbacks). Symbol fonts such as `amgdt` are configured separately via
|
|
21
|
+
* {@link SYMBOL_FONTS_PRESETS}.
|
|
22
|
+
*/
|
|
23
|
+
export declare const DEFAULT_FONTS_PRESETS: Record<DefaultFontsPreset, readonly string[]>;
|
|
24
|
+
/**
|
|
25
|
+
* GDT / SHX symbol-font chains used for AutoCAD control codes (`%%c`, `%%d`,
|
|
26
|
+
* `%%p`, `%%130`, etc.). Earlier entries are tried first.
|
|
27
|
+
*/
|
|
28
|
+
export declare const SYMBOL_FONTS_PRESETS: Record<DefaultFontsPreset, readonly string[]>;
|
|
29
|
+
export declare function isDefaultFontsPreset(value: string): value is DefaultFontsPreset;
|
package/lib/font/fontLoader.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export interface FontLoader {
|
|
|
44
44
|
* @param fontNames - Array of font names to load
|
|
45
45
|
* @returns Promise that resolves to an array of FontLoadStatus objects indicating the load status of each font
|
|
46
46
|
*/
|
|
47
|
-
load(fontNames: string[]): Promise<FontLoadStatus[]>;
|
|
47
|
+
load(fontNames: readonly string[]): Promise<FontLoadStatus[]>;
|
|
48
48
|
/**
|
|
49
49
|
* Retrieves information about all available fonts in the system
|
|
50
50
|
* @returns Promise that resolves to an array of FontInfo objects containing details about available fonts
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventManager } from '../common';
|
|
2
2
|
import { BaseFont } from './baseFont';
|
|
3
3
|
import { BaseTextShape } from './baseTextShape';
|
|
4
|
+
import { DefaultFontsPreset } from './defaultFontsPresets';
|
|
4
5
|
import { FontType } from './font';
|
|
5
6
|
import { FontInfo, FontLoader, FontLoadStatus } from './fontLoader';
|
|
6
7
|
/**
|
|
@@ -45,8 +46,17 @@ export declare class FontManager {
|
|
|
45
46
|
missedFonts: Record<string, number>;
|
|
46
47
|
/** Flag to enable/disable font caching */
|
|
47
48
|
enableFontCache: boolean;
|
|
48
|
-
/**
|
|
49
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Default fonts to use when a requested font is not found or lacks a glyph.
|
|
51
|
+
* Insertion order is preserved; earlier entries are tried first.
|
|
52
|
+
*/
|
|
53
|
+
defaultFonts: Set<string>;
|
|
54
|
+
/**
|
|
55
|
+
* GDT / SHX symbol fonts for AutoCAD control-code glyphs (`%%c`, `%%d`, `%%p`,
|
|
56
|
+
* `%%nnn`, etc.). Separate from {@link defaultFonts} so text fallbacks are not
|
|
57
|
+
* polluted by symbol-font code-point matches.
|
|
58
|
+
*/
|
|
59
|
+
symbolFonts: Set<string>;
|
|
50
60
|
/** Event managers for font-related events */
|
|
51
61
|
readonly events: {
|
|
52
62
|
/** Event triggered when a font cannot be found */
|
|
@@ -70,6 +80,47 @@ export declare class FontManager {
|
|
|
70
80
|
* @param mapping - The font mapping to set
|
|
71
81
|
*/
|
|
72
82
|
setFontMapping(mapping: FontMapping): void;
|
|
83
|
+
/**
|
|
84
|
+
* Sets the default font fallback chain.
|
|
85
|
+
*
|
|
86
|
+
* Pass a {@link DefaultFontsPreset} name to apply a predefined AutoCAD-era
|
|
87
|
+
* fallback stack, or pass one or more font names to define a custom chain.
|
|
88
|
+
* Earlier entries are tried first when a glyph is missing.
|
|
89
|
+
*
|
|
90
|
+
* @param fonts - A preset name, a single font name, or an ordered list of font names
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* FontManager.instance.setDefaultFonts('r12r14')
|
|
94
|
+
* FontManager.instance.setDefaultFonts(['hztxt', 'simsun', 'gdt'])
|
|
95
|
+
* FontManager.instance.setDefaultFonts('simkai')
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
setDefaultFonts(fonts: DefaultFontsPreset): void;
|
|
99
|
+
setDefaultFonts(fonts: string | readonly string[]): void;
|
|
100
|
+
/**
|
|
101
|
+
* Sets the symbol-font fallback chain for AutoCAD control-code glyphs.
|
|
102
|
+
*
|
|
103
|
+
* Pass a {@link DefaultFontsPreset} name to apply a predefined symbol stack,
|
|
104
|
+
* or pass one or more font names to define a custom chain.
|
|
105
|
+
*
|
|
106
|
+
* @param fonts - A preset name, a single font name, or an ordered list of font names
|
|
107
|
+
*/
|
|
108
|
+
setSymbolFonts(fonts: DefaultFontsPreset): void;
|
|
109
|
+
setSymbolFonts(fonts: string | readonly string[]): void;
|
|
110
|
+
/**
|
|
111
|
+
* Returns the font names for a predefined default-font preset.
|
|
112
|
+
* @param preset - The preset to look up
|
|
113
|
+
*/
|
|
114
|
+
getDefaultFontsPreset(preset: DefaultFontsPreset): readonly string[];
|
|
115
|
+
/**
|
|
116
|
+
* Returns the symbol-font names for a predefined preset.
|
|
117
|
+
* @param preset - The preset to look up
|
|
118
|
+
*/
|
|
119
|
+
getSymbolFontsPreset(preset: DefaultFontsPreset): readonly string[];
|
|
120
|
+
/**
|
|
121
|
+
* Font names that should be loaded for the active default and symbol chains.
|
|
122
|
+
*/
|
|
123
|
+
getFontsToLoad(): readonly string[];
|
|
73
124
|
/**
|
|
74
125
|
* Sets the font loader
|
|
75
126
|
* @param fontLoader - The font loader to set
|
|
@@ -83,12 +134,12 @@ export declare class FontManager {
|
|
|
83
134
|
*/
|
|
84
135
|
getAvailableFonts(): Promise<FontInfo[]>;
|
|
85
136
|
/**
|
|
86
|
-
* Return true if
|
|
87
|
-
* @returns True if
|
|
137
|
+
* Return true if all default fonts were loaded.
|
|
138
|
+
* @returns True if every font in `defaultFonts` is loaded. False otherwise.
|
|
88
139
|
*/
|
|
89
140
|
isDefaultFontLoaded(): boolean;
|
|
90
141
|
/**
|
|
91
|
-
* Loads
|
|
142
|
+
* Loads all default and symbol fonts
|
|
92
143
|
* @returns Promise that resolves to the font load statuses
|
|
93
144
|
*/
|
|
94
145
|
loadDefaultFont(): Promise<FontLoadStatus[]>;
|
|
@@ -97,7 +148,7 @@ export declare class FontManager {
|
|
|
97
148
|
* @param names - Font names to load.
|
|
98
149
|
* @returns Promise that resolves to an array of font load statuses
|
|
99
150
|
*/
|
|
100
|
-
loadFontsByNames(names: string | string[]): Promise<FontLoadStatus[]>;
|
|
151
|
+
loadFontsByNames(names: string | readonly string[]): Promise<FontLoadStatus[]>;
|
|
101
152
|
/**
|
|
102
153
|
* Loads the specified fonts from URLs
|
|
103
154
|
* @param urls - URLs of font files to load.
|
|
@@ -125,13 +176,32 @@ export declare class FontManager {
|
|
|
125
176
|
*/
|
|
126
177
|
getFontByChar(char: string): BaseFont | undefined;
|
|
127
178
|
/**
|
|
128
|
-
* Gets the text shape for a specific character
|
|
179
|
+
* Gets the text shape for a specific character in the named font only.
|
|
180
|
+
* Does not fall back to bigFont, default fonts, or other loaded fonts.
|
|
129
181
|
* @param char - The character to get the shape for
|
|
130
182
|
* @param fontName - The name of the font to use
|
|
131
183
|
* @param size - The size of the character
|
|
132
184
|
* @returns The text shape for the character, or undefined if not found
|
|
133
185
|
*/
|
|
134
186
|
getCharShape(char: string, fontName: string, size: number): BaseTextShape | undefined;
|
|
187
|
+
/**
|
|
188
|
+
* Resolves a named SHX shape glyph from the specified font.
|
|
189
|
+
*/
|
|
190
|
+
getShapeByName(name: string, fontName: string, size: number): BaseTextShape | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* Resolves an SHX shape glyph by numeric character code from the specified font.
|
|
193
|
+
*/
|
|
194
|
+
getShapeByCode(code: number, fontName: string, size: number): BaseTextShape | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Gets the text shape from the first loaded default font that contains the character.
|
|
197
|
+
* Used after primary and optional bigFont lookups per AutoCAD text-style semantics.
|
|
198
|
+
*/
|
|
199
|
+
getCharShapeFromDefaults(char: string, size: number): BaseTextShape | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* Gets the text shape from configured GDT / symbol fonts (e.g. `amgdt.shx`).
|
|
202
|
+
* Used for AutoCAD percent codes and other symbol-font code points.
|
|
203
|
+
*/
|
|
204
|
+
getCharShapeFromSymbolFonts(char: string, size: number): BaseTextShape | undefined;
|
|
135
205
|
/**
|
|
136
206
|
* Gets the scale factor for a specific font
|
|
137
207
|
* @param fontName - The name of the font
|
|
@@ -171,6 +241,10 @@ export declare class FontManager {
|
|
|
171
241
|
* Loads all fonts from the cache
|
|
172
242
|
*/
|
|
173
243
|
getAllFontsFromCache(): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* Registers a loaded font under its primary name and all aliases.
|
|
246
|
+
*/
|
|
247
|
+
private registerFontInMap;
|
|
174
248
|
/**
|
|
175
249
|
* Gets a record of all unsupported characters across all loaded fonts
|
|
176
250
|
* @returns A record mapping unsupported characters to their occurrence count
|
package/lib/font/index.d.ts
CHANGED
package/lib/font/meshFont.d.ts
CHANGED
|
@@ -82,6 +82,15 @@ export declare class MeshFont extends BaseFont {
|
|
|
82
82
|
* @returns An object containing the opentype font and parsed metadata
|
|
83
83
|
*/
|
|
84
84
|
private parseMeshFont;
|
|
85
|
+
/**
|
|
86
|
+
* Whether opentype maps the character to a real glyph (not .notdef at index 0).
|
|
87
|
+
*
|
|
88
|
+
* opentype.js ≤1.3.4: {@link OpenTypeFont.hasChar} used `charToGlyphIndex(c) !== null`,
|
|
89
|
+
* but CmapEncoding returns 0 for missing code points — see
|
|
90
|
+
* https://github.com/opentypejs/opentype.js/issues/330 (fixed in 2.0.0).
|
|
91
|
+
* We keep `index > 0` here so hasChar stays aligned with {@link _loadGlyphIfNeeded}.
|
|
92
|
+
*/
|
|
93
|
+
private opentypeHasGlyph;
|
|
85
94
|
/**
|
|
86
95
|
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
87
96
|
* @param char - The character to check
|
package/lib/font/shxFont.d.ts
CHANGED
|
@@ -55,6 +55,14 @@ export declare class ShxFont extends BaseFont {
|
|
|
55
55
|
* @returns The shape data for the character code, or undefined if not found
|
|
56
56
|
*/
|
|
57
57
|
getCodeShape(code: number, size: number): ShxTextShape | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the shape data for a named SHX shape at a given size.
|
|
60
|
+
*
|
|
61
|
+
* Shape names are matched case-insensitively via the underlying SHX parser.
|
|
62
|
+
*/
|
|
63
|
+
getShapeByName(name: string, size: number): ShxTextShape | undefined;
|
|
64
|
+
/** True when the SHX glyph has drawable strokes or a non-zero pen advance. */
|
|
65
|
+
private static hasRenderableStrokes;
|
|
58
66
|
/**
|
|
59
67
|
* For an unsupported char, use "?" as a replacement.
|
|
60
68
|
*/
|
package/lib/renderer/index.d.ts
CHANGED
package/lib/renderer/mtext.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FontManager } from '../font';
|
|
2
2
|
import { StyleManager } from './styleManager';
|
|
3
|
-
import { ColorSettings, MTextData, MTextLayout, TextStyle } from './types';
|
|
3
|
+
import { ColorSettings, MTextData, MTextLayout, ShapeData, TextStyle } from './types';
|
|
4
4
|
import * as THREE from 'three';
|
|
5
5
|
/**
|
|
6
6
|
* Represents an AutoCAD MText object in Three.js.
|
|
@@ -101,6 +101,12 @@ export declare class MText extends THREE.Object3D {
|
|
|
101
101
|
* @returns The created Three.js object, or undefined if creation fails
|
|
102
102
|
*/
|
|
103
103
|
private loadMText;
|
|
104
|
+
/**
|
|
105
|
+
* Builds and places one SHX shape glyph.
|
|
106
|
+
*/
|
|
107
|
+
loadShape(shapeData: ShapeData, style: TextStyle): THREE.Object3D<THREE.Object3DEventMap> | undefined;
|
|
108
|
+
private finalizePlacement;
|
|
109
|
+
private createShapeGroup;
|
|
104
110
|
/**
|
|
105
111
|
* Creates a group of text elements from MText data.
|
|
106
112
|
* @param mtextData - The MText data to process
|
|
@@ -275,6 +275,19 @@ export declare class MTextProcessor {
|
|
|
275
275
|
* @param group The group to add processed geometries to
|
|
276
276
|
*/
|
|
277
277
|
private startNewParagraph;
|
|
278
|
+
/**
|
|
279
|
+
* Renders one SHX shape glyph for AutoCAD SHAPE entities.
|
|
280
|
+
*
|
|
281
|
+
* The glyph is resolved by {@link shapeName} first, then by {@link shapeNumber}.
|
|
282
|
+
*/
|
|
283
|
+
processShapeGlyph(shapeName?: string, shapeNumber?: number): THREE.Object3D | undefined;
|
|
284
|
+
private resolveShapeGlyph;
|
|
285
|
+
/**
|
|
286
|
+
* Builds geometry for one glyph and appends it to the output buffers.
|
|
287
|
+
*
|
|
288
|
+
* @returns Horizontal advance width after width factor and oblique skew.
|
|
289
|
+
*/
|
|
290
|
+
private buildShapeGeometry;
|
|
278
291
|
/**
|
|
279
292
|
* Render the specified texts
|
|
280
293
|
* @param item Input texts to render
|
|
@@ -305,6 +318,7 @@ export declare class MTextProcessor {
|
|
|
305
318
|
* @param char Input one character
|
|
306
319
|
* @returns Return the text shape of the specified character
|
|
307
320
|
*/
|
|
321
|
+
private shapeHasStrokeGeometry;
|
|
308
322
|
private getCharShape;
|
|
309
323
|
private advanceToNextLine;
|
|
310
324
|
private captureCurrentLineAdvance;
|
|
@@ -323,6 +337,12 @@ export declare class MTextProcessor {
|
|
|
323
337
|
* a rough fallback when the font has no space definition.
|
|
324
338
|
*/
|
|
325
339
|
private calculateBlankWidthForFont;
|
|
340
|
+
/**
|
|
341
|
+
* Merges line-based geometries for LineSegments. SHX glyphs use indexed
|
|
342
|
+
* BufferGeometry while fraction/divider decorations omit an index; normalize
|
|
343
|
+
* to non-indexed form so mergeGeometries accepts the batch.
|
|
344
|
+
*/
|
|
345
|
+
private mergeLineGeometries;
|
|
326
346
|
/**
|
|
327
347
|
* Convert the text shape geometries to three.js object
|
|
328
348
|
* @param geometries Input text shape geometries
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FontManager } from '../font';
|
|
2
|
+
import { StyleManager } from './styleManager';
|
|
3
|
+
import { ColorSettings, MTextLayout, ShapeData, TextStyle } from './types';
|
|
4
|
+
import * as THREE from 'three';
|
|
5
|
+
/**
|
|
6
|
+
* Represents one AutoCAD SHAPE entity in Three.js.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Shape extends THREE.Object3D {
|
|
9
|
+
private _shapeData;
|
|
10
|
+
private _style;
|
|
11
|
+
private _fontsInStyleLoaded;
|
|
12
|
+
private _styleManager;
|
|
13
|
+
private _fontManager;
|
|
14
|
+
private _colorSettings;
|
|
15
|
+
private _box;
|
|
16
|
+
constructor(shapeData: ShapeData, style: TextStyle, styleManager: StyleManager, fontManager: FontManager, colorSettings?: ColorSettings);
|
|
17
|
+
get box(): THREE.Box3;
|
|
18
|
+
get styleManager(): StyleManager;
|
|
19
|
+
get textStyle(): TextStyle;
|
|
20
|
+
createLayoutData(): MTextLayout;
|
|
21
|
+
asyncDraw(): Promise<void>;
|
|
22
|
+
syncDraw(): void;
|
|
23
|
+
private createPlacementData;
|
|
24
|
+
private getFontName;
|
|
25
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AutoCAD percent-sign symbol codes (`%%c`, `%%d`, `%%p`) and their SHX
|
|
3
|
+
* symbol-font code points.
|
|
4
|
+
*
|
|
5
|
+
* Named percent codes are expanded by {@link @mlightcad/mtext-parser} into Unicode
|
|
6
|
+
* before rendering. AutoCAD itself does not rely on those Unicode code points in
|
|
7
|
+
* the primary text font; it resolves the symbols through GDT / symbol SHX fonts
|
|
8
|
+
* such as `amgdt.shx` using legacy control-code code points.
|
|
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.
|
|
17
|
+
*/
|
|
18
|
+
export type AutoCadPercentSymbolCode = 'c' | 'd' | 'p';
|
|
19
|
+
/**
|
|
20
|
+
* 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
|
+
* Earlier entries are preferred when present in {@link FontManager.symbolFonts}.
|
|
23
|
+
*/
|
|
24
|
+
export declare const AUTOCAD_PERCENT_SYMBOL_CONTROL_CODES: Readonly<Record<AutoCadPercentSymbolCode, readonly number[]>>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns whether a character originated from an AutoCAD named percent symbol.
|
|
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.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getShxControlCodeChar(char: string): string | undefined;
|
package/lib/renderer/types.d.ts
CHANGED
|
@@ -177,6 +177,25 @@ export interface MTextData {
|
|
|
177
177
|
/** Whether to collect per-character bounding boxes for picking. Default is true */
|
|
178
178
|
collectCharBoxes?: boolean;
|
|
179
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Describes one AutoCAD SHAPE entity for rendering.
|
|
182
|
+
*/
|
|
183
|
+
export interface ShapeData {
|
|
184
|
+
/** Shape name within the SHX font (DXF group 2). */
|
|
185
|
+
name?: string;
|
|
186
|
+
/** Numeric shape code within the SHX font. */
|
|
187
|
+
shapeNumber?: number;
|
|
188
|
+
/** Shape height (DXF group 40). */
|
|
189
|
+
size: number;
|
|
190
|
+
/** Insertion point in WCS coordinates. */
|
|
191
|
+
position: Point3d;
|
|
192
|
+
/** Rotation relative to the shape OCS X axis, in radians. */
|
|
193
|
+
rotation?: number;
|
|
194
|
+
/** Extrusion/normal vector. */
|
|
195
|
+
directionVector?: Point3d;
|
|
196
|
+
/** Relative X-scale factor. */
|
|
197
|
+
widthFactor?: number;
|
|
198
|
+
}
|
|
180
199
|
/**
|
|
181
200
|
* Represents a text style configuration that defines the visual appearance and formatting of text.
|
|
182
201
|
* This interface contains properties that control various aspects of text rendering including font,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StyleManager } from '../renderer/styleManager';
|
|
2
|
-
import { ColorSettings, MTextData, MTextLayout, TextStyle } from '../renderer/types';
|
|
2
|
+
import { ColorSettings, MTextData, MTextLayout, ShapeData, TextStyle } from '../renderer/types';
|
|
3
3
|
import * as THREE from 'three';
|
|
4
4
|
/**
|
|
5
5
|
* Represents a rendered MText object that extends THREE.Object3D with additional MText-specific properties.
|
|
@@ -55,6 +55,14 @@ export interface MTextBaseRenderer {
|
|
|
55
55
|
* @returns A Promise resolving to a populated `MTextObject` ready to add to a scene.
|
|
56
56
|
*/
|
|
57
57
|
syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
|
|
58
|
+
/**
|
|
59
|
+
* Render one SHX shape glyph synchronously.
|
|
60
|
+
*/
|
|
61
|
+
syncRenderShape(shapeContent: ShapeData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
|
|
62
|
+
/**
|
|
63
|
+
* Render one SHX shape glyph asynchronously.
|
|
64
|
+
*/
|
|
65
|
+
asyncRenderShape(shapeContent: ShapeData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
|
|
58
66
|
/**
|
|
59
67
|
* Ensure the specified fonts are available to the renderer.
|
|
60
68
|
*
|
|
@@ -63,7 +71,7 @@ export interface MTextBaseRenderer {
|
|
|
63
71
|
* @param fonts Font names to load (without extension for built-ins).
|
|
64
72
|
* @returns A Promise with the list of fonts that were processed.
|
|
65
73
|
*/
|
|
66
|
-
loadFonts(fonts: string[]): Promise<{
|
|
74
|
+
loadFonts(fonts: readonly string[]): Promise<{
|
|
67
75
|
loaded: string[];
|
|
68
76
|
}>;
|
|
69
77
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StyleManager } from '../renderer/styleManager';
|
|
2
|
-
import { ColorSettings, MTextData, TextStyle } from '../renderer/types';
|
|
2
|
+
import { ColorSettings, MTextData, ShapeData, TextStyle } from '../renderer/types';
|
|
3
3
|
import { MTextBaseRenderer, MTextObject } from './baseRenderer';
|
|
4
4
|
/**
|
|
5
5
|
* Main thread renderer for MText objects
|
|
@@ -30,10 +30,12 @@ export declare class MainThreadRenderer implements MTextBaseRenderer {
|
|
|
30
30
|
* that default font is loaded and fonts needed in mtext are loaded.
|
|
31
31
|
*/
|
|
32
32
|
syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
|
|
33
|
+
asyncRenderShape(shapeContent: ShapeData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
|
|
34
|
+
syncRenderShape(shapeContent: ShapeData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
|
|
33
35
|
/**
|
|
34
36
|
* Load fonts in the main thread
|
|
35
37
|
*/
|
|
36
|
-
loadFonts(fonts: string[]): Promise<{
|
|
38
|
+
loadFonts(fonts: readonly string[]): Promise<{
|
|
37
39
|
loaded: string[];
|
|
38
40
|
}>;
|
|
39
41
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { DefaultFontsPreset } from '../font';
|
|
1
2
|
import { StyleManager } from '../renderer';
|
|
2
|
-
import { ColorSettings, MTextData, TextStyle } from '../renderer/types';
|
|
3
|
+
import { ColorSettings, MTextData, ShapeData, TextStyle } from '../renderer/types';
|
|
3
4
|
import { MTextObject } from './baseRenderer';
|
|
4
5
|
import { WebWorkerRendererConfig } from './webWorkerRenderer';
|
|
5
6
|
export type RenderMode = 'main' | 'worker';
|
|
@@ -56,10 +57,24 @@ export declare class UnifiedRenderer {
|
|
|
56
57
|
* @param colorSettings - Optional color context (ByLayer, ByBlock colors).
|
|
57
58
|
*/
|
|
58
59
|
syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
|
|
60
|
+
asyncRenderShape(shapeContent: ShapeData, textStyle: TextStyle, colorSettings?: ColorSettings, _mode?: RenderMode): Promise<MTextObject>;
|
|
61
|
+
syncRenderShape(shapeContent: ShapeData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
|
|
62
|
+
/**
|
|
63
|
+
* Sets the default font fallback chain on the active renderer and workers.
|
|
64
|
+
*/
|
|
65
|
+
setDefaultFonts(fonts: DefaultFontsPreset | string | readonly string[]): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Returns font names for a predefined default-font preset.
|
|
68
|
+
*/
|
|
69
|
+
getDefaultFontsPreset(preset: DefaultFontsPreset): readonly string[];
|
|
70
|
+
/**
|
|
71
|
+
* Returns symbol-font names for a predefined preset.
|
|
72
|
+
*/
|
|
73
|
+
getSymbolFontsPreset(preset: DefaultFontsPreset): readonly string[];
|
|
59
74
|
/**
|
|
60
75
|
* Load fonts using the current mode
|
|
61
76
|
*/
|
|
62
|
-
loadFonts(fonts: string[]): Promise<{
|
|
77
|
+
loadFonts(fonts: readonly string[]): Promise<{
|
|
63
78
|
loaded: string[];
|
|
64
79
|
}>;
|
|
65
80
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StyleManager } from '../renderer/styleManager';
|
|
2
|
-
import { CharBox, ColorSettings, MTextData, TextStyle } from '../renderer/types';
|
|
2
|
+
import { CharBox, ColorSettings, MTextData, ShapeData, TextStyle } from '../renderer/types';
|
|
3
3
|
import { MTextBaseRenderer, MTextObject } from './baseRenderer';
|
|
4
4
|
/**
|
|
5
5
|
* Configuration options for WebWorkerRenderer
|
|
@@ -158,6 +158,10 @@ export declare class WebWorkerRenderer implements MTextBaseRenderer {
|
|
|
158
158
|
* @param value - URL to load fonts
|
|
159
159
|
*/
|
|
160
160
|
setFontUrl(value: string): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Syncs the default font fallback chain to all workers.
|
|
163
|
+
*/
|
|
164
|
+
setDefaultFonts(fonts: readonly string[], symbolFonts: readonly string[]): Promise<void>;
|
|
161
165
|
/**
|
|
162
166
|
* Render MText in one worker and return serialized data asynchronously.
|
|
163
167
|
*/
|
|
@@ -167,7 +171,9 @@ export declare class WebWorkerRenderer implements MTextBaseRenderer {
|
|
|
167
171
|
* Notes: It isn't supported yet.
|
|
168
172
|
*/
|
|
169
173
|
syncRenderMText(_mtextContent: MTextData, _textStyle: TextStyle, _colorSettings?: ColorSettings): MTextObject;
|
|
170
|
-
|
|
174
|
+
asyncRenderShape(_shapeContent: ShapeData, _textStyle: TextStyle, _colorSettings?: ColorSettings): Promise<MTextObject>;
|
|
175
|
+
syncRenderShape(_shapeContent: ShapeData, _textStyle: TextStyle, _colorSettings?: ColorSettings): MTextObject;
|
|
176
|
+
loadFonts(fonts: readonly string[]): Promise<{
|
|
171
177
|
loaded: string[];
|
|
172
178
|
}>;
|
|
173
179
|
getAvailableFonts(): Promise<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/mtext-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "AutoCAD MText renderer based on Three.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "MLight Lee <mlight.lee@outlook.com>",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@mlightcad/mtext-parser": "^1.4.1",
|
|
37
|
-
"@mlightcad/shx-parser": "^1.3.
|
|
37
|
+
"@mlightcad/shx-parser": "^1.3.4",
|
|
38
38
|
"iconv-lite": "^0.7.0",
|
|
39
39
|
"idb": "^8.0.3",
|
|
40
|
-
"opentype.js": "^
|
|
40
|
+
"opentype.js": "^2.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@types/opentype.js": "^1.3.
|
|
43
|
+
"@types/opentype.js": "^1.3.10",
|
|
44
44
|
"@types/three": "^0.172.0",
|
|
45
45
|
"vitest": "^3.2.4"
|
|
46
46
|
},
|