@mlightcad/mtext-renderer 0.11.5 → 0.11.7

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,3 +1,4 @@
1
+ import { ShxFontType } from '@mlightcad/shx-parser';
1
2
  import { EventManager } from '../common';
2
3
  import { BaseFont } from './baseFont';
3
4
  import { BaseTextShape } from './baseTextShape';
@@ -240,6 +241,12 @@ export declare class FontManager {
240
241
  * @returns The type of the font. If the specified font can't be found, `undefined` is returned
241
242
  */
242
243
  getFontType(fontName: string): FontType | undefined;
244
+ /**
245
+ * Gets the type of the SHX font. Such as BIGFONT, SHAPES, UNIFONT.
246
+ * @param fontName - The name of the font
247
+ * @returns The type of the SHX font, or undefined if the specified font is not a SHX font
248
+ */
249
+ getShxFontType(fontName: string): ShxFontType | undefined;
243
250
  /**
244
251
  * Gets the shape to display when a character is not found
245
252
  * @param size - The size of the shape
@@ -82,6 +82,11 @@ export declare class MeshFont extends BaseFont {
82
82
  * @returns An object containing the opentype font and parsed metadata
83
83
  */
84
84
  private parseMeshFont;
85
+ /**
86
+ * Resolves the opentype lookup character for a drawing character.
87
+ * Tries Unicode first, then Symbol encoding (0xF000 + ASCII) for GDT fonts.
88
+ */
89
+ private opentypeLookupChar;
85
90
  /**
86
91
  * Whether opentype maps the character to a real glyph (not .notdef at index 0).
87
92
  *
@@ -1,7 +1,9 @@
1
- import { ShxFontData } from '@mlightcad/shx-parser';
1
+ import { ShxFontData, ShxFontMetrics } from '@mlightcad/shx-parser';
2
2
  import { BaseFont } from './baseFont';
3
3
  import { FontData } from './font';
4
4
  import { ShxTextShape } from './shxTextShape';
5
+ /** Scaled SHX font layout metrics (cap height, cell width, etc.) from `@mlightcad/shx-parser`. */
6
+ export type { ShxFontMetrics } from '@mlightcad/shx-parser';
5
7
  /**
6
8
  * ShxFont is a class that extends BaseFont and represents a SHX font.
7
9
  * It provides methods to generate shapes for text and retrieve character shapes.
@@ -9,68 +11,88 @@ import { ShxTextShape } from './shxTextShape';
9
11
  export declare class ShxFont extends BaseFont {
10
12
  /** Internal shx font instance */
11
13
  private readonly font;
14
+ /** The type of font; always `'shx'`. */
12
15
  readonly type = "shx";
16
+ /** Parsed SHX font data used for glyph lookup and layout metrics. */
13
17
  readonly data: ShxFontData;
18
+ /**
19
+ * Creates a new SHX font wrapper.
20
+ * @param fontData - Font metadata and binary SHX data used to initialize the font.
21
+ */
14
22
  constructor(fontData: FontData);
15
23
  /**
16
- * Return true if this font contains glyph of the specified character. Otherwise, return false.
17
- * @param char - The character to check
18
- * @returns True if this font contains glyph of the specified character. Otherwise, return false.
24
+ * Returns whether the font contains a glyph for the given character.
25
+ * @param char - The character to look up.
26
+ * @returns True if the font contains the character; otherwise, false.
19
27
  */
20
28
  hasChar(char: string): boolean;
21
29
  /**
22
- * Return true if this font contains glyph of the specified character code. Otherwise, return false.
23
- * @param code - The character code to check
24
- * @returns True if this font contains glyph of the specified character code. Otherwise, return false.
30
+ * Returns whether the font contains a glyph for the given character code.
31
+ * @param code - The character code to look up.
32
+ * @returns True if the font contains the code point; otherwise, false.
25
33
  */
26
34
  hasCode(code: number): boolean;
27
35
  /**
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).
36
+ * Computes the horizontal advance for a space at the requested size.
37
+ * @param size - The requested font size.
38
+ * @returns The width of the space advance.
31
39
  */
32
40
  getSpaceAdvance(size: number): number;
41
+ /**
42
+ * Converts a text string into a list of SHX text shapes.
43
+ * @param text - The text to convert.
44
+ * @param size - The requested font size.
45
+ * @returns An array of generated SHX text shapes.
46
+ */
33
47
  generateShapes(text: string, size: number): ShxTextShape[];
34
48
  /**
35
- * SHX font always has fixed scale factor 1.
36
- * @returns Always return value 1
49
+ * Returns the scale factor used by the SHX font implementation.
50
+ * @returns Always returns 1 for SHX fonts.
37
51
  */
38
52
  getScaleFactor(): number;
53
+ /**
54
+ * Gets the scaled layout metrics for the font at the requested size.
55
+ * @param size - The requested font size.
56
+ * @returns The SHX font metrics for the given size.
57
+ */
58
+ getFontMetrics(size: number): ShxFontMetrics;
39
59
  /**
40
60
  * Gets the shape data for a specific character at a given size.
41
- * If the font type is BIGFONT, please use getCodeShape to get the shape data
42
- * because the character code for BIGFONT isn't unicode.
43
- * @param char - The character to get the shape for
44
- * @param size - The desired size of the character
45
- * @returns The shape data for the character, or undefined if not found
61
+ * @param char - The character to look up.
62
+ * @param size - The requested font size.
63
+ * @returns The shape data for the character, or undefined if not found.
46
64
  */
47
65
  getCharShape(char: string, size: number): ShxTextShape | undefined;
48
66
  /**
49
67
  * Gets the shape data for a specific character code at a given size.
50
- * The passed code must the code stored in font instead of unicode.
51
- * - Unicode shx font uses unicode as character code.
52
- * - Bigfont uses a custom encoding for double-byte characters.
53
- * @param code - The character code to get the shape for
54
- * @param size - The desired size of the character
55
- * @returns The shape data for the character code, or undefined if not found
68
+ * @param code - The character code to look up.
69
+ * @param size - The requested font size.
70
+ * @returns The shape data for the code, or undefined if not found.
56
71
  */
57
72
  getCodeShape(code: number, size: number): ShxTextShape | undefined;
58
73
  /**
59
- * Gets the shape data for a named SHX shape at a given size.
60
- *
61
- * Shape names are matched case-insensitively via the underlying SHX parser.
74
+ * Gets the shape data for a named SHX shape at the requested size.
75
+ * @param name - The SHX shape name to look up.
76
+ * @param size - The requested font size.
77
+ * @returns The matching shape, or undefined if unavailable.
62
78
  */
63
79
  getShapeByName(name: string, size: number): ShxTextShape | undefined;
64
- /** True when the SHX glyph has drawable strokes or a non-zero pen advance. */
80
+ /**
81
+ * Checks whether a parsed SHX shape contains renderable strokes.
82
+ * @param shape - The shape to inspect.
83
+ * @returns True when the shape has at least one renderable segment.
84
+ */
65
85
  private static hasRenderableStrokes;
66
86
  /**
67
- * For an unsupported char, use "?" as a replacement.
87
+ * Gets the fallback text shape used for missing characters.
88
+ * @param size - The requested font size.
89
+ * @returns The fallback shape, or undefined if it cannot be built.
68
90
  */
69
91
  getNotFoundTextShape(size: number): ShxTextShape | undefined;
70
92
  /**
71
- * Gets encoded code of the specified character according to font character encoding
72
- * @param char - The character to get its code
73
- * @returns Returns encoded code of the specified character
93
+ * Resolves the internal SHX character code for a given Unicode character.
94
+ * @param char - The input character.
95
+ * @returns The internal SHX code used for lookup.
74
96
  */
75
97
  private getCode;
76
98
  }
@@ -14,26 +14,27 @@ export declare class ShxTextShape extends BaseTextShape {
14
14
  private readonly font;
15
15
  private readonly fontSize;
16
16
  /**
17
- * Creates a new instance of ShxTextShape
18
- * @param code - The character code this shape represents
19
- * @param shape - The shape data for this character
17
+ * Creates a new SHX text shape wrapper.
18
+ * @param code - The character code represented by this shape.
19
+ * @param fontSize - The font size used to resolve the shape advance width.
20
+ * @param shape - The parsed SHX shape data.
21
+ * @param font - The SHX font instance that owns the shape.
20
22
  */
21
23
  constructor(code: number, fontSize: number, shape: ShxShape, font: ShxFont);
22
24
  /**
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.
25
+ * Computes the width of the shape from its bounding box.
26
+ * @returns The width of the shape's bounding box.
30
27
  */
31
- private resolveAdvanceWidth;
32
28
  protected calcWidth(): number;
29
+ /**
30
+ * Returns a translated copy of this shape.
31
+ * @param offset - The offset to apply to the shape.
32
+ * @returns A new shape shifted by the given offset.
33
+ */
33
34
  offset(offset: Point): ShxTextShape;
34
35
  /**
35
- * Converts the text shape to a THREE.js geometry
36
- * @returns A THREE.js BufferGeometry representing the text shape
36
+ * Converts the text shape to a THREE.js geometry.
37
+ * @returns A BufferGeometry representing the text shape.
37
38
  */
38
39
  toGeometry(): THREE.BufferGeometry<THREE.NormalBufferAttributes>;
39
40
  }
@@ -105,6 +105,10 @@ export declare class MText extends THREE.Object3D {
105
105
  * Builds and places one SHX shape glyph.
106
106
  */
107
107
  loadShape(shapeData: ShapeData, style: TextStyle): THREE.Object3D<THREE.Object3DEventMap> | undefined;
108
+ /**
109
+ *
110
+ * @param options.shxFontType The type of SHX font.
111
+ */
108
112
  private finalizePlacement;
109
113
  private createShapeGroup;
110
114
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlightcad/mtext-renderer",
3
- "version": "0.11.5",
3
+ "version": "0.11.7",
4
4
  "description": "AutoCAD MText renderer based on Three.js",
5
5
  "license": "MIT",
6
6
  "author": "MLight Lee <mlight.lee@outlook.com>",
@@ -44,7 +44,7 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "@mlightcad/mtext-parser": "^1.5.0",
47
- "@mlightcad/shx-parser": "^1.3.5",
47
+ "@mlightcad/shx-parser": "^1.4.3",
48
48
  "iconv-lite": "^0.7.0",
49
49
  "idb": "^8.0.3",
50
50
  "opentype.js": "^2.0.0"