@mlightcad/mtext-renderer 0.11.10 → 0.12.1

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.
@@ -1,10 +1,30 @@
1
+ import { MTextColor } from '@mlightcad/mtext-parser';
1
2
  import { ColorSettings } from './types';
2
3
  export declare function resolveMTextColor(colorSettings: ColorSettings): number;
4
+ /** Wire-format for an `MTextColor` carried on worker glyph payloads. */
5
+ export interface SerializedMTextColor {
6
+ aci?: number | null;
7
+ rgbValue?: number | null;
8
+ }
9
+ /**
10
+ * Serializes an `MTextColor` for worker → main-thread transfer.
11
+ *
12
+ * Prefer this over baking only the resolved RGB: ACI 7 (canvas foreground) and
13
+ * ACI 255 (literal white) both resolve to `0xffffff` on a dark canvas, but only
14
+ * ACI 7 must invert when the background flips.
15
+ */
16
+ export declare function serializeMTextColor(color: MTextColor): SerializedMTextColor;
17
+ /** Revives a wire-format color into a real `MTextColor` instance. */
18
+ export declare function deserializeMTextColor(serialized?: SerializedMTextColor | null): MTextColor | undefined;
3
19
  /**
4
20
  * Rebuild ColorSettings for a worker-deserialized glyph material.
5
21
  *
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.
22
+ * Prefer {@link serializedColor} when the worker attached the original segment
23
+ * color (ACI / RGB). Falling back to resolved RGB alone cannot distinguish
24
+ * ACI 7 from ACI 255.
25
+ *
26
+ * Without a serialized color, preserve ByLayer / ByBlock / entity ACI when the
27
+ * glyph RGB still matches the entity base resolution; otherwise bake RGB for
28
+ * true inline overrides.
9
29
  */
10
- export declare function buildWorkerMaterialColorSettings(base: ColorSettings, resolvedColor: number, baseByLayer: boolean): ColorSettings;
30
+ export declare function buildWorkerMaterialColorSettings(base: ColorSettings, resolvedColor: number, baseByLayer: boolean, serializedColor?: SerializedMTextColor | null): ColorSettings;
@@ -1,8 +1,15 @@
1
1
  /**
2
- * Scale applied with `lineSpaceFactor` when computing the extra vertical gap
3
- * between MTEXT lines in {@link MTextProcessor}.
2
+ * AutoCAD single-line spacing as a multiple of text height ("3-on-5").
3
+ *
4
+ * DXF group 44 (`lineSpaceFactor`) is a ratio relative to this single spacing,
5
+ * so baseline-to-baseline distance =
6
+ * `lineSpaceFactor × LINE_SPACING_SCALE_FACTOR × textHeight`.
4
7
  */
5
- export declare const LINE_SPACING_SCALE_FACTOR = 1.666666;
8
+ export declare const LINE_SPACING_SCALE_FACTOR: number;
9
+ /**
10
+ * Default DXF group-44 line spacing factor (AutoCAD single spacing).
11
+ */
12
+ export declare const DEFAULT_LINE_SPACE_FACTOR = 1;
6
13
  /**
7
14
  * Vertical compensation needed after switching normal glyph placement from
8
15
  * top-anchored to baseline-anchored coordinates.
@@ -16,7 +16,8 @@ export interface MTextFormatOptions {
16
16
  */
17
17
  widthFactor: number;
18
18
  /**
19
- * The line space factor.
19
+ * AutoCAD DXF group-44 line spacing factor: ratio of actual line spacing to
20
+ * single spacing (`5/3` of text height). Default is `1.0`.
20
21
  */
21
22
  lineSpaceFactor: number;
22
23
  /**
@@ -165,7 +166,8 @@ export declare class MTextProcessor {
165
166
  */
166
167
  get defaultFontSize(): number;
167
168
  /**
168
- * The default line space factor
169
+ * AutoCAD DXF group-44 line spacing factor (multiple of single spacing).
170
+ * Single spacing is {@link LINE_SPACING_SCALE_FACTOR} × text height.
169
171
  */
170
172
  get defaultLineSpaceFactor(): number;
171
173
  /**
@@ -191,7 +193,11 @@ export declare class MTextProcessor {
191
193
  */
192
194
  get currentLayoutFontSize(): number;
193
195
  /**
194
- * The height of current line of texts
196
+ * Baseline-to-baseline advance for the current line (AutoCAD MTEXT semantics).
197
+ *
198
+ * Single spacing is `5/3` of the drawing-space text height; `lineSpaceFactor`
199
+ * (DXF group 44) scales that distance. Font glyph scale factors must not
200
+ * affect this layout metric — use {@link currentLayoutFontSize}.
195
201
  */
196
202
  get currentLineHeight(): number;
197
203
  /**
@@ -170,7 +170,11 @@ export interface MTextData {
170
170
  attachmentPoint?: MTextAttachmentPoint;
171
171
  /** Determines the primary direction in which text flows */
172
172
  drawingDirection?: MTextFlowDirection;
173
- /** Factor that controls the spacing between text lines. Default is 1.0 */
173
+ /**
174
+ * AutoCAD DXF group-44 line spacing factor.
175
+ * Ratio of actual baseline spacing to single spacing (`5/3` of text height).
176
+ * Default is `1.0`.
177
+ */
174
178
  lineSpaceFactor?: number;
175
179
  /** The width scaling factor applied to each character. Default is 1.0 */
176
180
  widthFactor?: number;
@@ -113,6 +113,11 @@ interface SerializedChild {
113
113
  opacity: number;
114
114
  side?: number;
115
115
  linewidth?: number;
116
+ /** Original segment colour when the worker preserved ACI/RGB semantics. */
117
+ mtextColor?: {
118
+ aci?: number | null;
119
+ rgbValue?: number | null;
120
+ };
116
121
  };
117
122
  charBoxType?: CharBox['type'];
118
123
  lineLayouts?: Array<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlightcad/mtext-renderer",
3
- "version": "0.11.10",
3
+ "version": "0.12.1",
4
4
  "description": "AutoCAD MText renderer based on Three.js",
5
5
  "license": "MIT",
6
6
  "author": "MLight Lee <mlight.lee@outlook.com>",