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
Provenance
- Commit
fe6bef2- Tree
89697cf- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent
ade80f4
1 file changed+25 added−15 removed
modified:stb_truetype.h+25 added-15 removed
831 unmodified lines832 // frees the data allocated above833 834 STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg);835 STBTT_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.838 839 //////////////////////////////////////////////////////////////////////////////840 //495 unmodified lines1336 stbtt__buf_seek(&cff, private_loc[1]+subrsoff);1337 return stbtt__cff_get_index(&cff);1338 }1339 1340+// since most people won't use this, find this table the first time it's needed1341+static 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+ 1356 static 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 lines1431 info->numGlyphs = ttUSHORT(data+t+4);1432 else1433 info->numGlyphs = 0xffff;1434 1419- 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;1436+1437 // 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 lines2627 }2628 2629 STBTT_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;2637 2627- 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 lines2651 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