@mlightcad/mtext-renderer 0.4.0 → 0.4.2
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/README.md +14 -0
- package/dist/font/fontManager.d.ts +11 -2
- package/dist/index.js +40 -11
- package/dist/index.umd.cjs +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -232,6 +232,20 @@ const mtext = new MText(
|
|
|
232
232
|
scene.add(mtext);
|
|
233
233
|
```
|
|
234
234
|
|
|
235
|
+
If all of fonts or certain fonts are not needed any more after rendering, you can call method `release` of class `FontManager` to free memory occupied by them. Based on testing, one Chinese mesh font file may take 40M memory.
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
// ---
|
|
239
|
+
// FontManager: Releasing Fonts
|
|
240
|
+
// ---
|
|
241
|
+
// To release all loaded fonts and free memory:
|
|
242
|
+
fontManager.release();
|
|
243
|
+
|
|
244
|
+
// To release a specific font by name (e.g., 'simsun'):
|
|
245
|
+
fontManager.release('simsun');
|
|
246
|
+
// Returns true if the font was found and released, false otherwise.
|
|
247
|
+
```
|
|
248
|
+
|
|
235
249
|
## License
|
|
236
250
|
|
|
237
251
|
MIT
|
|
@@ -128,7 +128,16 @@ export declare class FontManager {
|
|
|
128
128
|
*/
|
|
129
129
|
getUnsupportedChar(): Record<string, number>;
|
|
130
130
|
/**
|
|
131
|
-
* Releases
|
|
131
|
+
* Releases loaded fonts from memory.
|
|
132
|
+
*
|
|
133
|
+
* - If no argument is provided, all loaded fonts are released and the font map is cleared.
|
|
134
|
+
* - If a font name is provided, only that specific font is released from the font map.
|
|
135
|
+
*
|
|
136
|
+
* This is useful for freeing up memory, especially when working with large font files (e.g., Chinese mesh fonts).
|
|
137
|
+
* Notes: Based on testing, one Chinese mesh font file may take 40M memory.
|
|
138
|
+
*
|
|
139
|
+
* @param fontToRelease - (Optional) The name of the font to release. If omitted, all fonts are released.
|
|
140
|
+
* @returns `true` if the operation succeeded (all fonts released or the specified font was found and deleted), `false` if the specified font was not found.
|
|
132
141
|
*/
|
|
133
|
-
release():
|
|
142
|
+
release(fontToRelease?: string): boolean;
|
|
134
143
|
}
|
package/dist/index.js
CHANGED
|
@@ -9408,7 +9408,7 @@ class un extends gn {
|
|
|
9408
9408
|
return new Sr("?", e, this);
|
|
9409
9409
|
}
|
|
9410
9410
|
}
|
|
9411
|
-
|
|
9411
|
+
class Q {
|
|
9412
9412
|
/**
|
|
9413
9413
|
* Converts an unsigned byte to a signed byte as used in SHX format.
|
|
9414
9414
|
* Values > 127 are converted to their signed equivalent (-128 to -1).
|
|
@@ -9563,7 +9563,7 @@ let Q = class {
|
|
|
9563
9563
|
`Position ${e} is out of range for the data length ${this.data.byteLength}!`
|
|
9564
9564
|
);
|
|
9565
9565
|
}
|
|
9566
|
-
}
|
|
9566
|
+
}
|
|
9567
9567
|
var $ = /* @__PURE__ */ ((t) => (t.SHAPES = "shapes", t.BIGFONT = "bigfont", t.UNIFONT = "unifont", t))($ || {});
|
|
9568
9568
|
let nl = class {
|
|
9569
9569
|
parse(e) {
|
|
@@ -10763,13 +10763,22 @@ class Ue {
|
|
|
10763
10763
|
return this.unsupportedChars;
|
|
10764
10764
|
}
|
|
10765
10765
|
/**
|
|
10766
|
-
* Releases
|
|
10766
|
+
* Releases loaded fonts from memory.
|
|
10767
|
+
*
|
|
10768
|
+
* - If no argument is provided, all loaded fonts are released and the font map is cleared.
|
|
10769
|
+
* - If a font name is provided, only that specific font is released from the font map.
|
|
10770
|
+
*
|
|
10771
|
+
* This is useful for freeing up memory, especially when working with large font files (e.g., Chinese mesh fonts).
|
|
10772
|
+
* Notes: Based on testing, one Chinese mesh font file may take 40M memory.
|
|
10773
|
+
*
|
|
10774
|
+
* @param fontToRelease - (Optional) The name of the font to release. If omitted, all fonts are released.
|
|
10775
|
+
* @returns `true` if the operation succeeded (all fonts released or the specified font was found and deleted), `false` if the specified font was not found.
|
|
10767
10776
|
*/
|
|
10768
|
-
release() {
|
|
10769
|
-
this.fontMap.clear();
|
|
10777
|
+
release(e) {
|
|
10778
|
+
return e == null ? (this.fontMap.clear(), !0) : this.fontMap.delete(e);
|
|
10770
10779
|
}
|
|
10771
10780
|
}
|
|
10772
|
-
class
|
|
10781
|
+
class Fl {
|
|
10773
10782
|
/**
|
|
10774
10783
|
* Creates a new instance of DefaultFontLoader
|
|
10775
10784
|
*/
|
|
@@ -11379,6 +11388,26 @@ class gl {
|
|
|
11379
11388
|
}
|
|
11380
11389
|
s += "\\M";
|
|
11381
11390
|
continue;
|
|
11391
|
+
case "U":
|
|
11392
|
+
if (this.scanner.peek() === "+") {
|
|
11393
|
+
this.scanner.consume(1);
|
|
11394
|
+
const c = this.scanner.tail.match(/^[0-9A-Fa-f]{4,8}/);
|
|
11395
|
+
if (c) {
|
|
11396
|
+
const f = c[0];
|
|
11397
|
+
this.scanner.consume(f.length);
|
|
11398
|
+
const h = parseInt(f, 16);
|
|
11399
|
+
let p = "";
|
|
11400
|
+
try {
|
|
11401
|
+
p = String.fromCodePoint(h);
|
|
11402
|
+
} catch {
|
|
11403
|
+
p = "▯";
|
|
11404
|
+
}
|
|
11405
|
+
return s ? [1, s] : [1, p];
|
|
11406
|
+
}
|
|
11407
|
+
this.scanner.consume(-1);
|
|
11408
|
+
}
|
|
11409
|
+
s += "\\U";
|
|
11410
|
+
continue;
|
|
11382
11411
|
default:
|
|
11383
11412
|
if (l)
|
|
11384
11413
|
try {
|
|
@@ -12480,7 +12509,7 @@ class xl {
|
|
|
12480
12509
|
}
|
|
12481
12510
|
}
|
|
12482
12511
|
const Bt = /* @__PURE__ */ new R.Vector3(), we = /* @__PURE__ */ new R.Vector3(), Pt = /* @__PURE__ */ new R.Vector3(), It = /* @__PURE__ */ new R.Quaternion(), Gt = /* @__PURE__ */ new R.Matrix4(), dn = /* @__PURE__ */ new R.Matrix4(), vn = /* @__PURE__ */ new R.Vector3(1, 0, 0);
|
|
12483
|
-
class
|
|
12512
|
+
class Cl extends R.Object3D {
|
|
12484
12513
|
/**
|
|
12485
12514
|
* Extracts all unique font names used in an MText string.
|
|
12486
12515
|
* This function searches for font commands in the format \f{fontname}| or \f{fontname}; and returns a set of unique font names.
|
|
@@ -12698,7 +12727,7 @@ class wl extends R.Object3D {
|
|
|
12698
12727
|
this.getBoxes(n[a], r);
|
|
12699
12728
|
}
|
|
12700
12729
|
}
|
|
12701
|
-
class
|
|
12730
|
+
class wl {
|
|
12702
12731
|
constructor() {
|
|
12703
12732
|
this.lineBasicMaterials = {}, this.meshBasicMaterials = {}, this.unsupportedTextStyles = {};
|
|
12704
12733
|
}
|
|
@@ -12716,12 +12745,12 @@ class El {
|
|
|
12716
12745
|
export {
|
|
12717
12746
|
gn as BaseFont,
|
|
12718
12747
|
yn as BaseTextShape,
|
|
12719
|
-
|
|
12748
|
+
Fl as DefaultFontLoader,
|
|
12720
12749
|
dr as EventManager,
|
|
12721
12750
|
Se as FontFactory,
|
|
12722
12751
|
Ue as FontManager,
|
|
12723
|
-
|
|
12752
|
+
Cl as MText,
|
|
12724
12753
|
hl as MTextAttachmentPoint,
|
|
12725
12754
|
Ze as MTextFlowDirection,
|
|
12726
|
-
|
|
12755
|
+
wl as StyleManager
|
|
12727
12756
|
};
|