utils.glyph_available

Returns the glyph index of a glyph (character) in a font

Prototype

n = utils.glyph_available (font, glyph)

Description

This lets you test if a particular glyph can be rendered in the specified font. This lets a script writer see if a suitable Unicode font has been installed when using UTF-8 mode.

For example:

print (utils.glyph_available ("Arial Unicode MS", 0x2710) )  --> 4439
Zero will be returned if the glyph is not in the font. Nil will be returned if the gdi32 DLL cannot be loaded or if the function GetGlyphIndicesW is not available from Windows.

The number 31 might be returned which probably indicates that the glyph is not in that font.

Other numbers (other than nil, 0 or 31) would indicate that the glyph is available. The exact number represents the "glyph index" in the font table.

Note that it appears that even if 0 is returned that character might be rendered anyway because Windows uses a "fallback" font if a character is not available in the main font. However whether or not this works seems to depend on what main font is selected (for example, if it is a Unicode font or not).

The intention of this function is to let script (plugin) writers warn users if they are planning to use certain glyphs (for example, mapping symbols) which are not in the currently-selected font.

Lua functions

Topics