@mlightcad/mtext-renderer 0.3.7 → 0.4.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/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 all loaded fonts and clears the font map
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(): void;
142
+ release(fontToRelease?: string): boolean;
134
143
  }
package/dist/index.js CHANGED
@@ -10763,10 +10763,19 @@ class Ue {
10763
10763
  return this.unsupportedChars;
10764
10764
  }
10765
10765
  /**
10766
- * Releases all loaded fonts and clears the font map
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
10781
  class Cl {
@@ -12002,7 +12011,7 @@ class xl {
12002
12011
  this.textStyle.font.toLowerCase(),
12003
12012
  a.fontSize
12004
12013
  )
12005
- }), this._currentContext.setColorFromHex(a.byLayerColor), this._currentContext.fontFace.family = this.textStyle.font.toLowerCase(), this._currentContext.widthFactor = { value: a.widthFactor, isRelative: !0 }, this._currentContext.oblique = e.obliqueAngle || 0, this._maxFontSize = 0, this._currentHorizontalAlignment = a.horizontalAlignment, this._currentIndent = 0, this._currentLeftMargin = 0, this._currentRightMargin = 0, this.initLineParams();
12014
+ }), this._currentContext.setColorFromHex(e.color), this._currentContext.fontFace.family = this.textStyle.font.toLowerCase(), this._currentContext.widthFactor = { value: a.widthFactor, isRelative: !0 }, this._currentContext.oblique = e.obliqueAngle || 0, this._maxFontSize = 0, this._currentHorizontalAlignment = a.horizontalAlignment, this._currentIndent = 0, this._currentLeftMargin = 0, this._currentRightMargin = 0, this.initLineParams();
12006
12015
  }
12007
12016
  get fontManager() {
12008
12017
  return this._fontManager;