Merge branch 'svg' of https://github.com/chris-y/stb into work2
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 · parents d487122, 0a10163 · Browse files · 1 file·+52 added−1 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+52 added−1 removed
- other:+52 added−1 removed
Provenance
- Commit
ade80f4- Tree
155df43- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent 1
d487122- Parent 2
0a10163
1 file changed+52 added−1 removed
modified:stb_truetype.h+52 added-1 removed
702 unmodified lines703 int fontstart; // offset of start of font704 705 int numGlyphs; // number of glyphs, needed for range checking706 707- int loca,head,glyf,hhea,hmtx,kern,gpos; // table locations as offset from start of .ttf707+ int loca,head,glyf,hhea,hmtx,kern,gpos,svg; // table locations as offset from start of .ttf708 int index_map; // a cmap mapping for our chosen character encoding709 int indexToLocFormat; // format needed to map from glyph index to glyph710 711 stbtt__buf cff; // cff font data118 unmodified lines830 831 STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);832 // 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.837+// returns data size or 0 if SVG not found.838+839 //////////////////////////////////////////////////////////////////////////////840 //841 // BITMAP RENDERING842 //572 unmodified lines1415 info->numGlyphs = ttUSHORT(data+t+4);1416 else1417 info->numGlyphs = 0xffff;1418 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+ 1427 // find a cmap encoding table we understand *now* to avoid searching1428 // later. (todo: could make this installable)1429 // the same regardless of glyph.1430 numTables = ttUSHORT(data + cmap + 2);1184 unmodified lines2615 {2616 STBTT_free(v, info->userdata);2617 }2618 2619+STBTT_DEF stbtt_uint8 *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl)2620+{2621+ stbtt_uint8 *data = info->data;2622+ stbtt_uint8 *svg_doc_list = data + info->svg;2623+ 2624+ int numEntries = ttUSHORT(svg_doc_list);2625+ stbtt_uint8 *svg_docs = svg_doc_list + 2;2626+2627+ for(int i=0; i<numEntries; i++) {2628+ 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;2632+ }2633+ return 0; 2634+}2635+2636+STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg)2637+{2638+ stbtt_uint8 *data = info->data;2639+ stbtt_uint8 *svg_doc;2640+ 2641+ if(info->svg == 0)2642+ return 0;2643+ 2644+ if(svg_doc = stbtt_FindSVGDoc(info, gl)) {2645+ *svg = (void *)data + info->svg + ttULONG(svg_doc + 4);2646+ return ttULONG(svg_doc + 8);2647+ } else {2648+ return 0;2649+ }2650+}2651+2652+STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg)2653+{2654+ return stbtt_GetGlyphSVG(info, stbtt_FindGlyphIndex(info, unicode_codepoint), svg);2655+}2656+2657 //////////////////////////////////////////////////////////////////////////////2658 //2659 // antialiasing software rasterizer2660 //2279 unmodified lines