Search code examples
truetypetypography

How to render zero-width glyphs in ttf?


I'm working on a TrueType font parsing/rendering engine in Javascript. Source can be found here.

My problem is that the space glyph is almost always indexed in the loca table as zero-width, which means that when I look up the glyph in the loca offsets, I get the offset for the exclam glyph. The spec for the loca table says:

If the font does not contain an outline for the missing character, then the first and second offsets should have the same value. This also applies to any other character without an outline, such as the space character. If a glyph has no outline, its length should be zero.

So, it looks like the space character has no outline, but I don't want to draw the .notdef glyph. How do I decide what to draw (or at least offset horizontally) if there's no glyph outline set?


Solution

  • This width of a character is set in the hmtx table, and a glyph must be rendered in that width, regardless of whether or not there is an outline defined for it.