From patchwork Sat Jan 3 01:18: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: 1200 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=1767403191; bh=47Vxzn5nGF2iaLL7Efj179QQdBDhqinirAF6NMv01Ok=; 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=eC8uG4tWyGgKnfSF3YwLgWZAPlfAhutcqDMoMYqvAqj1nvCobbmH9Fey9SUNaiLl2 wjc3qV4/HEE6wxqcqPGG+I5381ixVvorgAg8XXO8rgJcr13FNGYsqw7vT4Rfk3Xrin Q1ynpoY6+PZVTefgGBb5+NSA7pf9qPd3TACRbTpBJAr6I77wtjWh9k3Cip+Avnw7Ju 19+tasBWVIN/gWHAd+yS6pAY0H8whZQBWRNZ23FDXWjMMmAiv31utjFewGSeqbs4fD i1Ox++P78HGB3AyWkUV3cRULTNOOBapzYj+n7WOSzrFkcaZqOy2T9AHpJvMEQlAGjY 1EYfWSktr0zYA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AC9906904E for ; Fri, 2 Jan 2026 18:19:51 -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 5YwdhceZNKnE for ; Fri, 2 Jan 2026 18:19:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403191; bh=47Vxzn5nGF2iaLL7Efj179QQdBDhqinirAF6NMv01Ok=; 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=eC8uG4tWyGgKnfSF3YwLgWZAPlfAhutcqDMoMYqvAqj1nvCobbmH9Fey9SUNaiLl2 wjc3qV4/HEE6wxqcqPGG+I5381ixVvorgAg8XXO8rgJcr13FNGYsqw7vT4Rfk3Xrin Q1ynpoY6+PZVTefgGBb5+NSA7pf9qPd3TACRbTpBJAr6I77wtjWh9k3Cip+Avnw7Ju 19+tasBWVIN/gWHAd+yS6pAY0H8whZQBWRNZ23FDXWjMMmAiv31utjFewGSeqbs4fD i1Ox++P78HGB3AyWkUV3cRULTNOOBapzYj+n7WOSzrFkcaZqOy2T9AHpJvMEQlAGjY 1EYfWSktr0zYA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9C93469034 for ; Fri, 2 Jan 2026 18:19:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403189; bh=g4JCYmYE35oX1JCOCwpQbngi+wOGdvlz/Fz8jxeXNwk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=muAVyac7Lx8cwNa830uQbGjUunRpwj9EYK5Y7pOo2fMNMBkaPwPcgPbg5y8tYhOW6 LKgs9mBErNecfPBrq41emsHVSYzXBQ7EMa8c3c9gLnhfDsF5taVPxthw7M6rL7vc6j P8YsiJSAbZuF4hdz8dCsdA1F+4Vx8JQDF7R2c7oLtbeYhZA+/BV50Q+7VVvNMEGnWr 6K4j/k7LZ0b53EmnbTJPtC1lvZTwjIxRfsJ89dGL+p4qHrJU1A/MtdNBq/iz1qn/dV nAYR5A3sYC8QIsbh/Gxq8pMLrtONouafer7COBOFrUuBJW9khjG1TWJbYHPEzujZC9 o163mE2nIruHQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A2F6269034; Fri, 2 Jan 2026 18:19:49 -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 FoTCltm8o0jN; Fri, 2 Jan 2026 18:19:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403184; bh=HDnzoQKiICQcAxY52zrH2faf4HiP4Cm+ImWp+D3ue7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j9XMWWcnjpQ1kmdRSLYTlsqhxbZ+evWVFrcWu4O7B9l+jFyuklikOTgWztbABYmpQ HsMhUDOkyPKXyVZwveeA0N0A/Ska7bEzSTRgxiKt1oDwZBajZLhQB+9U/doTSxpRwn T22cF3b9eB+j5AMevs3qtpGtuDpT8mWjDnfCTyJ2QCtdB/hhQ0s/FUufbYKxyYO0kO 3I9dBetWq+3XOiH7NvwbFkjS472B/Hipm9NJaieXuaPVvTVrbFe5KazxdFQEstgd4x +k2CnsjMdxZFwXrwEl5vgZLlNuLJFGdipKk3t2qsM3S+wTTG6hBU2Fi+hzdvtPkXI0 miihF9s3kBKBw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9EE9E68F5F; Fri, 2 Jan 2026 18:19:44 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:42 -0700 Message-ID: <20260103011908.149445-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: IQHZ6BGQE5VKK2ZQVIUTY2V22SEM2HN3 X-Message-ID-Hash: IQHZ6BGQE5VKK2ZQVIUTY2V22SEM2HN3 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 06/24] 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 --- 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