foliojs / fontkit

An advanced font engine for Node and the browser
1.44k stars 210 forks source link

`vhea` and `glyf` fixes #305

Open StLyn4 opened 1 year ago

StLyn4 commented 1 year ago
  1. This branch fixes a bug with the processing of the vhea table. The version should consist of two 16-bit numbers instead of one. Because of this, errors have previously occurred in the processing of some fonts that use a vertical matrix.

  2. For TrueType fonts, the values in the loca table were not validated when calculating cbox. Therefore, the data from the glyf table was loaded even if it simply does not exist (for example, the space glyph). Added a basic check for the presence of data, and if there is none, it tries to calculate cbox using the "classic" method.

  3. If the glyph does not contain drawing commands (and, accordingly, coordinate points), then cbox / bbox contained Infinity as minX, minY, maxX, maxY values. Again, say hello to space. Therefore, a check has been added for such a case, with setting all previously named parameters to zero, as is done in FreeType (https://gitlab.freedesktop.org/freetype/freetype/-/blob/4d8db130ea4342317581bab65fc96365ce806b77/src/truetype/ttgload.c#L1648).