~ft/libpt

15dee22cc1e7ee120118e0a7f775c60d62fa00c7 — Sigrid Haflínudóttir 3 months ago 99dc653
fall back to stbtt_FindGlyphIndex when c2g mapping isn't available
2 files changed, 6 insertions(+), 3 deletions(-)

M pt.c
M stb_truetype.h
M pt.c => pt.c +2 -0
@@ 158,6 158,8 @@ code2glyph(Sfont *f, u32int c)
{
	u32int *r;

	if(f->c2g == nil)
		return stbtt_FindGlyphIndex(&f->fi, c);
	if((r = bsearch(c, f->c2g->code, f->c2g->num)) != nil)
		return f->c2g->glyph[r - f->c2g->code];
	return 0;

M stb_truetype.h => stb_truetype.h +4 -3
@@ 1544,13 1544,16 @@ STBTT_DEF stbtt_code2glyph *stbtt_Code2Glyph(const stbtt_fontinfo *info) {
   stbtt_uint32 index_map = info->index_map;
   stbtt_code2glyph *c2g;
   int i;
   stbtt_uint16 format = ttUSHORT(data + index_map + 0);

   if(format == 4) // FIXME
      return NULL;

   c2g = mallocz(sizeof(*c2g) + info->numGlyphs*6, 1);
   c2g->code = (u32int*)(c2g + 1);
   c2g->glyph = (u16int*)(c2g->code + info->numGlyphs);
   c2g->num = info->numGlyphs;

   stbtt_uint16 format = ttUSHORT(data + index_map + 0);
   if (format == 0) { // apple byte encoding
      stbtt_int32 bytes = ttUSHORT(data + index_map + 2);
      for(i = 0; i < bytes-6; i++){


@@ 1566,8 1569,6 @@ STBTT_DEF stbtt_code2glyph *stbtt_Code2Glyph(const stbtt_fontinfo *info) {
      }
   } else if (format == 2) {
      STBTT_assert(format == 2 && 0); // @TODO: high-byte mapping for japanese/chinese/korean
   } else if (format == 4) { // standard mapping for windows fonts: binary search collection of ranges
      STBTT_assert(format == 4 && 0); // FIXME
   } else if (format == 12 || format == 13) {
      stbtt_uint32 ngroups = ttULONG(data+index_map+12);
      stbtt_uint32 g, ch;