@mlightcad/mtext-renderer 0.9.3 → 0.10.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.
Files changed (40) hide show
  1. package/package.json +1 -1
  2. package/dist/index.js +0 -25332
  3. package/dist/index.umd.cjs +0 -17
  4. package/dist/mtext-renderer-worker.js +0 -30267
  5. package/lib/cache/fontCacheManager.d.ts +0 -71
  6. package/lib/cache/index.d.ts +0 -1
  7. package/lib/cache/schema.d.ts +0 -27
  8. package/lib/common/eventManager.d.ts +0 -26
  9. package/lib/common/index.d.ts +0 -2
  10. package/lib/common/utils.d.ts +0 -11
  11. package/lib/font/baseFont.d.ts +0 -81
  12. package/lib/font/baseTextShape.d.ts +0 -17
  13. package/lib/font/charGeometryCache.d.ts +0 -43
  14. package/lib/font/defaultFontLoader.d.ts +0 -50
  15. package/lib/font/font.d.ts +0 -25
  16. package/lib/font/fontFactory.d.ts +0 -31
  17. package/lib/font/fontLoader.d.ts +0 -58
  18. package/lib/font/fontManager.d.ts +0 -192
  19. package/lib/font/index.d.ts +0 -7
  20. package/lib/font/meshFont.d.ts +0 -138
  21. package/lib/font/meshFontParser.d.ts +0 -10
  22. package/lib/font/meshTextShape.d.ts +0 -33
  23. package/lib/font/normalComputationToggle.d.ts +0 -57
  24. package/lib/font/shxFont.d.ts +0 -62
  25. package/lib/font/shxTextShape.d.ts +0 -29
  26. package/lib/font/threeFont.d.ts +0 -50
  27. package/lib/index.d.ts +0 -5
  28. package/lib/renderer/charBoxUtils.d.ts +0 -4
  29. package/lib/renderer/defaultStyleManager.d.ts +0 -18
  30. package/lib/renderer/index.d.ts +0 -3
  31. package/lib/renderer/mtext.d.ts +0 -146
  32. package/lib/renderer/mtextProcessor.d.ts +0 -244
  33. package/lib/renderer/styleManager.d.ts +0 -20
  34. package/lib/renderer/types.d.ts +0 -175
  35. package/lib/worker/baseRenderer.d.ts +0 -91
  36. package/lib/worker/index.d.ts +0 -5
  37. package/lib/worker/mainThreadRenderer.d.ts +0 -49
  38. package/lib/worker/mtextWorker.d.ts +0 -1
  39. package/lib/worker/unifiedRenderer.d.ts +0 -69
  40. package/lib/worker/webWorkerRenderer.d.ts +0 -164
@@ -1,244 +0,0 @@
1
- import { ChangedProperties, MTextParagraphAlignment, MTextToken } from '@mlightcad/mtext-parser';
2
- import { FontManager } from '../font';
3
- import { StyleManager } from './styleManager';
4
- import { MTextFlowDirection, TextStyle } from './types';
5
- import * as THREE from 'three';
6
- export interface MTextFormatOptions {
7
- /**
8
- * Font size.
9
- */
10
- fontSize: number;
11
- /**
12
- * Scale factor of character width.
13
- */
14
- widthFactor: number;
15
- /**
16
- * The line space factor.
17
- */
18
- lineSpaceFactor: number;
19
- /**
20
- * The horizontal alignment.
21
- */
22
- horizontalAlignment: MTextParagraphAlignment;
23
- /**
24
- * The maximum width of one line of text string.
25
- */
26
- maxWidth: number;
27
- /**
28
- * The direction that the text string follows from its start to its finish.
29
- */
30
- flowDirection: MTextFlowDirection;
31
- /**
32
- * The color of the current block which is used when the text color is by block.
33
- */
34
- byBlockColor: number;
35
- /**
36
- * The color of the current layer which is used when the text color is by layer.
37
- */
38
- byLayerColor: number;
39
- /**
40
- * Whether to remove font name extension.
41
- */
42
- removeFontExtension: boolean;
43
- /**
44
- * Whether to collect per-character bounding boxes for picking.
45
- */
46
- collectCharBoxes?: boolean;
47
- }
48
- /**
49
- * This class represents lines of texts.
50
- */
51
- export declare class MTextProcessor {
52
- private _style;
53
- private _styleManager;
54
- private _fontManager;
55
- private _options;
56
- private _totalHeight;
57
- private _hOffset;
58
- private _vOffset;
59
- private _lineCount;
60
- private _currentLineObjects;
61
- private _contextStack;
62
- private _currentContext;
63
- private _maxFontSize;
64
- /**
65
- * The current horizontal alignment for the paragraph.
66
- *
67
- * In AutoCAD MText, paragraph-level formatting commands (such as \pqr, \pql, \pqc)
68
- * persist for the entire paragraph and are not scoped to inline formatting groups ({} blocks).
69
- * Only character-level formatting (font, bold, italic, color, etc.) is scoped to {} and managed via Context.
70
- * Therefore, paragraph alignment is maintained at the MTextProcessor level and not in Context,
71
- * so it persists until explicitly changed by another paragraph alignment command.
72
- */
73
- private _currentHorizontalAlignment;
74
- private _lastCharBoxTarget;
75
- private _lineHasRenderableChar;
76
- private _pendingEmptyLineFontSizeAdjust?;
77
- private _currentIndent;
78
- private _currentLeftMargin;
79
- private _currentRightMargin;
80
- /**
81
- * Construct one instance of this class and initialize some properties with default values.
82
- * @param style Input text style
83
- * @param styleManager Input text style manager instance
84
- * @param fontManager Input font manager instance
85
- * @param options Input formating options
86
- */
87
- constructor(style: TextStyle, styleManager: StyleManager, fontManager: FontManager, options: MTextFormatOptions);
88
- get fontManager(): FontManager;
89
- get styleManager(): StyleManager;
90
- get textStyle(): TextStyle;
91
- /**
92
- * Total height of all lines of text
93
- */
94
- get totalHeight(): number;
95
- /**
96
- * The maximum width of one text line
97
- */
98
- get maxWidth(): number;
99
- /**
100
- * The direction that the text string follows from its start to its finish.
101
- */
102
- get flowDirection(): MTextFlowDirection;
103
- /**
104
- * The default horizontal alignment of one text line
105
- */
106
- get defaultHorizontalAlignment(): MTextParagraphAlignment;
107
- /**
108
- * The default scale factor of character width
109
- */
110
- get defaultWidthFactor(): number;
111
- /**
112
- * The default font size of texts
113
- */
114
- get defaultFontSize(): number;
115
- /**
116
- * The default line space factor
117
- */
118
- get defaultLineSpaceFactor(): number;
119
- /**
120
- * Font name of current character
121
- */
122
- get currentFont(): string;
123
- /**
124
- * The current horizontal alignment of one text line
125
- */
126
- get currentHorizontalAlignment(): MTextParagraphAlignment;
127
- /**
128
- * Font size of current character
129
- */
130
- get currentFontSize(): number;
131
- /**
132
- * The height of current line of texts
133
- */
134
- get currentLineHeight(): number;
135
- /**
136
- * The maximum font size in current line. Characters in one line may have different font and font
137
- * size. So we need to store the maximum font size in current line in order to calculate the height
138
- * of current line.
139
- */
140
- get currentMaxFontSize(): number;
141
- /**
142
- * The current space setting between two characters. The meaning of this value is as follows.
143
- * - 1: no extra spacing (default tracking)
144
- * - 1.2: increases spacing by 20% of the text height
145
- * - 0.8: decreases spacing by 20% of the text height
146
- */
147
- get currentWordSpace(): number;
148
- /**
149
- * The current scale factor of character width
150
- */
151
- get currentWidthFactor(): number;
152
- /**
153
- * All of THREE.js objects in current line. It contains objects in all of sections of this line.
154
- */
155
- get currentLineObjects(): THREE.Object3D<THREE.Object3DEventMap>[];
156
- /**
157
- * The horizental offset of current character in this line
158
- */
159
- get hOffset(): number;
160
- set hOffset(value: number);
161
- /**
162
- * The vertical offset of current character in this line
163
- */
164
- get vOffset(): number;
165
- set vOffset(value: number);
166
- get currentIndent(): number;
167
- get currentLeftMargin(): number;
168
- get currentRightMargin(): number;
169
- get maxLineWidth(): number;
170
- /**
171
- * Process text format information
172
- * @param item Input mtext inline codes
173
- */
174
- processFormat(item: ChangedProperties): void;
175
- /**
176
- * Reset paragraph properties to their default values from options.
177
- */
178
- private resetParagraphProperties;
179
- /**
180
- * Start a new paragraph by processing current geometries, resetting paragraph properties,
181
- * and starting a new line with indent applied.
182
- * @param geometries Current text geometries to process
183
- * @param lineGeometries Current line geometries to process
184
- * @param group The group to add processed geometries to
185
- */
186
- private startNewParagraph;
187
- /**
188
- * Render the specified texts
189
- * @param item Input texts to render
190
- */
191
- processText(tokens: Generator<MTextToken>): THREE.Group<THREE.Object3DEventMap>;
192
- private processGeometries;
193
- private processWord;
194
- private processStack;
195
- private recordStackDivider;
196
- /**
197
- * Convert a legacy top-anchored vOffset (used by stack/sub/sup logic) into
198
- * the current baseline-anchored coordinate system.
199
- */
200
- private convertTopAlignedVOffset;
201
- private processBlank;
202
- private recordLineBreak;
203
- private processChar;
204
- private processLastLine;
205
- private initLineParams;
206
- private changeFont;
207
- /**
208
- * Calcuate font size, line space, line height and other parameters.
209
- */
210
- private calcuateLineParams;
211
- /**
212
- * Get text shape of the specified character
213
- * @param char Input one character
214
- * @returns Return the text shape of the specified character
215
- */
216
- private getCharShape;
217
- private startNewLine;
218
- private advanceToNextLine;
219
- private applyPendingEmptyLineYAdjust;
220
- private resolveCharBoxTarget;
221
- /**
222
- * Apply translation on the specified buffer geometries according to text alignment setting
223
- */
224
- private processAlignment;
225
- /**
226
- * In AutoCAD, the width of a regular space character (ASCII 32, the space key on the keyboard) in MText
227
- * depends on the current font and text height, and is not a fixed value.
228
- * Specifically:
229
- * - Space width ≈ Text height × space width ratio defined by the font
230
- * - For common TrueType fonts (like Arial), the space width is typically about 1/4 to 1/3 of the text height.
231
- * For example, if the text height is 10 (units), the space width would be approximately 2.5 to 3.3 units.
232
- * - For SHX fonts (AutoCAD's built-in vector fonts, such as txt.shx), the space width is often half the text height.
233
- * So if the text height is 10, the space width is typically 5 units.
234
- */
235
- private calculateBlankWidthForFont;
236
- /**
237
- * Convert the text shape geometries to three.js object
238
- * @param geometries Input text shape geometries
239
- * @returns Return three.js object created from the specified text shape geometries
240
- */
241
- private toThreeObject;
242
- private changeFontSizeScaleFactor;
243
- private changeFontHeight;
244
- }
@@ -1,20 +0,0 @@
1
- import { StyleTraits } from './types';
2
- import * as THREE from 'three';
3
- /**
4
- * Class to manage materials used by texts
5
- */
6
- export interface StyleManager {
7
- unsupportedTextStyles: Record<string, number>;
8
- /**
9
- * Gets one reusable material for mesh type font. If not found in cache, just create one.
10
- * @param traits - Traits to define one mesh basic material
11
- * @returns - One reusable material for mesh type font.
12
- */
13
- getMeshBasicMaterial(traits: StyleTraits): THREE.Material;
14
- /**
15
- * Gets one reusable material for line type font. If not found in cache, just create one.
16
- * @param traits - Traits to define one line basic material
17
- * @returns - One reusable material for line type font.
18
- */
19
- getLineBasicMaterial(traits: StyleTraits): THREE.Material;
20
- }
@@ -1,175 +0,0 @@
1
- import * as THREE from 'three';
2
- /**
3
- * A 3D point in drawing coordinates.
4
- */
5
- export interface Point3d {
6
- /** X coordinate */
7
- x: number;
8
- /** Y coordinate */
9
- y: number;
10
- /** Z coordinate */
11
- z: number;
12
- }
13
- /**
14
- * A 2D point in drawing coordinates.
15
- */
16
- export interface Point2d {
17
- /** X coordinate */
18
- x: number;
19
- /** Y coordinate */
20
- y: number;
21
- }
22
- /**
23
- * Defines the global text flow direction for MText layout.
24
- */
25
- export declare enum MTextFlowDirection {
26
- /** Text flows from left to right. */
27
- LEFT_TO_RIGHT = 1,
28
- /** Text flows from right to left. */
29
- RIGHT_TO_LEFT = 2,
30
- /** Text flows from top to bottom. */
31
- TOP_TO_BOTTOM = 3,
32
- /** Text flows from bottom to top. */
33
- BOTTOM_TO_TOP = 4,
34
- /** Use the direction defined by the active text style. */
35
- BY_STYLE = 5
36
- }
37
- /**
38
- * Anchor position used to align rendered MText relative to its insertion point.
39
- */
40
- export declare enum MTextAttachmentPoint {
41
- /** Top-left corner. */
42
- TopLeft = 1,
43
- /** Top-center point. */
44
- TopCenter = 2,
45
- /** Top-right corner. */
46
- TopRight = 3,
47
- /** Middle-left point. */
48
- MiddleLeft = 4,
49
- /** Center point. */
50
- MiddleCenter = 5,
51
- /** Middle-right point. */
52
- MiddleRight = 6,
53
- /** Bottom-left corner. */
54
- BottomLeft = 7,
55
- /** Bottom-center point. */
56
- BottomCenter = 8,
57
- /** Bottom-right corner. */
58
- BottomRight = 9
59
- }
60
- /**
61
- * Logical text token with optional pick box information.
62
- *
63
- * Semantics by {@link CharBoxType}:
64
- * - `CHAR`: `char` is the rendered character, `box` is defined, `children` is empty.
65
- * - `NEW_PARAGRAPH`: `char` is `\n`. The `box` represents a zero-width vertical
66
- * line whose height equals the current line height. `children` is empty.
67
- * - `STACK`: `char` is `''`, `box` is the union box of stack components, `children` contains stack parts.
68
- */
69
- export interface CharBox {
70
- /** Token type. */
71
- type: CharBoxType;
72
- /** Token bounding box in local MText coordinates. */
73
- box: THREE.Box3;
74
- /** Token character payload (`''` for `STACK`, `\n` for `NEW_PARAGRAPH`). */
75
- char: string;
76
- /** Nested token components (currently used by `STACK`). */
77
- children: CharBox[];
78
- }
79
- /**
80
- * Type of logical token emitted in {@link CharBox} output.
81
- */
82
- export declare enum CharBoxType {
83
- /** Regular rendered character token. */
84
- CHAR = "CHAR",
85
- /** Explicit paragraph break token. */
86
- NEW_PARAGRAPH = "NEW_PARAGRAPH",
87
- /** Stack token (for fraction-style stacked expressions). */
88
- STACK = "STACK"
89
- }
90
- /**
91
- * Sentinel character used internally to represent a stack divider line.
92
- */
93
- export declare const STACK_DIVIDER_CHAR = "\uE000";
94
- export interface StyleTraits {
95
- /**
96
- * Optional layer name. Material is identified by layer and color. So it means different
97
- * materials are created for the same color and differnt layer.
98
- */
99
- layer?: string;
100
- /**
101
- * The color of material
102
- */
103
- color: number;
104
- /**
105
- * One flag to indicate whether the color is by layer. If it is true, it means that the
106
- * material become invalid once layer color changed.
107
- */
108
- isByLayer?: boolean;
109
- }
110
- /**
111
- * Represents the data structure for multiline text (MText) entities.
112
- * Contains all necessary properties to define the appearance and positioning of text.
113
- */
114
- export interface MTextData {
115
- /** The actual text content to be displayed */
116
- text: string;
117
- /** The height of the text characters in drawing units */
118
- height: number;
119
- /** The width of the text box in drawing units. Text will wrap if it exceeds this width */
120
- width: number;
121
- /** The 3D insertion point coordinates where the text will be placed */
122
- position: Point3d;
123
- /** The rotation angle of the text in radians. Default is 0 (horizontal) */
124
- rotation?: number;
125
- /** The normal vector that defines the plane in which the text lies. Used for 3D orientation */
126
- directionVector?: Point3d;
127
- /** Specifies which point of the text boundary is aligned with the insertion point */
128
- attachmentPoint?: MTextAttachmentPoint;
129
- /** Determines the primary direction in which text flows */
130
- drawingDirection?: MTextFlowDirection;
131
- /** Factor that controls the spacing between text lines. Default is 1.0 */
132
- lineSpaceFactor?: number;
133
- /** The width scaling factor applied to each character. Default is 1.0 */
134
- widthFactor?: number;
135
- /** Whether to collect per-character bounding boxes for picking. Default is true */
136
- collectCharBoxes?: boolean;
137
- }
138
- /**
139
- * Represents a text style configuration that defines the visual appearance and formatting of text.
140
- * This interface contains properties that control various aspects of text rendering including font,
141
- * dimensions, and display characteristics.
142
- */
143
- export interface TextStyle extends StyleTraits {
144
- /** The unique name identifier for this text style */
145
- name: string;
146
- /** Flag indicating standard text style settings. Controls various text generation behaviors */
147
- standardFlag: number;
148
- /** The fixed height of the text in drawing units. Used when text height should remain constant */
149
- fixedTextHeight: number;
150
- /** The horizontal scaling factor applied to text characters. Default is 1.0 for normal width */
151
- widthFactor: number;
152
- /** The angle in radians for italic text. 0.0 represents vertical text, positive values slant to the right */
153
- obliqueAngle: number;
154
- /** Bit-coded flag controlling text generation options (e.g., mirroring, upside-down) */
155
- textGenerationFlag: number;
156
- /** The most recently used text height for this style */
157
- lastHeight: number;
158
- /** The primary font name or file to be used for text rendering */
159
- font: string;
160
- /** The font name or file to be used for wide characters (typically used for CJK characters) */
161
- bigFont: string;
162
- /** Optional extended font settings or alternative font specification */
163
- extendedFont?: string;
164
- }
165
- /**
166
- * Defines the default color settings for special color modes in text rendering.
167
- * These settings are used to resolve color values when text uses layer-dependent
168
- * or block-dependent coloring.
169
- */
170
- export interface ColorSettings {
171
- /** The color value to use when text is set to "by layer" color mode */
172
- byLayerColor: number;
173
- /** The color value to use when text is set to "by block" color mode */
174
- byBlockColor: number;
175
- }
@@ -1,91 +0,0 @@
1
- import { StyleManager } from '../renderer/styleManager';
2
- import { CharBox, ColorSettings, MTextData, TextStyle } from '../renderer/types';
3
- import * as THREE from 'three';
4
- /**
5
- * Represents a rendered MText object that extends THREE.Object3D with additional MText-specific properties.
6
- * This interface defines the contract for objects returned by MText renderers.
7
- */
8
- export interface MTextObject extends THREE.Object3D {
9
- /**
10
- * The bounding box of the MText object in local coordinates.
11
- * This box represents the bounds of the text content without considering transformations.
12
- * To get the world-space bounding box, apply the object's world matrix to this box.
13
- */
14
- box: THREE.Box3;
15
- /**
16
- * The list of bounding boxes for each glyph in the MText object.
17
- */
18
- charBoxes: CharBox[];
19
- }
20
- /**
21
- * Defines the common rendering contract for producing Three.js objects from MText content.
22
- *
23
- * Implementations may render on the main thread or delegate work to a Web Worker,
24
- * but they must expose the same high-level API so callers can switch strategies
25
- * without changing usage.
26
- */
27
- export interface MTextBaseRenderer {
28
- /**
29
- * Used to manage materials used by texts
30
- */
31
- get styleManager(): StyleManager;
32
- set styleManager(value: StyleManager);
33
- /**
34
- * Render the provided MText content into a Three.js object hierarchy asynchronously
35
- *
36
- * The returned root object contains meshes/lines for glyphs and exposes a
37
- * bounding box on `object.box`.
38
- *
39
- * @param mtextContent Structured MText input (text, height, width, position).
40
- * @param textStyle Text style to apply (font, width factor, oblique, etc.).
41
- * @param colorSettings Optional color context (ByLayer, ByBlock colors).
42
- * @returns A Promise resolving to a populated `MTextObject` ready to add to a scene.
43
- */
44
- asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
45
- /**
46
- * Render the provided MText content into a Three.js object hierarchy synchronously.
47
- *
48
- * The returned root object contains meshes/lines for glyphs and exposes a
49
- * bounding box on `object.box`.
50
- *
51
- * @param mtextContent Structured MText input (text, height, width, position).
52
- * @param textStyle Text style to apply (font, width factor, oblique, etc.).
53
- * @param colorSettings Optional color context (ByLayer, ByBlock colors).
54
- * @returns A Promise resolving to a populated `MTextObject` ready to add to a scene.
55
- */
56
- syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
57
- /**
58
- * Ensure the specified fonts are available to the renderer.
59
- *
60
- * Implementations should load and cache missing fonts; repeated calls should be cheap.
61
- *
62
- * @param fonts Font names to load (without extension for built-ins).
63
- * @returns A Promise with the list of fonts that were processed.
64
- */
65
- loadFonts(fonts: string[]): Promise<{
66
- loaded: string[];
67
- }>;
68
- /**
69
- * Retrieve the list of fonts that can be used by the renderer.
70
- *
71
- * The shape of each font entry is implementation-defined but should include a displayable name.
72
- *
73
- * @returns A Promise with available font metadata.
74
- */
75
- getAvailableFonts(): Promise<{
76
- fonts: Array<{
77
- name: string[];
78
- }>;
79
- }>;
80
- /**
81
- * Set URL to load fonts
82
- * @param value - URL to load fonts
83
- */
84
- setFontUrl(value: string): Promise<void>;
85
- /**
86
- * Release any resources owned by the renderer (e.g., terminate Web Workers).
87
- *
88
- * Safe to call multiple times.
89
- */
90
- destroy(): void;
91
- }
@@ -1,5 +0,0 @@
1
- export * from './webWorkerRenderer';
2
- export * from './mainThreadRenderer';
3
- export * from './unifiedRenderer';
4
- export * from './unifiedRenderer';
5
- export * from './baseRenderer';
@@ -1,49 +0,0 @@
1
- import { StyleManager } from '../renderer/styleManager';
2
- import { ColorSettings, MTextData, TextStyle } from '../renderer/types';
3
- import { MTextBaseRenderer, MTextObject } from './baseRenderer';
4
- /**
5
- * Main thread renderer for MText objects
6
- * This provides the same interface as the worker but runs in the main thread
7
- */
8
- export declare class MainThreadRenderer implements MTextBaseRenderer {
9
- private fontManager;
10
- private defaultStyleManager;
11
- private isInitialized;
12
- constructor();
13
- /**
14
- * Used to manage materials used by texts
15
- */
16
- get styleManager(): StyleManager;
17
- set styleManager(value: StyleManager);
18
- /**
19
- * Set URL to load fonts
20
- * @param value - URL to load fonts
21
- */
22
- setFontUrl(value: string): Promise<void>;
23
- /**
24
- * Render MText directly in the main thread asynchronously. It will ensure that default font
25
- * is loaded. And fonts needed in mtext are loaded on demand.
26
- */
27
- asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
28
- /**
29
- * Render MText directly in the main thread synchronously. It is user's responsibility to ensure
30
- * that default font is loaded and fonts needed in mtext are loaded.
31
- */
32
- syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
33
- /**
34
- * Load fonts in the main thread
35
- */
36
- loadFonts(fonts: string[]): Promise<{
37
- loaded: string[];
38
- }>;
39
- /**
40
- * Get available fonts from the main thread
41
- */
42
- getAvailableFonts(): Promise<{
43
- fonts: Array<{
44
- name: string[];
45
- }>;
46
- }>;
47
- destroy(): void;
48
- private ensureInitialized;
49
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,69 +0,0 @@
1
- import { StyleManager } from '../renderer';
2
- import { ColorSettings, MTextData, TextStyle } from '../renderer/types';
3
- import { MTextObject } from './baseRenderer';
4
- import { WebWorkerRendererConfig } from './webWorkerRenderer';
5
- export type RenderMode = 'main' | 'worker';
6
- /**
7
- * Unified renderer that can work in both main thread and web worker modes
8
- */
9
- export declare class UnifiedRenderer {
10
- private webWorkerRenderer;
11
- private mainThreadRenderer;
12
- private renderer;
13
- private defaultMode;
14
- /**
15
- * Constructor
16
- *
17
- * @param defaultMode - Default rendering mode. Default is 'main' which means rendering in main thread.
18
- * @param workerConfig - Configuration options for WebWorkerRenderer which is used
19
- * when render mode is 'worker'.
20
- */
21
- constructor(defaultMode?: RenderMode, workerConfig?: WebWorkerRendererConfig);
22
- /**
23
- * Sets one new style manager to override the default style manager
24
- * @param value - New style manager
25
- */
26
- setStyleManager(value: StyleManager): void;
27
- /**
28
- * Sets the default rendering mmode
29
- * @param mode The default rendering mode
30
- */
31
- setDefaultMode(mode: RenderMode): void;
32
- /**
33
- * Set URL to load fonts
34
- * @param value - URL to load fonts
35
- */
36
- setFontUrl(value: string): Promise<void>;
37
- /**
38
- * Get the default rendering mode
39
- */
40
- getDefaultMode(): RenderMode;
41
- /**
42
- * Render MText using the current mode asynchronously.
43
- * @param mode - Rendering mode used. If undefined, the default rendering mode is used.
44
- */
45
- asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings, mode?: RenderMode): Promise<MTextObject>;
46
- /**
47
- * Render MText using the current mode synchronously. Main thread render is always used
48
- * for this function because web worker renderer doesn't support rendering synchronously.
49
- */
50
- syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
51
- /**
52
- * Load fonts using the current mode
53
- */
54
- loadFonts(fonts: string[]): Promise<{
55
- loaded: string[];
56
- }>;
57
- /**
58
- * Get available fonts using the current mode
59
- */
60
- getAvailableFonts(): Promise<{
61
- fonts: Array<{
62
- name: string[];
63
- }>;
64
- }>;
65
- /**
66
- * Clean up resources
67
- */
68
- destroy(): void;
69
- }