@mlightcad/mtext-renderer 0.8.10 → 0.9.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.
@@ -86,7 +86,17 @@ export declare class MText extends THREE.Object3D {
86
86
  get box(): THREE.Box3;
87
87
  set box(box: THREE.Box3);
88
88
  /**
89
- * Gets per-character bounding boxes with debug characters.
89
+ * Gets logical text token boxes for picking/debug.
90
+ *
91
+ * Token semantics:
92
+ * - `CHAR`: `char` is the rendered character, `box` is defined, `children` is empty.
93
+ * - `NEW_PARAGRAPH`: `char` is `\n`, `box` is `undefined`, `children` is empty.
94
+ * - `STACK`: `char` is empty string (`''`), `box` is the union of stack component boxes,
95
+ * and `children` contains the stack sub-components.
96
+ *
97
+ * Notes:
98
+ * - Superscript/subscript stacks (`^`) are emitted as regular `CHAR` entries.
99
+ * - Fraction stacks (`/`, `#`) are emitted as one `STACK` entry.
90
100
  */
91
101
  get charBoxes(): CharBox[];
92
102
  /**
@@ -3,6 +3,7 @@ import { FontManager } from '../font';
3
3
  import { StyleManager } from './styleManager';
4
4
  import { MTextFlowDirection, TextStyle } from './types';
5
5
  import * as THREE from 'three';
6
+ export declare const STACK_DIVIDER_CHAR = "\uE000";
6
7
  export interface MTextFormatOptions {
7
8
  /**
8
9
  * Font size.
@@ -71,6 +72,7 @@ export declare class MTextProcessor {
71
72
  * so it persists until explicitly changed by another paragraph alignment command.
72
73
  */
73
74
  private _currentHorizontalAlignment;
75
+ private _lastCharBoxTarget;
74
76
  private _currentIndent;
75
77
  private _currentLeftMargin;
76
78
  private _currentRightMargin;
@@ -189,6 +191,12 @@ export declare class MTextProcessor {
189
191
  private processGeometries;
190
192
  private processWord;
191
193
  private processStack;
194
+ private recordStackDivider;
195
+ /**
196
+ * Convert a legacy top-anchored vOffset (used by stack/sub/sup logic) into
197
+ * the current baseline-anchored coordinate system.
198
+ */
199
+ private convertTopAlignedVOffset;
192
200
  private processBlank;
193
201
  private recordLineBreak;
194
202
  private processChar;
@@ -206,6 +214,8 @@ export declare class MTextProcessor {
206
214
  */
207
215
  private getCharShape;
208
216
  private startNewLine;
217
+ private advanceToNextLine;
218
+ private resolveCharBoxTarget;
209
219
  /**
210
220
  * Apply translation on the specified buffer geometries according to text alignment setting
211
221
  */
@@ -1,34 +1,90 @@
1
1
  import * as THREE from 'three';
2
+ /**
3
+ * A 3D point in drawing coordinates.
4
+ */
2
5
  export interface Point3d {
6
+ /** X coordinate */
3
7
  x: number;
8
+ /** Y coordinate */
4
9
  y: number;
10
+ /** Z coordinate */
5
11
  z: number;
6
12
  }
13
+ /**
14
+ * A 2D point in drawing coordinates.
15
+ */
7
16
  export interface Point2d {
17
+ /** X coordinate */
8
18
  x: number;
19
+ /** Y coordinate */
9
20
  y: number;
10
21
  }
22
+ /**
23
+ * Defines the global text flow direction for MText layout.
24
+ */
11
25
  export declare enum MTextFlowDirection {
26
+ /** Text flows from left to right. */
12
27
  LEFT_TO_RIGHT = 1,
28
+ /** Text flows from right to left. */
13
29
  RIGHT_TO_LEFT = 2,
30
+ /** Text flows from top to bottom. */
14
31
  TOP_TO_BOTTOM = 3,
32
+ /** Text flows from bottom to top. */
15
33
  BOTTOM_TO_TOP = 4,
34
+ /** Use the direction defined by the active text style. */
16
35
  BY_STYLE = 5
17
36
  }
37
+ /**
38
+ * Anchor position used to align rendered MText relative to its insertion point.
39
+ */
18
40
  export declare enum MTextAttachmentPoint {
41
+ /** Top-left corner. */
19
42
  TopLeft = 1,
43
+ /** Top-center point. */
20
44
  TopCenter = 2,
45
+ /** Top-right corner. */
21
46
  TopRight = 3,
47
+ /** Middle-left point. */
22
48
  MiddleLeft = 4,
49
+ /** Center point. */
23
50
  MiddleCenter = 5,
51
+ /** Middle-right point. */
24
52
  MiddleRight = 6,
53
+ /** Bottom-left corner. */
25
54
  BottomLeft = 7,
55
+ /** Bottom-center point. */
26
56
  BottomCenter = 8,
57
+ /** Bottom-right corner. */
27
58
  BottomRight = 9
28
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`, `box` is `undefined`, `children` is empty.
66
+ * - `STACK`: `char` is `''`, `box` is the union box of stack components, `children` contains stack parts.
67
+ */
29
68
  export interface CharBox {
30
- box: THREE.Box3;
69
+ /** Token type. */
70
+ type: CharBoxType;
71
+ /** Token bounding box in local MText coordinates (undefined for `NEW_PARAGRAPH`). */
72
+ box?: THREE.Box3;
73
+ /** Token character payload (`''` for `STACK`, `\n` for `NEW_PARAGRAPH`). */
31
74
  char: string;
75
+ /** Nested token components (currently used by `STACK`). */
76
+ children: CharBox[];
77
+ }
78
+ /**
79
+ * Type of logical token emitted in {@link CharBox} output.
80
+ */
81
+ export declare enum CharBoxType {
82
+ /** Regular rendered character token. */
83
+ CHAR = "CHAR",
84
+ /** Explicit paragraph break token. */
85
+ NEW_PARAGRAPH = "NEW_PARAGRAPH",
86
+ /** Stack token (for fraction-style stacked expressions). */
87
+ STACK = "STACK"
32
88
  }
33
89
  export interface StyleTraits {
34
90
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlightcad/mtext-renderer",
3
- "version": "0.8.10",
3
+ "version": "0.9.0",
4
4
  "description": "AutoCAD MText renderer based on Three.js",
5
5
  "license": "MIT",
6
6
  "author": "MLight Lee <mlight.lee@outlook.com>",