Skip to content
Myr

stb_truetype: clean up svg support

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parent ade80f4 · Browse files · 1 file+25 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+25 added−15 removed

  • other:+25 added−15 removed

1 file+25 added−15 removed

modified:stb_truetype.h+25 added-15 removed
831 unmodified lines
832// frees the data allocated above833834STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg);835STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg);836// fills svg with the font's SVG data.836// fills svg with the character's SVG data.837// returns data size or 0 if SVG not found.838839//////////////////////////////////////////////////////////////////////////////840//
495 unmodified lines
1336 stbtt__buf_seek(&cff, private_loc[1]+subrsoff);1337 return stbtt__cff_get_index(&cff);1338}13391340// since most people won't use this, find this table the first time it's needed1341static int stbtt__get_svg(stbtt_fontinfo *info)1342{1343 stbtt_uint32 t;1344 if (info->svg < 0) {1345 t = stbtt__find_table(info->data, info->fontstart, "SVG ");1346 if (t) {1347 stbtt_uint32 offset = ttULONG(info->data + t + 2);1348 info->svg = t + offset;1349 } else {1350 info->svg = 0;1351 }1352 }1353 return info->svg;1354}1355 1356static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, int fontstart)1357{1358 stbtt_uint32 cmap, t;1359 stbtt_int32 i,numTables;
71 unmodified lines
1431 info->numGlyphs = ttUSHORT(data+t+4);1432 else1433 info->numGlyphs = 0xffff;14341419 t = stbtt__find_table(data, fontstart, "SVG ");1420 if (t) {1421 stbtt_uint32 offset = ttULONG(data + t + 2);1422 info->svg = t + offset;1423 } else {1424 info->svg = 0;1425 }1426 1435 info->svg = -1;14361437 // find a cmap encoding table we understand *now* to avoid searching1438 // later. (todo: could make this installable)1439 // the same regardless of glyph.1440 numTables = ttUSHORT(data + cmap + 2);
1186 unmodified lines
2627}26282629STBTT_DEF stbtt_uint8 *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl)2630{2631 int i;2632 stbtt_uint8 *data = info->data;2622 stbtt_uint8 *svg_doc_list = data + info->svg;2633 stbtt_uint8 *svg_doc_list = data + stbtt__get_svg((stbtt_fontinfo *) info);2634 2635 int numEntries = ttUSHORT(svg_doc_list);2636 stbtt_uint8 *svg_docs = svg_doc_list + 2;26372627 for(int i=0; i<numEntries; i++) {2638 for(i=0; i<numEntries; i++) {2639 stbtt_uint8 *svg_doc = svg_docs + (12 * i);2629 printf("%lx - %lx - %lx %lx\n", ttUSHORT(svg_doc), ttUSHORT(svg_doc + 2), ttULONG(svg_doc + 4), ttULONG(svg_doc + 8));2630 if((gl >= ttUSHORT(svg_doc)) && (gl <= ttUSHORT(svg_doc + 2)))2631 return svg_doc;2640 if ((gl >= ttUSHORT(svg_doc)) && (gl <= ttUSHORT(svg_doc + 2)))2641 return svg_doc;2642 }2643 return 0; 2644}2645
5 unmodified lines
2651 if(info->svg == 0)2652 return 0;2653 2654 if(svg_doc = stbtt_FindSVGDoc(info, gl)) {2645 *svg = (void *)data + info->svg + ttULONG(svg_doc + 4);2655 *svg = (char *)data + info->svg + ttULONG(svg_doc + 4);2656 return ttULONG(svg_doc + 8);2657 } else {2658 return 0;2659 }
2290 unmodified lines