1- import { Module , exports , utf8_ptr_to_string } from "./helpers" ;
1+ import { Module , exports , registry , utf8_ptr_to_string } from "./helpers" ;
22import type { FontExtents , GlyphExtents } from "./types" ;
33import { Font } from "./font" ;
44
@@ -13,6 +13,8 @@ export class FontFuncs {
1313
1414 constructor ( ) {
1515 this . ptr = exports . hb_font_funcs_create ( ) ;
16+ const ptr = this . ptr ;
17+ registry . register ( this , ( ) => { exports . hb_font_funcs_destroy ( ptr ) ; } , this ) ;
1618 }
1719
1820 /**
@@ -33,7 +35,6 @@ export class FontFuncs {
3335 ) => {
3436 const font = new Font ( fontPtr ) ;
3537 const extents = func ( font , glyph ) ;
36- font . destroy ( ) ;
3738 if ( extents ) {
3839 Module . HEAP32 [ extentsPtr / 4 ] = extents . xBearing ;
3940 Module . HEAP32 [ extentsPtr / 4 + 1 ] = extents . yBearing ;
@@ -68,7 +69,6 @@ export class FontFuncs {
6869 const font = new Font ( fontPtr ) ;
6970 const name = utf8_ptr_to_string ( namePtr , len ) ;
7071 const glyph = func ( font , name ) ;
71- font . destroy ( ) ;
7272 if ( glyph ) {
7373 Module . HEAPU32 [ glyphPtr / 4 ] = glyph ;
7474 return 1 ;
@@ -95,7 +95,6 @@ export class FontFuncs {
9595 ) => {
9696 const font = new Font ( fontPtr ) ;
9797 const advance = func ( font , glyph ) ;
98- font . destroy ( ) ;
9998 return advance ;
10099 } ,
101100 "ippip" ,
@@ -118,7 +117,6 @@ export class FontFuncs {
118117 ) => {
119118 const font = new Font ( fontPtr ) ;
120119 const advance = func ( font , glyph ) ;
121- font . destroy ( ) ;
122120 return advance ;
123121 } ,
124122 "ippip" ,
@@ -145,7 +143,6 @@ export class FontFuncs {
145143 ) => {
146144 const font = new Font ( fontPtr ) ;
147145 const origin = func ( font , glyph ) ;
148- font . destroy ( ) ;
149146 if ( origin ) {
150147 Module . HEAP32 [ xPtr / 4 ] = origin [ 0 ] ;
151148 Module . HEAP32 [ yPtr / 4 ] = origin [ 1 ] ;
@@ -177,7 +174,6 @@ export class FontFuncs {
177174 ) => {
178175 const font = new Font ( fontPtr ) ;
179176 const origin = func ( font , glyph ) ;
180- font . destroy ( ) ;
181177 if ( origin ) {
182178 Module . HEAP32 [ xPtr / 4 ] = origin [ 0 ] ;
183179 Module . HEAP32 [ yPtr / 4 ] = origin [ 1 ] ;
@@ -208,7 +204,6 @@ export class FontFuncs {
208204 ) => {
209205 const font = new Font ( fontPtr ) ;
210206 const kerning = func ( font , firstGlyph , secondGlyph ) ;
211- font . destroy ( ) ;
212207 return kerning ;
213208 } ,
214209 "ippiip" ,
@@ -234,7 +229,6 @@ export class FontFuncs {
234229 ) => {
235230 const font = new Font ( fontPtr ) ;
236231 const name = func ( font , glyph ) ;
237- font . destroy ( ) ;
238232 if ( name ) {
239233 utf8Encoder . encodeInto (
240234 name ,
@@ -267,7 +261,6 @@ export class FontFuncs {
267261 ) => {
268262 const font = new Font ( fontPtr ) ;
269263 const glyph = func ( font , unicode ) ;
270- font . destroy ( ) ;
271264 if ( glyph ) {
272265 Module . HEAPU32 [ glyphPtr / 4 ] = glyph ;
273266 return 1 ;
@@ -302,7 +295,6 @@ export class FontFuncs {
302295 ) => {
303296 const font = new Font ( fontPtr ) ;
304297 const glyph = func ( font , unicode , variationSelector ) ;
305- font . destroy ( ) ;
306298 if ( glyph ) {
307299 Module . HEAPU32 [ glyphPtr / 4 ] = glyph ;
308300 return 1 ;
@@ -329,7 +321,6 @@ export class FontFuncs {
329321 ) => {
330322 const font = new Font ( fontPtr ) ;
331323 const extents = func ( font ) ;
332- font . destroy ( ) ;
333324 if ( extents ) {
334325 Module . HEAP32 [ extentsPtr / 4 ] = extents . ascender ;
335326 Module . HEAP32 [ extentsPtr / 4 + 1 ] = extents . descender ;
@@ -358,7 +349,6 @@ export class FontFuncs {
358349 ) => {
359350 const font = new Font ( fontPtr ) ;
360351 const extents = func ( font ) ;
361- font . destroy ( ) ;
362352 if ( extents ) {
363353 Module . HEAP32 [ extentsPtr / 4 ] = extents . ascender ;
364354 Module . HEAP32 [ extentsPtr / 4 + 1 ] = extents . descender ;
@@ -371,9 +361,4 @@ export class FontFuncs {
371361 ) ;
372362 exports . hb_font_funcs_set_font_v_extents_func ( this . ptr , funcPtr , 0 , 0 ) ;
373363 }
374-
375- /** Free the object. */
376- destroy ( ) : void {
377- exports . hb_font_funcs_destroy ( this . ptr ) ;
378- }
379364}
0 commit comments