@mlightcad/mtext-renderer 0.10.15 → 0.11.0
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 +12925 -9044
- package/dist/index.umd.cjs +8 -6
- package/dist/mtext-renderer-worker.js +34091 -30242
- 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 +73 -7
- package/lib/font/index.d.ts +1 -0
- package/lib/font/meshFont.d.ts +9 -0
- package/lib/font/shxFont.d.ts +4 -25
- package/lib/renderer/colorUtils.d.ts +8 -0
- package/lib/renderer/index.d.ts +1 -0
- package/lib/renderer/mtextDataUtils.d.ts +27 -0
- package/lib/renderer/mtextProcessor.d.ts +16 -0
- package/lib/renderer/percentControlCodes.d.ts +5 -0
- package/lib/renderer/shxSymbolControlCodes.d.ts +46 -0
- package/lib/worker/baseRenderer.d.ts +1 -1
- package/lib/worker/mainThreadRenderer.d.ts +1 -1
- package/lib/worker/unifiedRenderer.d.ts +14 -1
- package/lib/worker/webWorkerRenderer.d.ts +5 -2
- package/package.json +4 -4
|
@@ -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,24 @@ 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
|
+
* Gets the text shape from the first loaded default font that contains the character.
|
|
189
|
+
* Used after primary and optional bigFont lookups per AutoCAD text-style semantics.
|
|
190
|
+
*/
|
|
191
|
+
getCharShapeFromDefaults(char: string, size: number): BaseTextShape | undefined;
|
|
192
|
+
/**
|
|
193
|
+
* Gets the text shape from configured GDT / symbol fonts (e.g. `amgdt.shx`).
|
|
194
|
+
* Used for AutoCAD percent codes and other symbol-font code points.
|
|
195
|
+
*/
|
|
196
|
+
getCharShapeFromSymbolFonts(char: string, size: number): BaseTextShape | undefined;
|
|
135
197
|
/**
|
|
136
198
|
* Gets the scale factor for a specific font
|
|
137
199
|
* @param fontName - The name of the font
|
|
@@ -171,6 +233,10 @@ export declare class FontManager {
|
|
|
171
233
|
* Loads all fonts from the cache
|
|
172
234
|
*/
|
|
173
235
|
getAllFontsFromCache(): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* Registers a loaded font under its primary name and all aliases.
|
|
238
|
+
*/
|
|
239
|
+
private registerFontInMap;
|
|
174
240
|
/**
|
|
175
241
|
* Gets a record of all unsupported characters across all loaded fonts
|
|
176
242
|
* @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
|
@@ -32,31 +32,8 @@ export declare class ShxFont extends BaseFont {
|
|
|
32
32
|
getSpaceAdvance(size: number): number;
|
|
33
33
|
generateShapes(text: string, size: number): ShxTextShape[];
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* SHX glyphs are defined with `baseUp` units of cap-height (height of an
|
|
39
|
-
* uppercase letter above the baseline) and `height` units of total em-box
|
|
40
|
-
* (cap-height + descender + headroom for accents). AutoCAD's DXF group 40
|
|
41
|
-
* for TEXT/ATTRIB/MTEXT is the cap-height — the historical SHX convention
|
|
42
|
-
* since the format's introduction in AutoCAD R2 (1985), kept by AutoCAD
|
|
43
|
-
* when TrueType support was added in the early 1990s so that DWGs portable
|
|
44
|
-
* across font formats render at consistent visual sizes.
|
|
45
|
-
*
|
|
46
|
-
* Returning `1` (the previous behavior) meant SHX glyphs were rendered at
|
|
47
|
-
* `baseUp / height` of the expected size — typically ~0.75 for western
|
|
48
|
-
* fonts like `romans.shx`/`complex.shx` where `baseUp=21, height=28`.
|
|
49
|
-
* Multiplying by `height / baseUp` restores the cap-height interpretation.
|
|
50
|
-
*
|
|
51
|
-
* Mirrors the behavior already in place for mesh fonts (see
|
|
52
|
-
* `meshFontParser.ts` where `scaleFactor = unitsPerEm / glyph('A').yMax`),
|
|
53
|
-
* isolated to the glyph render path only — `mtextProcessor.currentLayoutFontSize`
|
|
54
|
-
* divides by this factor to keep layout metrics (line height, attachment
|
|
55
|
-
* offsets, blank width) on the original cap-height scale.
|
|
56
|
-
*
|
|
57
|
-
* @returns `height / baseUp` when both are populated and positive; `1`
|
|
58
|
-
* otherwise (e.g. exotic BIGFONT/symbol fonts without standard metrics),
|
|
59
|
-
* matching the prior behavior as a safe fallback.
|
|
35
|
+
* SHX font always has fixed scale factor 1.
|
|
36
|
+
* @returns Always return value 1
|
|
60
37
|
*/
|
|
61
38
|
getScaleFactor(): number;
|
|
62
39
|
/**
|
|
@@ -78,6 +55,8 @@ export declare class ShxFont extends BaseFont {
|
|
|
78
55
|
* @returns The shape data for the character code, or undefined if not found
|
|
79
56
|
*/
|
|
80
57
|
getCodeShape(code: number, size: number): ShxTextShape | undefined;
|
|
58
|
+
/** True when the SHX glyph has drawable strokes or a non-zero pen advance. */
|
|
59
|
+
private static hasRenderableStrokes;
|
|
81
60
|
/**
|
|
82
61
|
* For an unsupported char, use "?" as a replacement.
|
|
83
62
|
*/
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import { ColorSettings } from './types';
|
|
2
2
|
export declare function resolveMTextColor(colorSettings: ColorSettings): number;
|
|
3
|
+
/**
|
|
4
|
+
* Rebuild ColorSettings for a worker-deserialized glyph material.
|
|
5
|
+
*
|
|
6
|
+
* Worker meshes already carry the final resolved RGB in their serialized
|
|
7
|
+
* material. When the entity base color is ByLayer, preserve that semantic only
|
|
8
|
+
* for glyphs that match the layer fallback color.
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildWorkerMaterialColorSettings(base: ColorSettings, resolvedColor: number, baseByLayer: boolean): ColorSettings;
|
package/lib/renderer/index.d.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MTextData } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Minimum width-to-height ratio for a declared MTEXT wrap box to be treated as
|
|
4
|
+
* a real column width rather than a mistaken width factor or other bad DXF value.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MIN_REASONABLE_MTEXT_WIDTH_HEIGHT_RATIO = 1.5;
|
|
7
|
+
/**
|
|
8
|
+
* Conservative CJK full-width glyph advance as a fraction of cap height, used
|
|
9
|
+
* only when estimating a replacement wrap width from explicit line content.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CJK_MTEXT_CHAR_WIDTH_HEIGHT_RATIO = 0.8;
|
|
12
|
+
/**
|
|
13
|
+
* Estimates a usable MTEXT wrap width from the longest explicit line in the raw
|
|
14
|
+
* MTEXT string while preserving explicit line breaks such as `\P`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function estimateMTextWrapWidth(text: string, height: number): number;
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the MTEXT wrap width used for layout and anchoring.
|
|
19
|
+
*
|
|
20
|
+
* Some CAD files contain MTEXT group-code 41 values that are smaller than a
|
|
21
|
+
* single glyph height, usually because the value came from a text width factor
|
|
22
|
+
* instead of an actual wrapping box width. Treating that tiny positive value as
|
|
23
|
+
* the word-wrap width forces CJK text to wrap one character per line. When the
|
|
24
|
+
* width is clearly impossible as a layout width, estimate a usable width from
|
|
25
|
+
* the longest explicit MTEXT line and preserve explicit line breaks such as `\P`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveMTextWrapWidth(mtextData: Pick<MTextData, 'text' | 'height' | 'width'>): number;
|
|
@@ -59,6 +59,7 @@ export declare class MTextProcessor {
|
|
|
59
59
|
private _options;
|
|
60
60
|
private _totalHeight;
|
|
61
61
|
private _hOffset;
|
|
62
|
+
private _maxLineAdvance;
|
|
62
63
|
private _vOffset;
|
|
63
64
|
private _lineCount;
|
|
64
65
|
private _currentLineObjects;
|
|
@@ -103,6 +104,13 @@ export declare class MTextProcessor {
|
|
|
103
104
|
* The maximum width of one text line
|
|
104
105
|
*/
|
|
105
106
|
get maxWidth(): number;
|
|
107
|
+
/**
|
|
108
|
+
* Maximum logical pen advance across processed visual lines.
|
|
109
|
+
*
|
|
110
|
+
* Unlike visible geometry bounds, this keeps the text insertion origin tied to
|
|
111
|
+
* the layout pen position even when glyphs have side bearings or overhangs.
|
|
112
|
+
*/
|
|
113
|
+
get maxLineAdvance(): number;
|
|
106
114
|
/**
|
|
107
115
|
* The direction that the text string follows from its start to its finish.
|
|
108
116
|
*/
|
|
@@ -297,8 +305,10 @@ export declare class MTextProcessor {
|
|
|
297
305
|
* @param char Input one character
|
|
298
306
|
* @returns Return the text shape of the specified character
|
|
299
307
|
*/
|
|
308
|
+
private shapeHasStrokeGeometry;
|
|
300
309
|
private getCharShape;
|
|
301
310
|
private advanceToNextLine;
|
|
311
|
+
private captureCurrentLineAdvance;
|
|
302
312
|
private countFinalCharBoxes;
|
|
303
313
|
private applyPendingEmptyLineYAdjust;
|
|
304
314
|
private resolveCharBoxTarget;
|
|
@@ -314,6 +324,12 @@ export declare class MTextProcessor {
|
|
|
314
324
|
* a rough fallback when the font has no space definition.
|
|
315
325
|
*/
|
|
316
326
|
private calculateBlankWidthForFont;
|
|
327
|
+
/**
|
|
328
|
+
* Merges line-based geometries for LineSegments. SHX glyphs use indexed
|
|
329
|
+
* BufferGeometry while fraction/divider decorations omit an index; normalize
|
|
330
|
+
* to non-indexed form so mergeGeometries accepts the batch.
|
|
331
|
+
*/
|
|
332
|
+
private mergeLineGeometries;
|
|
317
333
|
/**
|
|
318
334
|
* Convert the text shape geometries to three.js object
|
|
319
335
|
* @param geometries Input text shape geometries
|
|
@@ -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;
|
|
@@ -63,7 +63,7 @@ export interface MTextBaseRenderer {
|
|
|
63
63
|
* @param fonts Font names to load (without extension for built-ins).
|
|
64
64
|
* @returns A Promise with the list of fonts that were processed.
|
|
65
65
|
*/
|
|
66
|
-
loadFonts(fonts: string[]): Promise<{
|
|
66
|
+
loadFonts(fonts: readonly string[]): Promise<{
|
|
67
67
|
loaded: string[];
|
|
68
68
|
}>;
|
|
69
69
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DefaultFontsPreset } from '../font';
|
|
1
2
|
import { StyleManager } from '../renderer';
|
|
2
3
|
import { ColorSettings, MTextData, TextStyle } from '../renderer/types';
|
|
3
4
|
import { MTextObject } from './baseRenderer';
|
|
@@ -56,10 +57,22 @@ 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
|
+
/**
|
|
61
|
+
* Sets the default font fallback chain on the active renderer and workers.
|
|
62
|
+
*/
|
|
63
|
+
setDefaultFonts(fonts: DefaultFontsPreset | string | readonly string[]): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Returns font names for a predefined default-font preset.
|
|
66
|
+
*/
|
|
67
|
+
getDefaultFontsPreset(preset: DefaultFontsPreset): readonly string[];
|
|
68
|
+
/**
|
|
69
|
+
* Returns symbol-font names for a predefined preset.
|
|
70
|
+
*/
|
|
71
|
+
getSymbolFontsPreset(preset: DefaultFontsPreset): readonly string[];
|
|
59
72
|
/**
|
|
60
73
|
* Load fonts using the current mode
|
|
61
74
|
*/
|
|
62
|
-
loadFonts(fonts: string[]): Promise<{
|
|
75
|
+
loadFonts(fonts: readonly string[]): Promise<{
|
|
63
76
|
loaded: string[];
|
|
64
77
|
}>;
|
|
65
78
|
/**
|
|
@@ -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,7 @@ 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
|
-
loadFonts(fonts: string[]): Promise<{
|
|
174
|
+
loadFonts(fonts: readonly string[]): Promise<{
|
|
171
175
|
loaded: string[];
|
|
172
176
|
}>;
|
|
173
177
|
getAvailableFonts(): Promise<{
|
|
@@ -179,7 +183,6 @@ export declare class WebWorkerRenderer implements MTextBaseRenderer {
|
|
|
179
183
|
* Reconstruct MText object from JSON serialized data
|
|
180
184
|
*/
|
|
181
185
|
reconstructMText(serializedData: SerializedMText, colorSettings: ColorSettings): MTextObject;
|
|
182
|
-
private buildMaterialColorSettings;
|
|
183
186
|
private deserializeCharBoxes;
|
|
184
187
|
private collectLayout;
|
|
185
188
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/mtext-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
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
|
},
|