@mlightcad/mtext-renderer 0.10.4 → 0.10.5

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.
@@ -0,0 +1,2 @@
1
+ import { ColorSettings } from './types';
2
+ export declare function resolveMTextColor(colorSettings: ColorSettings): number;
@@ -1,5 +1,5 @@
1
1
  import { StyleManager } from './styleManager';
2
- import { StyleTraits } from './types';
2
+ import { ColorSettings } from './types';
3
3
  import * as THREE from 'three';
4
4
  /**
5
5
  * Class to manage basic text style
@@ -8,11 +8,11 @@ export declare class DefaultStyleManager implements StyleManager {
8
8
  private lineBasicMaterials;
9
9
  private meshBasicMaterials;
10
10
  unsupportedTextStyles: Record<string, number>;
11
- getMeshBasicMaterial(traits: StyleTraits): THREE.Material;
12
- getLineBasicMaterial(traits: StyleTraits): THREE.Material;
11
+ getMeshBasicMaterial(colorSettings: ColorSettings): THREE.Material;
12
+ getLineBasicMaterial(colorSettings: ColorSettings): THREE.Material;
13
13
  /**
14
14
  * Builds a stable material key from traits.
15
15
  * Key differs for shader vs basic, ByLayer vs ByEntity.
16
16
  */
17
- protected buildKey(traits: StyleTraits): string;
17
+ protected buildKey(colorSettings: ColorSettings): string;
18
18
  }
@@ -1,3 +1,4 @@
1
+ export * from './colorUtils';
1
2
  export * from './mtext';
2
3
  export * from './styleManager';
3
4
  export * from './types';
@@ -1,7 +1,7 @@
1
1
  import { ChangedProperties, MTextParagraphAlignment, MTextToken } from '@mlightcad/mtext-parser';
2
2
  import { FontManager } from '../font';
3
3
  import { StyleManager } from './styleManager';
4
- import { LineLayout, MTextFlowDirection, TextStyle } from './types';
4
+ import { ColorSettings, LineLayout, MTextFlowDirection, TextStyle } from './types';
5
5
  import * as THREE from 'three';
6
6
  export interface MTextFormatOptions {
7
7
  /**
@@ -50,6 +50,7 @@ export interface MTextFormatOptions {
50
50
  */
51
51
  export declare class MTextProcessor {
52
52
  private _style;
53
+ private _colorSettings;
53
54
  private _styleManager;
54
55
  private _fontManager;
55
56
  private _options;
@@ -87,7 +88,7 @@ export declare class MTextProcessor {
87
88
  * @param fontManager Input font manager instance
88
89
  * @param options Input formating options
89
90
  */
90
- constructor(style: TextStyle, styleManager: StyleManager, fontManager: FontManager, options: MTextFormatOptions);
91
+ constructor(style: TextStyle, colorSettings: ColorSettings, styleManager: StyleManager, fontManager: FontManager, options: MTextFormatOptions);
91
92
  get fontManager(): FontManager;
92
93
  get styleManager(): StyleManager;
93
94
  get textStyle(): TextStyle;
@@ -300,4 +301,6 @@ export declare class MTextProcessor {
300
301
  private toThreeObject;
301
302
  private changeFontSizeScaleFactor;
302
303
  private changeFontHeight;
304
+ private resolveBaseColor;
305
+ private getMaterialColorSettings;
303
306
  }
@@ -1,4 +1,4 @@
1
- import { StyleTraits } from './types';
1
+ import { ColorSettings } from './types';
2
2
  import * as THREE from 'three';
3
3
  /**
4
4
  * Class to manage materials used by texts
@@ -10,11 +10,11 @@ export interface StyleManager {
10
10
  * @param traits - Traits to define one mesh basic material
11
11
  * @returns - One reusable material for mesh type font.
12
12
  */
13
- getMeshBasicMaterial(traits: StyleTraits): THREE.Material;
13
+ getMeshBasicMaterial(colorSettings: ColorSettings): THREE.Material;
14
14
  /**
15
15
  * Gets one reusable material for line type font. If not found in cache, just create one.
16
16
  * @param traits - Traits to define one line basic material
17
17
  * @returns - One reusable material for line type font.
18
18
  */
19
- getLineBasicMaterial(traits: StyleTraits): THREE.Material;
19
+ getLineBasicMaterial(colorSettings: ColorSettings): THREE.Material;
20
20
  }
@@ -1,3 +1,4 @@
1
+ import { MTextColor } from '@mlightcad/mtext-parser';
1
2
  import * as THREE from 'three';
2
3
  /**
3
4
  * A 3D point in drawing coordinates.
@@ -115,22 +116,26 @@ export declare enum CharBoxType {
115
116
  * Sentinel character used internally to represent a stack divider line.
116
117
  */
117
118
  export declare const STACK_DIVIDER_CHAR = "\uE000";
118
- export interface StyleTraits {
119
- /**
120
- * Optional layer name. Material is identified by layer and color. So it means different
121
- * materials are created for the same color and differnt layer.
122
- */
119
+ /**
120
+ * Defines color settings for text rendering, including layer/material resolution
121
+ * and ByLayer/ByBlock fallback colors.
122
+ */
123
+ export interface ColorSettings {
124
+ /** The color value to use when text is set to "by layer" color mode */
125
+ byLayerColor: number;
126
+ /** The color value to use when text is set to "by block" color mode */
127
+ byBlockColor: number;
128
+ /** Optional layer name used when resolving materials */
123
129
  layer?: string;
124
130
  /**
125
- * The color of material
126
- */
127
- color: number;
128
- /**
129
- * One flag to indicate whether the color is by layer. If it is true, it means that the
130
- * material become invalid once layer color changed.
131
+ * Default text color. Use `MTextColor.aci === 256` to indicate ByLayer.
131
132
  */
132
- isByLayer?: boolean;
133
+ color: MTextColor;
133
134
  }
135
+ /**
136
+ * Create default color settings (ByLayer + white fallback).
137
+ */
138
+ export declare const createDefaultColorSettings: () => ColorSettings;
134
139
  /**
135
140
  * Represents the data structure for multiline text (MText) entities.
136
141
  * Contains all necessary properties to define the appearance and positioning of text.
@@ -164,7 +169,7 @@ export interface MTextData {
164
169
  * This interface contains properties that control various aspects of text rendering including font,
165
170
  * dimensions, and display characteristics.
166
171
  */
167
- export interface TextStyle extends StyleTraits {
172
+ export interface TextStyle {
168
173
  /** The unique name identifier for this text style */
169
174
  name: string;
170
175
  /** Flag indicating standard text style settings. Controls various text generation behaviors */
@@ -186,14 +191,3 @@ export interface TextStyle extends StyleTraits {
186
191
  /** Optional extended font settings or alternative font specification */
187
192
  extendedFont?: string;
188
193
  }
189
- /**
190
- * Defines the default color settings for special color modes in text rendering.
191
- * These settings are used to resolve color values when text uses layer-dependent
192
- * or block-dependent coloring.
193
- */
194
- export interface ColorSettings {
195
- /** The color value to use when text is set to "by layer" color mode */
196
- byLayerColor: number;
197
- /** The color value to use when text is set to "by block" color mode */
198
- byBlockColor: number;
199
- }
@@ -40,12 +40,14 @@ export declare class UnifiedRenderer {
40
40
  getDefaultMode(): RenderMode;
41
41
  /**
42
42
  * Render MText using the current mode asynchronously.
43
+ * @param colorSettings - Optional color context (ByLayer, ByBlock colors).
43
44
  * @param mode - Rendering mode used. If undefined, the default rendering mode is used.
44
45
  */
45
46
  asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings, mode?: RenderMode): Promise<MTextObject>;
46
47
  /**
47
48
  * Render MText using the current mode synchronously. Main thread render is always used
48
49
  * for this function because web worker renderer doesn't support rendering synchronously.
50
+ * @param colorSettings - Optional color context (ByLayer, ByBlock colors).
49
51
  */
50
52
  syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
51
53
  /**
@@ -178,7 +178,8 @@ export declare class WebWorkerRenderer implements MTextBaseRenderer {
178
178
  /**
179
179
  * Reconstruct MText object from JSON serialized data
180
180
  */
181
- reconstructMText(serializedData: SerializedMText, textStyle: TextStyle): MTextObject;
181
+ reconstructMText(serializedData: SerializedMText, colorSettings: ColorSettings): MTextObject;
182
+ private buildMaterialColorSettings;
182
183
  private deserializeCharBoxes;
183
184
  private collectLayout;
184
185
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlightcad/mtext-renderer",
3
- "version": "0.10.4",
3
+ "version": "0.10.5",
4
4
  "description": "AutoCAD MText renderer based on Three.js",
5
5
  "license": "MIT",
6
6
  "author": "MLight Lee <mlight.lee@outlook.com>",