summaryrefslogtreecommitdiff
path: root/lib/stb_truetype.h
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-09-28 01:05:07 -0400
committerpommicket <pommicket@gmail.com>2025-09-28 01:05:07 -0400
commit5c0c8ac1d84b93c413604229396d6d3ff590804e (patch)
tree985a1016498aa0440dc1663e3f51ac7c460d2789 /lib/stb_truetype.h
parent80585f276ee666c9967312671bef081abedf53c3 (diff)
Update to latest stb_truetypeHEAD2.8.4trunk
Diffstat (limited to 'lib/stb_truetype.h')
-rw-r--r--lib/stb_truetype.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/stb_truetype.h b/lib/stb_truetype.h
index bbf2284..90a5c2e 100644
--- a/lib/stb_truetype.h
+++ b/lib/stb_truetype.h
@@ -54,7 +54,7 @@
// Hou Qiming Derek Vinyard
// Rob Loach Cort Stratton
// Kenney Phillis Jr. Brian Costabile
-// Ken Voskuil (kaesve)
+// Ken Voskuil (kaesve) Yakov Galka
//
// VERSION HISTORY
//
@@ -4604,6 +4604,8 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
scale_y = -scale_y;
{
+ // distance from singular values (in the same units as the pixel grid)
+ const float eps = 1./1024, eps2 = eps*eps;
int x,y,i,j;
float *precompute;
stbtt_vertex *verts;
@@ -4616,15 +4618,15 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
float x0 = verts[i].x*scale_x, y0 = verts[i].y*scale_y;
float x1 = verts[j].x*scale_x, y1 = verts[j].y*scale_y;
float dist = (float) STBTT_sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
- precompute[i] = (dist == 0) ? 0.0f : 1.0f / dist;
+ precompute[i] = (dist < eps) ? 0.0f : 1.0f / dist;
} else if (verts[i].type == STBTT_vcurve) {
float x2 = verts[j].x *scale_x, y2 = verts[j].y *scale_y;
float x1 = verts[i].cx*scale_x, y1 = verts[i].cy*scale_y;
float x0 = verts[i].x *scale_x, y0 = verts[i].y *scale_y;
float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2;
float len2 = bx*bx + by*by;
- if (len2 != 0.0f)
- precompute[i] = 1.0f / (bx*bx + by*by);
+ if (len2 >= eps2)
+ precompute[i] = 1.0f / len2;
else
precompute[i] = 0.0f;
} else
@@ -4689,8 +4691,8 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
float a = 3*(ax*bx + ay*by);
float b = 2*(ax*ax + ay*ay) + (mx*bx+my*by);
float c = mx*ax+my*ay;
- if (a == 0.0) { // if a is 0, it's linear
- if (b != 0.0) {
+ if (STBTT_fabs(a) < eps2) { // if a is 0, it's linear
+ if (STBTT_fabs(b) >= eps2) {
res[num++] = -c/b;
}
} else {