Skip to content
Myr

Add functions to extract SVG glyphs from font.

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

The fucntions are: stbtt_GetCodepointSVG - provides a pointer to the SVG data in the supplied argument, and returns the length of this data stbtt_GetGlyphSVG - As above but takes the glyph index instead of the codepoint Note that the returned data may be deflate compressed.

authored by Chris Young · committed by Chris Young · parent 2c2908f · 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

1 file+52 added−1 removed

modified:stb_truetype.h+52 added-1 removed
700 unmodified lines
701 int fontstart; // offset of start of font702703 int numGlyphs; // number of glyphs, needed for range checking704705 int loca,head,glyf,hhea,hmtx,kern,gpos; // table locations as offset from start of .ttf705 int loca,head,glyf,hhea,hmtx,kern,gpos,svg; // table locations as offset from start of .ttf706 int index_map; // a cmap mapping for our chosen character encoding707 int indexToLocFormat; // format needed to map from glyph index to glyph708709 stbtt__buf cff; // cff font data
118 unmodified lines
828829STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);830// frees the data allocated above831832STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg);833STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg);834// fills svg with the font's SVG data.835// returns data size or 0 if SVG not found.836837//////////////////////////////////////////////////////////////////////////////838//839// BITMAP RENDERING840//
572 unmodified lines
1413 info->numGlyphs = ttUSHORT(data+t+4);1414 else1415 info->numGlyphs = 0xffff;14161417 t = stbtt__find_table(data, fontstart, "SVG ");1418 if (t) {1419 stbtt_uint32 offset = ttULONG(data + t + 2);1420 info->svg = t + offset;1421 } else {1422 info->svg = 0;1423 }1424 1425 // find a cmap encoding table we understand *now* to avoid searching1426 // later. (todo: could make this installable)1427 // the same regardless of glyph.1428 numTables = ttUSHORT(data + cmap + 2);
1185 unmodified lines
2614{2615 STBTT_free(v, info->userdata);2616}26172618STBTT_DEF stbtt_uint8 *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl)2619{2620 stbtt_uint8 *data = info->data;2621 stbtt_uint8 *svg_doc_list = data + info->svg;2622 2623 int numEntries = ttUSHORT(svg_doc_list);2624 stbtt_uint8 *svg_docs = svg_doc_list + 2;26252626 for(int i=0; i<numEntries; i++) {2627 stbtt_uint8 *svg_doc = svg_docs + (12 * i);2628 printf("%lx - %lx - %lx %lx\n", ttUSHORT(svg_doc), ttUSHORT(svg_doc + 2), ttULONG(svg_doc + 4), ttULONG(svg_doc + 8));2629 if((gl >= ttUSHORT(svg_doc)) && (gl <= ttUSHORT(svg_doc + 2)))2630 return svg_doc;2631 }2632 return 0; 2633}26342635STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg)2636{2637 stbtt_uint8 *data = info->data;2638 stbtt_uint8 *svg_doc;2639 2640 if(info->svg == 0)2641 return 0;2642 2643 if(svg_doc = stbtt_FindSVGDoc(info, gl)) {2644 *svg = (void *)data + info->svg + ttULONG(svg_doc + 4);2645 return ttULONG(svg_doc + 8);2646 } else {2647 return 0;2648 }2649}26502651STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg)2652{2653 return stbtt_GetGlyphSVG(info, stbtt_FindGlyphIndex(info, unicode_codepoint), svg);2654}26552656//////////////////////////////////////////////////////////////////////////////2657//2658// antialiasing software rasterizer2659//
2274 unmodified lines