@mlightcad/mtext-renderer 0.12.2 → 0.12.4

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.
@@ -51,9 +51,19 @@ export declare class FontManager {
51
51
  /**
52
52
  * When true (default), missing fonts are fetched/parsed in the background
53
53
  * via {@link requestFont} instead of requiring an open-time preload.
54
- * Drawing continues with temporary fallbacks until {@link events.fontLoaded}.
54
+ * Drawing continues with temporary fallbacks until {@link events.fontLoaded}
55
+ * unless {@link awaitFontsBeforeDraw} (or a per-draw override) waits first.
55
56
  */
56
57
  lazyFontLoading: boolean;
58
+ /**
59
+ * When true, {@link MText.asyncDraw} / {@link Shape.asyncDraw} wait for fonts
60
+ * referenced by the content and style to finish loading before building
61
+ * geometry. Useful with {@link lazyFontLoading} when callers prefer a single
62
+ * draw pass instead of redrawing on {@link events.fontLoaded}.
63
+ *
64
+ * Has no effect when {@link lazyFontLoading} is false (draw already awaits).
65
+ */
66
+ awaitFontsBeforeDraw: boolean;
57
67
  /**
58
68
  * Default fonts to use when a requested font is not found or lacks a glyph.
59
69
  * Insertion order is preserved; earlier entries are tried first.
@@ -179,9 +189,11 @@ export declare class FontManager {
179
189
  */
180
190
  requestFont(fontName: string): Promise<FontLoadStatus[]>;
181
191
  /**
182
- * Fire-and-forget {@link requestFont} for each name (deduped per name).
192
+ * Requests each font name via {@link requestFont} (deduped per name).
193
+ * Callers may ignore the returned promise for fire-and-forget loads, or
194
+ * await it when they need fonts before drawing.
183
195
  */
184
- requestFonts(fontNames: readonly string[]): void;
196
+ requestFonts(fontNames: readonly string[]): Promise<FontLoadStatus[]>;
185
197
  private normalizeFontName;
186
198
  /**
187
199
  * Parses a user-uploaded font file, registers it for rendering, and stores
@@ -146,9 +146,10 @@ export declare class MeshFont extends BaseFont {
146
146
  * Gets the shape to display when a character is not found in the font.
147
147
  * Uses "?" as a replacement character.
148
148
  * @param size - The desired size of the not found shape
149
- * @returns The shape data for the not found indicator
149
+ * @returns The shape data for the not found indicator, or undefined if "?"
150
+ * cannot be loaded from this font
150
151
  */
151
- getNotFoundTextShape(size: number): MeshTextShape;
152
+ getNotFoundTextShape(size: number): MeshTextShape | undefined;
152
153
  /**
153
154
  * Estimates memory used by this mesh font (parsed opentype + glyphs + geometry cache).
154
155
  */
@@ -2,6 +2,21 @@ import { FontManager } from '../font';
2
2
  import { StyleManager } from './styleManager';
3
3
  import { ColorSettings, MTextData, MTextLayout, ShapeData, TextStyle } from './types';
4
4
  import * as THREE from 'three';
5
+ /**
6
+ * Options for {@link MText.asyncDraw} / {@link Shape.asyncDraw}.
7
+ */
8
+ export interface MTextDrawOptions {
9
+ /**
10
+ * Wait for fonts referenced by the content/style — and, when awaiting, the
11
+ * configured default/symbol fallback chains — to finish loading before
12
+ * building geometry.
13
+ *
14
+ * Defaults to `true` when {@link FontManager.lazyFontLoading} is false, or
15
+ * when {@link FontManager.awaitFontsBeforeDraw} is true. Otherwise fonts are
16
+ * scheduled in the background and the first draw may use fallbacks.
17
+ */
18
+ awaitFonts?: boolean;
19
+ }
5
20
  /**
6
21
  * Represents an AutoCAD MText object in Three.js.
7
22
  * This class extends THREE.Object3D to provide MText rendering capabilities,
@@ -60,13 +75,15 @@ export declare class MText extends THREE.Object3D {
60
75
  */
61
76
  dispose(): void;
62
77
  /**
63
- * Draw the MText object. Schedules required fonts for background load and
64
- * builds the object graph immediately with current fallbacks.
78
+ * Draw the MText object.
65
79
  *
66
- * Does not await downloads callers that need glyphs from newly loaded fonts
67
- * should redraw after {@link FontManager.events.fontLoaded}.
80
+ * With {@link FontManager.lazyFontLoading} and without awaiting fonts, this
81
+ * schedules downloads in the background and builds geometry immediately with
82
+ * current fallbacks — redraw after {@link FontManager.events.fontLoaded} if
83
+ * you need the final faces. Pass `{ awaitFonts: true }` or set
84
+ * {@link FontManager.awaitFontsBeforeDraw} to wait for referenced fonts first.
68
85
  */
69
- asyncDraw(): Promise<void>;
86
+ asyncDraw(options?: MTextDrawOptions): Promise<void>;
70
87
  /**
71
88
  * Draw the MText object. This method assumes that fonts needed are loaded. If font needed
72
89
  * not found, the default font will be used.
@@ -1,4 +1,5 @@
1
1
  import { FontManager } from '../font';
2
+ import { MTextDrawOptions } from './mtext';
2
3
  import { StyleManager } from './styleManager';
3
4
  import { ColorSettings, MTextLayout, ShapeData, TextStyle } from './types';
4
5
  import * as THREE from 'three';
@@ -18,7 +19,7 @@ export declare class Shape extends THREE.Object3D {
18
19
  get styleManager(): StyleManager;
19
20
  get textStyle(): TextStyle;
20
21
  createLayoutData(): MTextLayout;
21
- asyncDraw(): Promise<void>;
22
+ asyncDraw(options?: MTextDrawOptions): Promise<void>;
22
23
  syncDraw(): void;
23
24
  private createPlacementData;
24
25
  private getFontName;
@@ -24,7 +24,9 @@ export declare class MainThreadRenderer implements MTextBaseRenderer {
24
24
  /**
25
25
  * Render MText directly in the main thread asynchronously. Fonts referenced by
26
26
  * the text/style are scheduled via {@link FontManager.requestFonts} when
27
- * {@link FontManager.lazyFontLoading} is enabled; otherwise they are awaited.
27
+ * {@link FontManager.lazyFontLoading} is enabled (unless
28
+ * {@link FontManager.awaitFontsBeforeDraw} waits for them first); otherwise
29
+ * they are awaited.
28
30
  */
29
31
  asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
30
32
  /**
@@ -17,6 +17,8 @@ export declare class UnifiedRenderer {
17
17
  private webWorkerConfigured;
18
18
  /** Last lazyFontLoading value pushed to the worker pool, if any. */
19
19
  private workerLazyFontLoading;
20
+ /** Last awaitFontsBeforeDraw value pushed to the worker pool, if any. */
21
+ private workerAwaitFontsBeforeDraw;
20
22
  /**
21
23
  * Constructor
22
24
  *
@@ -75,6 +77,11 @@ export declare class UnifiedRenderer {
75
77
  * existing worker pool.
76
78
  */
77
79
  setLazyFontLoading(enabled: boolean): Promise<void>;
80
+ /**
81
+ * Mirrors {@link FontManager.awaitFontsBeforeDraw} onto the main thread and
82
+ * any existing worker pool.
83
+ */
84
+ setAwaitFontsBeforeDraw(enabled: boolean): Promise<void>;
78
85
  /**
79
86
  * Returns font names for a predefined default-font preset.
80
87
  */
@@ -186,6 +186,10 @@ export declare class WebWorkerRenderer implements MTextBaseRenderer {
186
186
  * Mirrors {@link FontManager.lazyFontLoading} into every worker isolate.
187
187
  */
188
188
  setLazyFontLoading(enabled: boolean): Promise<void>;
189
+ /**
190
+ * Mirrors {@link FontManager.awaitFontsBeforeDraw} into every worker isolate.
191
+ */
192
+ setAwaitFontsBeforeDraw(enabled: boolean): Promise<void>;
189
193
  /**
190
194
  * Render MText in one worker and return serialized data asynchronously.
191
195
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlightcad/mtext-renderer",
3
- "version": "0.12.2",
3
+ "version": "0.12.4",
4
4
  "description": "AutoCAD MText renderer based on Three.js",
5
5
  "license": "MIT",
6
6
  "author": "MLight Lee <mlight.lee@outlook.com>",