Hello, a few corrections and annotations (the code, BTW, is taken from the already mentioned wiki http://luatex.bluwiki.com/go/Use_a_TrueType_font).
mag = size / ttffont.units_per_em
This should be "local mag = size / ttffont.units_per_em".
f.characters[char] = { index = glyph, width = glyph_table.width * mag, name = glyph_table.name, }
This does not set the height and depth of the character correctly, which I found results in spacing errors before and after large display maths. In my code, I have added: if glyph_table.boundingbox[4] then f.characters[char].height = glyph_table.boundingbox[4] * mag end if glyph_table.boundingbox[2] then f.characters[char].depth = -glyph_table.boundingbox[2] * mag end
if glyph_table.kerns then local kerns = { } for _, kern in pairs(glyph_table.kerns) do kerns[names_of_char[kern.char]] = kern.off * mag end f.characters[char].kerns = kerns end end f.filename = filename f.type = 'real' f.format = fonttype f.embedding = "subset" f.cidinfo = { registry = "Adobe", ordering = "Identity", supplement = 0, version = 1 } end else f = font.read_tfm(name, size) end return f end ) }
Also note that the loaded font will not have any ligatures. Jonathan