@@ -295,6 +295,88 @@ export class Font {
295295 return extents ;
296296 }
297297
298+ /**
299+ * Fetches the glyph ID for a Unicode code point in the specified
300+ * font, with an optional variation selector.
301+ *
302+ * If `variationSelector` is 0, it is equivalent to
303+ * {@link Font.nominalGlyph}; otherwise it is equivalent to
304+ * {@link Font.variationGlyph}.
305+ *
306+ * @param unicode The Unicode code point to query.
307+ * @param variationSelector A variation-selector code point.
308+ * @returns The glyph ID, or undefined if not found.
309+ */
310+ glyph ( unicode : number , variationSelector : number = 0 ) : number | undefined {
311+ const sp = Module . stackSave ( ) ;
312+ const glyphIdPtr = Module . stackAlloc ( 4 ) ;
313+ let glyphId : number | undefined ;
314+ if (
315+ exports . hb_font_get_glyph (
316+ this . ptr ,
317+ unicode ,
318+ variationSelector ,
319+ glyphIdPtr ,
320+ )
321+ ) {
322+ glyphId = Module . HEAPU32 [ glyphIdPtr / 4 ] ;
323+ }
324+ Module . stackRestore ( sp ) ;
325+ return glyphId ;
326+ }
327+
328+ /**
329+ * Fetches the nominal glyph ID for a Unicode code point in the
330+ * specified font.
331+ *
332+ * This version of the function should not be used to fetch glyph IDs
333+ * for code points modified by variation selectors. For variation-selector
334+ * support, use {@link Font.variationGlyph} or {@link Font.glyph}.
335+ *
336+ * @param unicode The Unicode code point to query.
337+ * @returns The glyph ID, or undefined if not found.
338+ */
339+ nominalGlyph ( unicode : number ) : number | undefined {
340+ const sp = Module . stackSave ( ) ;
341+ const glyphIdPtr = Module . stackAlloc ( 4 ) ;
342+ let glyphId : number | undefined ;
343+ if ( exports . hb_font_get_nominal_glyph ( this . ptr , unicode , glyphIdPtr ) ) {
344+ glyphId = Module . HEAPU32 [ glyphIdPtr / 4 ] ;
345+ }
346+ Module . stackRestore ( sp ) ;
347+ return glyphId ;
348+ }
349+
350+ /**
351+ * Fetches the glyph ID for a Unicode code point when followed by
352+ * by the specified variation-selector code point, in the specified
353+ * font.
354+ *
355+ * @param unicode The Unicode code point to query.
356+ * @param variationSelector The variation-selector code point to query.
357+ * @returns The glyph ID, or undefined if not found.
358+ */
359+ variationGlyph (
360+ unicode : number ,
361+ variationSelector : number ,
362+ ) : number | undefined {
363+ const sp = Module . stackSave ( ) ;
364+ const glyphIdPtr = Module . stackAlloc ( 4 ) ;
365+ let glyphId : number | undefined ;
366+ if (
367+ exports . hb_font_get_variation_glyph (
368+ this . ptr ,
369+ unicode ,
370+ variationSelector ,
371+ glyphIdPtr ,
372+ )
373+ ) {
374+ glyphId = Module . HEAPU32 [ glyphIdPtr / 4 ] ;
375+ }
376+ Module . stackRestore ( sp ) ;
377+ return glyphId ;
378+ }
379+
298380 /**
299381 * Return glyph ID from name.
300382 * @param name Name of the requested glyph in the font.
0 commit comments