@mlightcad/mtext-renderer 0.11.1 → 0.11.2

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.
@@ -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)
@@ -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
- * Loads font metadata from a CDN if not already loaded.
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
- * Used for AutoCAD percent codes and other symbol-font code points.
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
- getCharShapeFromSymbolFonts(char: string, size: number): BaseTextShape | undefined;
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
- * 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.
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 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.
19
+ * Returns ordered font code points to try for a parser-emitted percent symbol.
45
20
  */
46
- export declare function getShxControlCodeChar(char: string): string | undefined;
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';
@@ -85,6 +85,12 @@ export declare class UnifiedRenderer {
85
85
  name: string[];
86
86
  }>;
87
87
  }>;
88
+ /**
89
+ * Parse and cache a user-uploaded font file in IndexedDB.
90
+ * Always runs on the main-thread {@link FontManager} so the cache is shared
91
+ * with the web worker renderer.
92
+ */
93
+ cacheFont(data: ArrayBuffer | File, fileName?: string, aliases?: string[], encoding?: string): Promise<FontLoadStatus>;
88
94
  /**
89
95
  * Clean up resources
90
96
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlightcad/mtext-renderer",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
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.4.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",