@mlightcad/mtext-renderer 0.7.0 → 0.7.1
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 +875 -826
- package/dist/index.umd.cjs +5 -5
- package/dist/mtext-renderer-worker.js +586 -537
- package/lib/font/fontManager.d.ts +1 -1
- package/lib/font/meshFont.d.ts +52 -2
- package/package.json +1 -1
|
@@ -36,7 +36,7 @@ export declare class FontManager {
|
|
|
36
36
|
/** Mapping of original font names to their replacements */
|
|
37
37
|
protected fontMapping: FontMapping;
|
|
38
38
|
/** Map of loaded fonts, keyed by font name */
|
|
39
|
-
protected
|
|
39
|
+
protected loadedFontMap: Map<string, BaseFont>;
|
|
40
40
|
/** List of font file names that have been loaded */
|
|
41
41
|
protected fileNames: string[];
|
|
42
42
|
/** Record of characters that are not supported by any loaded font */
|
package/lib/font/meshFont.d.ts
CHANGED
|
@@ -2,18 +2,48 @@ import { Font, FontData as ThreeFontData } from 'three/examples/jsm/loaders/Font
|
|
|
2
2
|
import { BaseFont } from './baseFont';
|
|
3
3
|
import { FontData } from './font';
|
|
4
4
|
import { MeshTextShape } from './meshTextShape';
|
|
5
|
+
interface MeshGlyph {
|
|
6
|
+
ha: number;
|
|
7
|
+
x_min: number;
|
|
8
|
+
x_max: number;
|
|
9
|
+
o?: string | undefined;
|
|
10
|
+
}
|
|
5
11
|
/**
|
|
6
12
|
* Represents the data structure for mesh-based fonts.
|
|
7
13
|
* Extends the base ThreeFontData interface with additional properties specific to mesh fonts.
|
|
8
14
|
*/
|
|
9
15
|
export interface MeshFontData extends ThreeFontData {
|
|
16
|
+
/** A map of glyphs keyed by character */
|
|
17
|
+
glyphs: Record<string, MeshGlyph>;
|
|
18
|
+
/** The full font family name */
|
|
19
|
+
familyName: string;
|
|
20
|
+
/** The font ascender */
|
|
21
|
+
ascender: number;
|
|
22
|
+
/** The font descender */
|
|
23
|
+
descender: number;
|
|
24
|
+
/** Underline position in font units */
|
|
25
|
+
underlinePosition: number;
|
|
26
|
+
/** Underline thickness in font units */
|
|
27
|
+
underlineThickness: number;
|
|
28
|
+
/** Font bounding box */
|
|
29
|
+
boundingBox: {
|
|
30
|
+
xMin: number;
|
|
31
|
+
xMax: number;
|
|
32
|
+
yMin: number;
|
|
33
|
+
yMax: number;
|
|
34
|
+
};
|
|
35
|
+
/** Font resolution (usually unitsPerEm) */
|
|
36
|
+
resolution: number;
|
|
10
37
|
/** Scale factor used to adjust the size of characters when rendering */
|
|
11
38
|
scaleFactor: number;
|
|
39
|
+
/** Original font information table */
|
|
40
|
+
original_font_information: Record<string, string>;
|
|
12
41
|
}
|
|
13
42
|
/**
|
|
14
43
|
* Represents a mesh-based font (e.g., TTF, OTF, WOFF).
|
|
15
44
|
* This class extends BaseFont to provide specific functionality for mesh fonts,
|
|
16
|
-
* including character shape generation
|
|
45
|
+
* including character shape generation, scale factor management, and
|
|
46
|
+
* **lazy glyph loading** to reduce memory consumption.
|
|
17
47
|
*/
|
|
18
48
|
export declare class MeshFont extends BaseFont {
|
|
19
49
|
/** Scale factor used to adjust the size of characters */
|
|
@@ -24,11 +54,24 @@ export declare class MeshFont extends BaseFont {
|
|
|
24
54
|
readonly type = "mesh";
|
|
25
55
|
/** The parsed font data */
|
|
26
56
|
readonly data: MeshFontData;
|
|
57
|
+
/** Internal opentype.js font instance used for on-demand glyph parsing */
|
|
58
|
+
private readonly opentypeFont;
|
|
59
|
+
/** Glyph cache to limit memory usage */
|
|
60
|
+
private readonly glyphCache;
|
|
27
61
|
/**
|
|
28
62
|
* Creates a new instance of MeshFont.
|
|
29
|
-
* @param
|
|
63
|
+
* @param fontData - Either a MeshFontData object containing font information or an ArrayBuffer containing raw font data
|
|
30
64
|
*/
|
|
31
65
|
constructor(fontData: FontData);
|
|
66
|
+
/**
|
|
67
|
+
* Parses a mesh font from raw binary data.
|
|
68
|
+
* This function converts raw font data (e.g., TTF, OTF, WOFF) into a MeshFontData object
|
|
69
|
+
* that can be used by the MeshFont class.
|
|
70
|
+
*
|
|
71
|
+
* @param data - The raw font data as an ArrayBuffer
|
|
72
|
+
* @returns An object containing the opentype font and parsed metadata
|
|
73
|
+
*/
|
|
74
|
+
private parseMeshFont;
|
|
32
75
|
/**
|
|
33
76
|
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
34
77
|
* @param char - The character to check
|
|
@@ -41,6 +84,12 @@ export declare class MeshFont extends BaseFont {
|
|
|
41
84
|
* @returns True if this font contains glyph of the specified character code. Otherwise, return false.
|
|
42
85
|
*/
|
|
43
86
|
hasCode(code: number): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Loads glyph data lazily when requested.
|
|
89
|
+
* Parsed glyphs are cached in an LRU cache to limit memory usage.
|
|
90
|
+
* @param char - The character whose glyph should be loaded
|
|
91
|
+
*/
|
|
92
|
+
private _loadGlyphIfNeeded;
|
|
44
93
|
/**
|
|
45
94
|
* Generates shapes for a text string
|
|
46
95
|
* @param text - The text to generate shapes for
|
|
@@ -76,3 +125,4 @@ export declare class MeshFont extends BaseFont {
|
|
|
76
125
|
*/
|
|
77
126
|
getNotFoundTextShape(size: number): MeshTextShape;
|
|
78
127
|
}
|
|
128
|
+
export {};
|