From patchwork Fri Sep 19 20:14:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 354 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=1758312967; bh=P4cFNFv1ln+Hze0BWys1Ym9o1XQKDxNWAYuaDZb41LQ=; 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=lu/y1/DXcQYsfCABbhoFN2AgzVVa9UQQU7SgQyphdTGeOiYkwWaCMa5lZEaMLMXw3 0rEe3soLIpgO0tRFG+Aq8y7/6hNJv0GSqbIypeTyooFgG9xzEcC/TtaIeAjCnWZj6j Nr6qD1VKETkzbg0JFfqlYmfCYbp18BPM3fwWoL97k57029UIgkKTJ9PVeHD4RMLuEe VvshHkfUj0d66bhMG+GgYbmo2qQUWodnGF+0/btq+A4ba3Viiw1yKxexuHAX2mmDip KVx+TeQYy7OTlRmMx5PCYGGRTyu/9A9BkcWJdpU+pBcq+455kq0XoaRqM5v4Kyj1Rj gKJVYcWqe6EAw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BE60067C6C for ; Fri, 19 Sep 2025 14:16:07 -0600 (MDT) 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 7FNmfR2mTY8T for ; Fri, 19 Sep 2025 14:16:07 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758312967; bh=P4cFNFv1ln+Hze0BWys1Ym9o1XQKDxNWAYuaDZb41LQ=; 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=lu/y1/DXcQYsfCABbhoFN2AgzVVa9UQQU7SgQyphdTGeOiYkwWaCMa5lZEaMLMXw3 0rEe3soLIpgO0tRFG+Aq8y7/6hNJv0GSqbIypeTyooFgG9xzEcC/TtaIeAjCnWZj6j Nr6qD1VKETkzbg0JFfqlYmfCYbp18BPM3fwWoL97k57029UIgkKTJ9PVeHD4RMLuEe VvshHkfUj0d66bhMG+GgYbmo2qQUWodnGF+0/btq+A4ba3Viiw1yKxexuHAX2mmDip KVx+TeQYy7OTlRmMx5PCYGGRTyu/9A9BkcWJdpU+pBcq+455kq0XoaRqM5v4Kyj1Rj gKJVYcWqe6EAw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A560267C0E for ; Fri, 19 Sep 2025 14:16:07 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758312965; bh=7V/1y7yN6nW20yCRXYnSwiOlI3DF837GAShHHifPyDI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wJ1XGUwwHNrq3JNLnAEBiMbA5vx68XVtPMaCVnLgHpqqpXgYyy5LkHQjove8gwfZg ykrfMCm3S0MP1JXxqCLY9yOukmTKcModTyIVn1liOPFGapsxDWCcHkM+ST+1WVIcnn pAMSr6J6pE84FdpI6RxHNbVgxA3U4PoXuUTsVTa2wnp5ejBnFdtJRkuZaR+SPK52gG oWijPWEbv9IghlnV2VZW2eI7xp+4gfXnkEyqAkhUHIrviBHbnMbi+gkEmccti5UPGa 3IS7t2+ic3fFLz5WGH/rbvm3ZnBIHe+xFdSWwHk2ra6TkGnX3WW4duAq8XKIpgVa/t /+5b05GZnP4KA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C214E67B3B; Fri, 19 Sep 2025 14:16:05 -0600 (MDT) 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 uC2xK_aj-aiq; Fri, 19 Sep 2025 14:16:05 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758312961; bh=Bczi8MQe52dULp7Zkr9NAr8d9OpYF5D0woQ+XzHQgWM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m+2l3+b66vz44yEuw9WtVpNhJ0CpRO2E8gqKSTgJEiHel0A1A9qH4JhpEeSHpEG2s AIXnlI1ctBtIDgaQSWbm+AER6L3DRjawnI8PVqkT4Cg2LSzLmFueXtEuYfJ49w13lT BqEM701F1HkcQwhubpf489v1cS+gMZWROIjgJWTczUFQJBkiTYYFrVhOxQlEYSFWt2 ogUv7OCu9rvosqKGw9Ug9JaHdhAhg3n4CrVoO3CRCikBHJLz4vnRhFSCaXWMCeO1I/ CYFeFlughbKBXHpW9UO0/VBpE1o7Gw6N4laSI2j/omtQWM079dOxwnMv4ogAo2N5ze HL1dY35StqTEg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id BFAF167C72; Fri, 19 Sep 2025 14:16:00 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 19 Sep 2025 14:14:19 -0600 Message-ID: <20250919201507.4024144-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250919201507.4024144-1-sjg@u-boot.org> References: <20250919201507.4024144-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GULJQRJRSEQYKK54NSHEZLVATL4G5DEK X-Message-ID-Hash: GULJQRJRSEQYKK54NSHEZLVATL4G5DEK 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 , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 12/42] video: Allow selection of bitmap fonts in 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 It is sometimes useful to use a bitmap font for the console even when truetype fonts are available. As a starting point, pull in the font table and provide information about font sizes. Allow selection of a bitmap font by name, as well as listing available bitmap fonts. Co-developed-by: Claude Signed-off-by: Simon Glass --- drivers/video/console_truetype.c | 64 ++++++++++++++++++++++++++++++-- test/cmd/font.c | 8 +++- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index a17519282fc..eb9e7f55d68 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -12,6 +12,7 @@ #include #include #include +#include /* Functions needed by stb_truetype.h */ static int tt_floor(double val) @@ -169,6 +170,7 @@ struct console_tt_metrics { * last character. We record enough characters to go back to the * start of the current command line. * @pos_ptr: Current position in the position history + * @cur_fontdata: Current fixed font data (NULL if using TrueType) */ struct console_tt_priv { struct console_tt_metrics *cur_met; @@ -176,6 +178,7 @@ struct console_tt_priv { int num_metrics; struct pos_info pos[POS_HISTORY_SIZE]; int pos_ptr; + struct video_fontdata *cur_fontdata; }; /** @@ -595,9 +598,19 @@ int console_truetype_get_font(struct udevice *dev, int seq, struct vidfont_info *info) { struct font_info *tab; + struct video_fontdata *fontdata; int i; - for (i = 0, tab = font_table; tab->begin; tab++, i++) { + /* List fixed fonts first */ + for (i = 0, fontdata = fonts; fontdata->name; fontdata++, i++) { + if (i == seq) { + info->name = fontdata->name; + return 0; + } + } + + /* then list TrueType fonts */ + for (tab = font_table; tab->begin; tab++, i++) { if (i == seq && font_valid(tab)) { info->name = tab->name; return 0; @@ -671,6 +684,27 @@ static struct console_tt_metrics *find_metrics(struct udevice *dev, return NULL; } +/** + * set_bitmap_font() - Set up console to use a fixed font + * + * @dev: Console device + * @fontdata: Fixed font data to use + * Return: 0 if OK, -ve on error + */ +static void set_bitmap_font(struct udevice *dev, + struct video_fontdata *fontdata) +{ + struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct console_tt_priv *priv = dev_get_priv(dev); + + priv->cur_fontdata = fontdata; + priv->cur_met = NULL; + + vidconsole_set_bitmap_font(dev, fontdata); + + vc_priv->tab_width_frac = VID_TO_POS(fontdata->width) * 8 / 2; +} + static void select_metrics(struct udevice *dev, struct console_tt_metrics *met) { struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); @@ -734,9 +768,24 @@ static int get_metrics(struct udevice *dev, const char *name, uint size, static int truetype_select_font(struct udevice *dev, const char *name, uint size) { + struct console_tt_priv *priv = dev_get_priv(dev); struct console_tt_metrics *met; + struct video_fontdata *fontdata; int ret; + /* Check if this is a request for a fixed font */ + if (name) { + for (fontdata = fonts; fontdata->name; fontdata++) { + if (!strcmp(name, fontdata->name)) { + /* Switch to fixed-font mode */ + set_bitmap_font(dev, fontdata); + return 0; + } + } + } + + /* Continue with TrueType font selection */ + priv->cur_fontdata = NULL; ret = get_metrics(dev, name, size, &met); if (ret) return log_msg_ret("sel", ret); @@ -1036,11 +1085,18 @@ static int truetype_set_cursor_visible(struct udevice *dev, bool visible, const char *console_truetype_get_font_size(struct udevice *dev, uint *sizep) { struct console_tt_priv *priv = dev_get_priv(dev); - struct console_tt_metrics *met = priv->cur_met; - *sizep = met->font_size; + if (priv->cur_fontdata) { + /* Using fixed font */ + *sizep = priv->cur_fontdata->height; + return priv->cur_fontdata->name; + } else { + /* Using TrueType font */ + struct console_tt_metrics *met = priv->cur_met; - return met->font_name; + *sizep = met->font_size; + return met->font_name; + } } static int console_truetype_probe(struct udevice *dev) diff --git a/test/cmd/font.c b/test/cmd/font.c index 7ae648d7395..b2610ddef8d 100644 --- a/test/cmd/font.c +++ b/test/cmd/font.c @@ -26,6 +26,10 @@ static int font_test_base(struct unit_test_state *uts) ut_assertok(uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)); ut_assertok(run_command("font list", 0)); + if (IS_ENABLED(CONFIG_VIDEO_FONT_8X16)) + ut_assert_nextline("8x16"); + if (IS_ENABLED(CONFIG_VIDEO_FONT_SUN12X22)) + ut_assert_nextline("12x22"); if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_NIMBUS)) ut_assert_nextline("nimbus_sans_l_regular"); if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_ANKACODER)) @@ -37,8 +41,10 @@ static int font_test_base(struct unit_test_state *uts) ut_assertok(vidconsole_get_font_size(dev, &name, &size)); if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_ANKACODER)) ut_asserteq_str("ankacoder_c75_r", name); - else + else if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_NIMBUS)) ut_asserteq_str("nimbus_sans_l_regular", name); + else + ut_asserteq_str("8x16", name); ut_asserteq(CONFIG_CONSOLE_TRUETYPE_SIZE, size); if (!IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))