@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.
- package/dist/index.js +2402 -2341
- package/dist/index.umd.cjs +7 -6
- package/dist/mtext-renderer-worker.js +1959 -1903
- package/lib/font/shxFont.d.ts +6 -0
- package/lib/font/shxTextShape.d.ts +10 -0
- package/lib/renderer/colorUtils.d.ts +8 -0
- package/lib/renderer/index.d.ts +1 -0
- package/lib/renderer/mtextDataUtils.d.ts +27 -0
- package/lib/renderer/mtextProcessor.d.ts +16 -8
- package/lib/worker/webWorkerRenderer.d.ts +0 -1
- package/package.json +1 -1
package/lib/font/shxFont.d.ts
CHANGED
|
@@ -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;
|
package/lib/renderer/index.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
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
|
/**
|