Customizing font functions

During shaping, HarfBuzz frequently needs to query font objects to get at the contents and parameters of the glyphs in a font file. It includes a built-in set of functions that is tailored to working with OpenType fonts. However, as was the case with Unicode functions in the buffers chapter, HarfBuzz also wants to make it easy for you to assign a substitute set of font functions if you are developing a program to work with a library or platform that provides its own font functions.

Therefore, the HarfBuzz API defines a set of virtual methods for accessing font-object properties, and you can replace the defaults with your own selections without interfering with the shaping process. Each font object in HarfBuzz includes a structure called font_funcs that serves as a vtable for the font object. The virtual methods in font_funcs are:

You can fetch the font-functions configuration for a font object by calling hb_font_get_font_funcs():

      hb_font_funcs_t *ffunctions;
      ffunctions = hb_font_get_font_funcs (font);

The individual methods can each be replaced with their own setter function, such as hb_font_funcs_set_nominal_glyph_func(*ffunctions, func, *user_data, destroy).

Font-functions structures can be reused for multiple font objects, and can be reference counted with hb_font_funcs_reference() and hb_font_funcs_destroy(). Just like other objects in HarfBuzz, you can set user-data for each font-functions structure and assign a destroy callback for it.

You can also mark a font-functions structure as immutable, with hb_font_funcs_make_immutable(). This is especially useful if your code is a library or framework that will have its own client programs. By marking your font-functions structures as immutable, you prevent your client programs from changing the configuration and introducing inconsistencies and errors downstream.