From patchwork Sat Jan 3 20:04:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470779; bh=dwf45oPZKU68V2KLL7anriO0EwFFOtMxTwy+qKyqb4s=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=wNFsRoNi0D5jBKd1ivOxPpYHfJAJcSUezAFkdwpvGl2qNwZblFlQhTT0O7malHjH7 9kdjBtZFDq3nY7AU/PTwCZ0pknVM6L+DkoOfWtn5qBRwjVijk34GDIAPgFAbvcUt/7 IfgTJ7NGtDxFJ62KZm8FV0rDucjZneFnNIPSQZYqysE8wUN9k//Pp3uLBCjiTMPqQj 9YStaYpc2QrJluRlkvfEzAtA2Q9a5B5o2u+AZqwJwr0ipL0QzoUYtnDcZMjd7U/aRd TL94xE7OpSBvQwGEz+v4ziT0ANE233tQhslY0S834bKO0Z1vW9RLH2KUn98M3nFSpn aw1lMfhv9xraw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C82E569097 for ; Sat, 3 Jan 2026 13:06:19 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id DdUKeh3YHCJb for ; Sat, 3 Jan 2026 13:06:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470779; bh=dwf45oPZKU68V2KLL7anriO0EwFFOtMxTwy+qKyqb4s=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=wNFsRoNi0D5jBKd1ivOxPpYHfJAJcSUezAFkdwpvGl2qNwZblFlQhTT0O7malHjH7 9kdjBtZFDq3nY7AU/PTwCZ0pknVM6L+DkoOfWtn5qBRwjVijk34GDIAPgFAbvcUt/7 IfgTJ7NGtDxFJ62KZm8FV0rDucjZneFnNIPSQZYqysE8wUN9k//Pp3uLBCjiTMPqQj 9YStaYpc2QrJluRlkvfEzAtA2Q9a5B5o2u+AZqwJwr0ipL0QzoUYtnDcZMjd7U/aRd TL94xE7OpSBvQwGEz+v4ziT0ANE233tQhslY0S834bKO0Z1vW9RLH2KUn98M3nFSpn aw1lMfhv9xraw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B760B6907B for ; Sat, 3 Jan 2026 13:06:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470777; bh=U0zby2pq4s1fYrTiId2TEOB31JJuz5835RbMvu6xSyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N2pSeSmwQt2P6ydnHuMs4RTFwXFCSZBkOFe0ycCgU8Hq5FQcDQI5kIVb2fA5m/43P Z6QO8NETQbCe34GUChzJcv+ui+cLyU0mUQNrCYy86G1I2WQv8bWOdg//tmWTcvtnHK lFiSRdFoHUWvsaYodboCVL+I4SjGNELYHXx8dSKHczzazWIbzDQkCZXkFUiQBP6tMU EuA0YrJ3ANNJeGSfmadSvllzaBg9LoTAbg9oKQMhsHHsbIpFUR7r5UMrBWdRMPgOd+ u1cnIc50kVFnzkK88z4GYJxsWtCMCEuHC7Bbjknu0S/NfDgWcn0a8jVUiIJjYESlNt rvOIS2ZtEQGnQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6EB2C68FCC; Sat, 3 Jan 2026 13:06:17 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id RqJoCADAmcUr; Sat, 3 Jan 2026 13:06:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470773; bh=+TkRlzW9Tzcv5ffXbM7Njij1kUD9ai2Sxl8EZmpUWeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FzDNdaDpDTpMkHdcubombNOzS7bYe94AchLTfkyTUSliq1wppNGMTAT9X2UiUuLQT YCI4wK3oO4dZeWG4+e29bFNGsEn1rmLGAddVq6ftct7Gw9YxgXCfShbj4IYnSHi5RO QCG5cg3xl6xVxG8sAsu3KsfCKHxSU4de6OVKFV805flDrJlWcmDGG1l2g8hENJ1daK SEb2MjQWhyMX0bSF8hLMDxs+sQsKFOSG51TJRKpccpNPiDRX4kUN1QalElLnt9JeBd rRv2ZQRQybyUB7lMXG4H94NWdVB15Khk6fng7VS2eYxVKGX0g1t83iI4B5sUNpGLjs aO7ocgCWy3BJQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 1C9C468FD2; Sat, 3 Jan 2026 13:06:13 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:42 -0700 Message-ID: <20260103200510.3605009-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: X64IALXXOEOTFH6SO6MXPP2EFCPDXUTG X-Message-ID-Hash: X64IALXXOEOTFH6SO6MXPP2EFCPDXUTG X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 11/29] video: Update stb_truetype List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass This was last updated in 2023. The updates are minimal but we may as well keep it up to date. Bring in the latest version: f1c79c0 ("Merge pull request #1851 from jeffrbig2/master"_ Signed-off-by: Simon Glass --- (no changes since v1) drivers/video/stb_truetype.h | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/video/stb_truetype.h b/drivers/video/stb_truetype.h index 32a7b6e1dc0..90a5c2e2b3f 100644 --- a/drivers/video/stb_truetype.h +++ b/drivers/video/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 // @@ -412,6 +412,7 @@ int main(int arg, char **argv) } #endif + ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// //// @@ -482,7 +483,7 @@ int main(int arg, char **argv) #endif #ifndef STBTT_memcpy - #include + #include #define STBTT_memcpy memcpy #define STBTT_memset memset #endif @@ -563,6 +564,7 @@ STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int p STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap); // Query the font vertical metrics without having to create a font first. + ////////////////////////////////////////////////////////////////////////////// // // NEW TEXTURE BAKING API @@ -735,6 +737,7 @@ STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, in // need to do anything special to free it, because the contents are pure // value data with no additional data structures. Returns 0 on failure. + ////////////////////////////////////////////////////////////////////////////// // // CHARACTER TO GLYPH-INDEX CONVERSIOn @@ -746,6 +749,7 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep // codepoint-based functions. // Returns 0 if the character codepoint is not defined in the font. + ////////////////////////////////////////////////////////////////////////////// // // CHARACTER PROPERTIES @@ -915,6 +919,7 @@ STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1); STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1); + // @TODO: don't expose this structure typedef struct { @@ -989,6 +994,8 @@ STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, floa // The algorithm has not been optimized at all, so expect it to be slow // if computing lots of characters or very large sizes. + + ////////////////////////////////////////////////////////////////////////////// // // Finding the right font... @@ -1010,6 +1017,7 @@ STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, floa // from the file yourself and do your own comparisons on them. // You have to have called stbtt_InitFont() first. + STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags); // returns the offset (not index) of the font that matches, or -1 if none // if you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold". @@ -2801,6 +2809,7 @@ typedef struct stbtt__edge { int invert; } stbtt__edge; + typedef struct stbtt__active_edge { struct stbtt__active_edge *next; @@ -4595,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; @@ -4607,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 @@ -4680,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 { @@ -4961,6 +4972,7 @@ STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const #endif // STB_TRUETYPE_IMPLEMENTATION + // FULL VERSION HISTORY // // 1.25 (2021-07-11) many fixes