|
@@ -1,5 +1,5 @@
|
|
-// stb_truetype.h - v1.21 - public domain
|
|
|
|
-// authored from 2009-2016 by Sean Barrett / RAD Game Tools
|
|
|
|
|
|
+// stb_truetype.h - v1.22 - public domain
|
|
|
|
+// authored from 2009-2019 by Sean Barrett / RAD Game Tools
|
|
//
|
|
//
|
|
// This library processes TrueType files:
|
|
// This library processes TrueType files:
|
|
// parse files
|
|
// parse files
|
|
@@ -46,9 +46,11 @@
|
|
// Rob Loach Cort Stratton
|
|
// Rob Loach Cort Stratton
|
|
// Kenney Phillis Jr. github:oyvindjam
|
|
// Kenney Phillis Jr. github:oyvindjam
|
|
// Brian Costabile github:vassvik
|
|
// Brian Costabile github:vassvik
|
|
|
|
+// Ken Voskuil (kaesve) Ryan Griege
|
|
//
|
|
//
|
|
// VERSION HISTORY
|
|
// VERSION HISTORY
|
|
//
|
|
//
|
|
|
|
+// 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined
|
|
// 1.21 (2019-02-25) fix warning
|
|
// 1.21 (2019-02-25) fix warning
|
|
// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics()
|
|
// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics()
|
|
// 1.19 (2018-02-11) GPOS kerning, STBTT_fmod
|
|
// 1.19 (2018-02-11) GPOS kerning, STBTT_fmod
|
|
@@ -2540,8 +2542,7 @@ STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int g1, int
|
|
|
|
|
|
if (info->gpos)
|
|
if (info->gpos)
|
|
xAdvance += stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2);
|
|
xAdvance += stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2);
|
|
-
|
|
|
|
- if (info->kern)
|
|
|
|
|
|
+ else if (info->kern)
|
|
xAdvance += stbtt__GetGlyphKernInfoAdvance(info, g1, g2);
|
|
xAdvance += stbtt__GetGlyphKernInfoAdvance(info, g1, g2);
|
|
|
|
|
|
return xAdvance;
|
|
return xAdvance;
|
|
@@ -3968,6 +3969,7 @@ static float stbtt__oversample_shift(int oversample)
|
|
STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
|
STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
|
{
|
|
{
|
|
int i,j,k;
|
|
int i,j,k;
|
|
|
|
+ int missing_glyph_added = 0;
|
|
|
|
|
|
k=0;
|
|
k=0;
|
|
for (i=0; i < num_ranges; ++i) {
|
|
for (i=0; i < num_ranges; ++i) {
|
|
@@ -3979,7 +3981,7 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stb
|
|
int x0,y0,x1,y1;
|
|
int x0,y0,x1,y1;
|
|
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
|
|
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
|
|
int glyph = stbtt_FindGlyphIndex(info, codepoint);
|
|
int glyph = stbtt_FindGlyphIndex(info, codepoint);
|
|
- if (glyph == 0 && spc->skip_missing) {
|
|
|
|
|
|
+ if (glyph == 0 && (spc->skip_missing || missing_glyph_added)) {
|
|
rects[k].w = rects[k].h = 0;
|
|
rects[k].w = rects[k].h = 0;
|
|
} else {
|
|
} else {
|
|
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
|
|
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
|
|
@@ -3989,6 +3991,8 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stb
|
|
&x0,&y0,&x1,&y1);
|
|
&x0,&y0,&x1,&y1);
|
|
rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
|
|
rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
|
|
rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
|
|
rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
|
|
|
|
+ if (glyph == 0)
|
|
|
|
+ missing_glyph_added = 1;
|
|
}
|
|
}
|
|
++k;
|
|
++k;
|
|
}
|
|
}
|
|
@@ -4023,7 +4027,7 @@ STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info
|
|
// rects array must be big enough to accommodate all characters in the given ranges
|
|
// rects array must be big enough to accommodate all characters in the given ranges
|
|
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
|
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
|
{
|
|
{
|
|
- int i,j,k, return_value = 1;
|
|
|
|
|
|
+ int i,j,k, missing_glyph = -1, return_value = 1;
|
|
|
|
|
|
// save current values
|
|
// save current values
|
|
int old_h_over = spc->h_oversample;
|
|
int old_h_over = spc->h_oversample;
|
|
@@ -4088,6 +4092,13 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const
|
|
bc->yoff = (float) y0 * recip_v + sub_y;
|
|
bc->yoff = (float) y0 * recip_v + sub_y;
|
|
bc->xoff2 = (x0 + r->w) * recip_h + sub_x;
|
|
bc->xoff2 = (x0 + r->w) * recip_h + sub_x;
|
|
bc->yoff2 = (y0 + r->h) * recip_v + sub_y;
|
|
bc->yoff2 = (y0 + r->h) * recip_v + sub_y;
|
|
|
|
+
|
|
|
|
+ if (glyph == 0)
|
|
|
|
+ missing_glyph = j;
|
|
|
|
+ } else if (spc->skip_missing) {
|
|
|
|
+ return_value = 0;
|
|
|
|
+ } else if (r->was_packed && r->w == 0 && r->h == 0 && missing_glyph >= 0) {
|
|
|
|
+ ranges[i].chardata_for_range[j] = ranges[i].chardata_for_range[missing_glyph];
|
|
} else {
|
|
} else {
|
|
return_value = 0; // if any fail, report failure
|
|
return_value = 0; // if any fail, report failure
|
|
}
|
|
}
|
|
@@ -4389,12 +4400,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|
int w,h;
|
|
int w,h;
|
|
unsigned char *data;
|
|
unsigned char *data;
|
|
|
|
|
|
- // if one scale is 0, use same scale for both
|
|
|
|
- if (scale_x == 0) scale_x = scale_y;
|
|
|
|
- if (scale_y == 0) {
|
|
|
|
- if (scale_x == 0) return NULL; // if both scales are 0, return NULL
|
|
|
|
- scale_y = scale_x;
|
|
|
|
- }
|
|
|
|
|
|
+ if (scale == 0) return NULL;
|
|
|
|
|
|
stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale, scale, 0.0f,0.0f, &ix0,&iy0,&ix1,&iy1);
|
|
stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale, scale, 0.0f,0.0f, &ix0,&iy0,&ix1,&iy1);
|
|
|
|
|