@mlightcad/mtext-renderer 0.10.15 → 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.
@@ -32,31 +32,8 @@ export declare class ShxFont extends BaseFont {
32
32
  getSpaceAdvance(size: number): number;
33
33
  generateShapes(text: string, size: number): ShxTextShape[];
34
34
  /**
35
- * Scale factor that converts AutoCAD's `TEXT.height` (cap-height in the SHX
36
- * convention) into the em-box-scaled size expected by `generateShapes`.
37
- *
38
- * SHX glyphs are defined with `baseUp` units of cap-height (height of an
39
- * uppercase letter above the baseline) and `height` units of total em-box
40
- * (cap-height + descender + headroom for accents). AutoCAD's DXF group 40
41
- * for TEXT/ATTRIB/MTEXT is the cap-height — the historical SHX convention
42
- * since the format's introduction in AutoCAD R2 (1985), kept by AutoCAD
43
- * when TrueType support was added in the early 1990s so that DWGs portable
44
- * across font formats render at consistent visual sizes.
45
- *
46
- * Returning `1` (the previous behavior) meant SHX glyphs were rendered at
47
- * `baseUp / height` of the expected size — typically ~0.75 for western
48
- * fonts like `romans.shx`/`complex.shx` where `baseUp=21, height=28`.
49
- * Multiplying by `height / baseUp` restores the cap-height interpretation.
50
- *
51
- * Mirrors the behavior already in place for mesh fonts (see
52
- * `meshFontParser.ts` where `scaleFactor = unitsPerEm / glyph('A').yMax`),
53
- * isolated to the glyph render path only — `mtextProcessor.currentLayoutFontSize`
54
- * divides by this factor to keep layout metrics (line height, attachment
55
- * offsets, blank width) on the original cap-height scale.
56
- *
57
- * @returns `height / baseUp` when both are populated and positive; `1`
58
- * otherwise (e.g. exotic BIGFONT/symbol fonts without standard metrics),
59
- * matching the prior behavior as a safe fallback.
35
+ * SHX font always has fixed scale factor 1.
36
+ * @returns Always return value 1
60
37
  */
61
38
  getScaleFactor(): number;
62
39
  /**
@@ -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
  */
@@ -299,6 +307,7 @@ export declare class MTextProcessor {
299
307
  */
300
308
  private getCharShape;
301
309
  private advanceToNextLine;
310
+ private captureCurrentLineAdvance;
302
311
  private countFinalCharBoxes;
303
312
  private applyPendingEmptyLineYAdjust;
304
313
  private resolveCharBoxTarget;
@@ -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.15",
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>",