stb_truetype: runtime selection of skipping missing codepoints
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 eaf78c1 · Browse files · 1 file·+15 added−3 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+15 added−3 removed
- other:+15 added−3 removed
Provenance
- Commit
c35d1dd- Tree
cab72b6- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent
eaf78c1
1 file changed+15 added−3 removed
modified:stb_truetype.h+15 added-3 removed
641 unmodified lines642 //643 // To use with PackFontRangesGather etc., you must set it before calls644 // call to PackFontRangesGatherRects.645 646+// If skip != 0, this tells stb_truetype to skip any codepoints for which647+// there is no corresponding glyph. If skip=0, which is the default, then648+// codepoints without a glyph recived the font's "missing character" glyph,649+// typically an empty box by convention.650+STBTT_DEF void stbtt_PackSetSkipMissingGlyphs(stbtt_pack_context *spc, int skip);651+652 STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, // same data as above653 int char_index, // character to display654 float *xpos, float *ypos, // pointers to current position in screen pixel space655 stbtt_aligned_quad *q, // output: quad to draw20 unmodified lines676 int width;677 int height;678 int stride_in_bytes;679 int padding;680+ int skip_empty;681 unsigned int h_oversample, v_oversample;682 unsigned char *pixels;683 void *nodes;684 };3145 unmodified lines3830 if (v_oversample <= STBTT_MAX_OVERSAMPLE)3831 spc->v_oversample = v_oversample;3832 }3833 3834+STBTT_DEF void stbtt_PackSetSkipMissingGlyphs(stbtt_pack_context *spc, int skip)3835+{3836+ spc->skip_empty = skip;3837+}3838+3839 #define STBTT__OVER_MASK (STBTT_MAX_OVERSAMPLE-1)3840 3841 static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width)3842 {145 unmodified lines3988 for (j=0; j < ranges[i].num_chars; ++j) {3989 int x0,y0,x1,y1;3990 int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];3991 int glyph = stbtt_FindGlyphIndex(info, codepoint);3980- if (glyph != 0) {3992+ if (glyph == 0 && spc->skip_empty) {3993+ rects[k].w = rects[k].h = 0;3994+ } else {3995 stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,3996 scale * spc->h_oversample,3997 scale * spc->v_oversample,3998 0,0,3999 &x0,&y0,&x1,&y1);4000 rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);4001 rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);3988- } else {3989- rects[k].w = rects[k].h = 0;4002 }4003 ++k;4004 }4005 }887 unmodified lines