Add functions to extract SVG glyphs from font.
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.
This commit is contained in:
parent
2c2908f505
commit
0a1016331c
@ -702,7 +702,7 @@ struct stbtt_fontinfo
|
|||||||
|
|
||||||
int numGlyphs; // number of glyphs, needed for range checking
|
int numGlyphs; // number of glyphs, needed for range checking
|
||||||
|
|
||||||
int loca,head,glyf,hhea,hmtx,kern,gpos; // table locations as offset from start of .ttf
|
int loca,head,glyf,hhea,hmtx,kern,gpos,svg; // table locations as offset from start of .ttf
|
||||||
int index_map; // a cmap mapping for our chosen character encoding
|
int index_map; // a cmap mapping for our chosen character encoding
|
||||||
int indexToLocFormat; // format needed to map from glyph index to glyph
|
int indexToLocFormat; // format needed to map from glyph index to glyph
|
||||||
|
|
||||||
@ -829,6 +829,11 @@ STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, s
|
|||||||
STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);
|
STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);
|
||||||
// frees the data allocated above
|
// frees the data allocated above
|
||||||
|
|
||||||
|
STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg);
|
||||||
|
STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg);
|
||||||
|
// fills svg with the font's SVG data.
|
||||||
|
// returns data size or 0 if SVG not found.
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// BITMAP RENDERING
|
// BITMAP RENDERING
|
||||||
@ -1409,6 +1414,14 @@ static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, in
|
|||||||
else
|
else
|
||||||
info->numGlyphs = 0xffff;
|
info->numGlyphs = 0xffff;
|
||||||
|
|
||||||
|
t = stbtt__find_table(data, fontstart, "SVG ");
|
||||||
|
if (t) {
|
||||||
|
stbtt_uint32 offset = ttULONG(data + t + 2);
|
||||||
|
info->svg = t + offset;
|
||||||
|
} else {
|
||||||
|
info->svg = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// find a cmap encoding table we understand *now* to avoid searching
|
// find a cmap encoding table we understand *now* to avoid searching
|
||||||
// later. (todo: could make this installable)
|
// later. (todo: could make this installable)
|
||||||
// the same regardless of glyph.
|
// the same regardless of glyph.
|
||||||
@ -2602,6 +2615,44 @@ STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)
|
|||||||
STBTT_free(v, info->userdata);
|
STBTT_free(v, info->userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STBTT_DEF stbtt_uint8 *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl)
|
||||||
|
{
|
||||||
|
stbtt_uint8 *data = info->data;
|
||||||
|
stbtt_uint8 *svg_doc_list = data + info->svg;
|
||||||
|
|
||||||
|
int numEntries = ttUSHORT(svg_doc_list);
|
||||||
|
stbtt_uint8 *svg_docs = svg_doc_list + 2;
|
||||||
|
|
||||||
|
for(int i=0; i<numEntries; i++) {
|
||||||
|
stbtt_uint8 *svg_doc = svg_docs + (12 * i);
|
||||||
|
printf("%lx - %lx - %lx %lx\n", ttUSHORT(svg_doc), ttUSHORT(svg_doc + 2), ttULONG(svg_doc + 4), ttULONG(svg_doc + 8));
|
||||||
|
if((gl >= ttUSHORT(svg_doc)) && (gl <= ttUSHORT(svg_doc + 2)))
|
||||||
|
return svg_doc;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg)
|
||||||
|
{
|
||||||
|
stbtt_uint8 *data = info->data;
|
||||||
|
stbtt_uint8 *svg_doc;
|
||||||
|
|
||||||
|
if(info->svg == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if(svg_doc = stbtt_FindSVGDoc(info, gl)) {
|
||||||
|
*svg = (void *)data + info->svg + ttULONG(svg_doc + 4);
|
||||||
|
return ttULONG(svg_doc + 8);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg)
|
||||||
|
{
|
||||||
|
return stbtt_GetGlyphSVG(info, stbtt_FindGlyphIndex(info, unicode_codepoint), svg);
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// antialiasing software rasterizer
|
// antialiasing software rasterizer
|
||||||
|
Loading…
Reference in New Issue
Block a user