@mlightcad/mtext-renderer 0.10.14 → 0.10.16

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.
@@ -24,6 +24,12 @@ export declare class ShxFont extends BaseFont {
24
24
  * @returns True if this font contains glyph of the specified character code. Otherwise, return false.
25
25
  */
26
26
  hasCode(code: number): boolean;
27
+ /**
28
+ * Horizontal advance for the space character (ASCII 32) at the given size.
29
+ * Uses the SHX glyph pen advance when defined; otherwise falls back to half the
30
+ * text height (common for AutoCAD SHX fonts).
31
+ */
32
+ getSpaceAdvance(size: number): number;
27
33
  generateShapes(text: string, size: number): ShxTextShape[];
28
34
  /**
29
35
  * SHX font always has fixed scale factor 1.
@@ -19,6 +19,16 @@ export declare class ShxTextShape extends BaseTextShape {
19
19
  * @param shape - The shape data for this character
20
20
  */
21
21
  constructor(code: number, fontSize: number, shape: ShxShape, font: ShxFont);
22
+ /**
23
+ * Resolves horizontal advance for SHX glyphs.
24
+ *
25
+ * - Unicode / shapes fonts: prefer the pen-down end X (lastPoint), which matches
26
+ * AutoCAD's advance for single-byte SHX.
27
+ * - Big fonts (CJK): advance is the scaled font cell width (content.width /
28
+ * content.height * fontSize). Glyph bbox or lastPoint can be narrower than the
29
+ * cell; using only bbox caused successive Han characters to overlap visually.
30
+ */
31
+ private resolveAdvanceWidth;
22
32
  protected calcWidth(): number;
23
33
  offset(offset: Point): ShxTextShape;
24
34
  /**
@@ -1,2 +1,10 @@
1
1
  import { ColorSettings } from './types';
2
2
  export declare function resolveMTextColor(colorSettings: ColorSettings): number;
3
+ /**
4
+ * Rebuild ColorSettings for a worker-deserialized glyph material.
5
+ *
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.
9
+ */
10
+ export declare function buildWorkerMaterialColorSettings(base: ColorSettings, resolvedColor: number, baseByLayer: boolean): ColorSettings;
@@ -1,5 +1,6 @@
1
1
  export * from './colorUtils';
2
2
  export * from './constants';
3
3
  export * from './mtext';
4
+ export * from './mtextDataUtils';
4
5
  export * from './styleManager';
5
6
  export * from './types';
@@ -0,0 +1,27 @@
1
+ import { MTextData } from './types';
2
+ /**
3
+ * Minimum width-to-height ratio for a declared MTEXT wrap box to be treated as
4
+ * a real column width rather than a mistaken width factor or other bad DXF value.
5
+ */
6
+ export declare const MIN_REASONABLE_MTEXT_WIDTH_HEIGHT_RATIO = 1.5;
7
+ /**
8
+ * Conservative CJK full-width glyph advance as a fraction of cap height, used
9
+ * only when estimating a replacement wrap width from explicit line content.
10
+ */
11
+ export declare const CJK_MTEXT_CHAR_WIDTH_HEIGHT_RATIO = 0.8;
12
+ /**
13
+ * Estimates a usable MTEXT wrap width from the longest explicit line in the raw
14
+ * MTEXT string while preserving explicit line breaks such as `\P`.
15
+ */
16
+ export declare function estimateMTextWrapWidth(text: string, height: number): number;
17
+ /**
18
+ * Resolves the MTEXT wrap width used for layout and anchoring.
19
+ *
20
+ * Some CAD files contain MTEXT group-code 41 values that are smaller than a
21
+ * single glyph height, usually because the value came from a text width factor
22
+ * instead of an actual wrapping box width. Treating that tiny positive value as
23
+ * the word-wrap width forces CJK text to wrap one character per line. When the
24
+ * width is clearly impossible as a layout width, estimate a usable width from
25
+ * the longest explicit MTEXT line and preserve explicit line breaks such as `\P`.
26
+ */
27
+ export declare function resolveMTextWrapWidth(mtextData: Pick<MTextData, 'text' | 'height' | 'width'>): number;
@@ -59,6 +59,7 @@ export declare class MTextProcessor {
59
59
  private _options;
60
60
  private _totalHeight;
61
61
  private _hOffset;
62
+ private _maxLineAdvance;
62
63
  private _vOffset;
63
64
  private _lineCount;
64
65
  private _currentLineObjects;
@@ -103,6 +104,13 @@ export declare class MTextProcessor {
103
104
  * The maximum width of one text line
104
105
  */
105
106
  get maxWidth(): number;
107
+ /**
108
+ * Maximum logical pen advance across processed visual lines.
109
+ *
110
+ * Unlike visible geometry bounds, this keeps the text insertion origin tied to
111
+ * the layout pen position even when glyphs have side bearings or overhangs.
112
+ */
113
+ get maxLineAdvance(): number;
106
114
  /**
107
115
  * The direction that the text string follows from its start to its finish.
108
116
  */
@@ -166,6 +174,8 @@ export declare class MTextProcessor {
166
174
  * The current scale factor of character width
167
175
  */
168
176
  get currentWidthFactor(): number;
177
+ /** Horizontal advance for one space, including tracking and width factor. */
178
+ get currentBlankAdvance(): number;
169
179
  /**
170
180
  * All of THREE.js objects in current line. It contains objects in all of sections of this line.
171
181
  */
@@ -297,6 +307,7 @@ export declare class MTextProcessor {
297
307
  */
298
308
  private getCharShape;
299
309
  private advanceToNextLine;
310
+ private captureCurrentLineAdvance;
300
311
  private countFinalCharBoxes;
301
312
  private applyPendingEmptyLineYAdjust;
302
313
  private resolveCharBoxTarget;
@@ -305,14 +316,11 @@ export declare class MTextProcessor {
305
316
  */
306
317
  private processAlignment;
307
318
  /**
308
- * In AutoCAD, the width of a regular space character (ASCII 32, the space key on the keyboard) in MText
309
- * depends on the current font and text height, and is not a fixed value.
310
- * Specifically:
311
- * - Space width Text height × space width ratio defined by the font
312
- * - For common TrueType fonts (like Arial), the space width is typically about 1/4 to 1/3 of the text height.
313
- * For example, if the text height is 10 (units), the space width would be approximately 2.5 to 3.3 units.
314
- * - For SHX fonts (AutoCAD's built-in vector fonts, such as txt.shx), the space width is often half the text height.
315
- * So if the text height is 10, the space width is typically 5 units.
319
+ * Resolves horizontal advance for an ASCII space in the active font.
320
+ *
321
+ * AutoCAD uses each font's own space glyph metrics (SHX pen advance or TrueType
322
+ * horizontal advance). A fixed fraction of text height (e.g. 50% for SHX) is only
323
+ * a rough fallback when the font has no space definition.
316
324
  */
317
325
  private calculateBlankWidthForFont;
318
326
  /**
@@ -179,7 +179,6 @@ export declare class WebWorkerRenderer implements MTextBaseRenderer {
179
179
  * Reconstruct MText object from JSON serialized data
180
180
  */
181
181
  reconstructMText(serializedData: SerializedMText, colorSettings: ColorSettings): MTextObject;
182
- private buildMaterialColorSettings;
183
182
  private deserializeCharBoxes;
184
183
  private collectLayout;
185
184
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlightcad/mtext-renderer",
3
- "version": "0.10.14",
3
+ "version": "0.10.16",
4
4
  "description": "AutoCAD MText renderer based on Three.js",
5
5
  "license": "MIT",
6
6
  "author": "MLight Lee <mlight.lee@outlook.com>",