Skip to contentSkip to conversation

Add grub_font_get_no_fallback

PATCH New Vladimir Serbinenko 1 participant 3 messages May 16, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Add grub_font_get_no_fallback

This allows the caller to handle the fallback

---
 grub-core/font/font.c | 21 ++++++++++++++++-----
 include/grub/font.h   |  2 ++
 2 files changed, 18 insertions(+), 5 deletions(-)
grub-core/font/font.c +16 -5
index 18de52562..ea01db01b 100644
@@ -904,12 +904,8 @@ remove_font (grub_font_t font)
     }
 }
 
-/* Get a font from the list of loaded fonts.  This function will return
-   another font if the requested font is not available.  If no fonts are
-   loaded, then a special 'null font' is returned, which contains no glyphs,
-   but is not a null pointer so the caller may omit checks for NULL.  */
 grub_font_t
-grub_font_get (const char *font_name)
+grub_font_get_no_fallback (const char *font_name)
 {
   struct grub_font_node *node;
 
@@ -920,6 +916,21 @@ grub_font_get (const char *font_name)
 	return font;
     }
 
+  return NULL;
+}
+
+/* Get a font from the list of loaded fonts.  This function will return
+   another font if the requested font is not available.  If no fonts are
+   loaded, then a special 'null font' is returned, which contains no glyphs,
+   but is not a null pointer so the caller may omit checks for NULL.  */
+grub_font_t
+grub_font_get (const char *font_name)
+{
+  grub_font_t font = grub_font_get_no_fallback (font_name);
+
+  if (font)
+    return font;
+
   /* If no font by that name is found, return the first font in the list
      as a fallback.  */
   if (grub_font_list && grub_font_list->value)
include/grub/font.h +2 -0
index 708fa42ac..e6a43f8fc 100644
@@ -107,6 +107,8 @@ grub_font_t EXPORT_FUNC(grub_font_load) (const char *filename);
    is returned as a fallback.  */
 grub_font_t EXPORT_FUNC (grub_font_get) (const char *font_name);
 
+grub_font_t EXPORT_FUNC(grub_font_get_no_fallback) (const char *font_name);
+					
 const char *EXPORT_FUNC (grub_font_get_name) (grub_font_t font);
 
 int EXPORT_FUNC (grub_font_get_max_char_width) (grub_font_t font);
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

PATCH 2/3 gfxmenu: Add missing error handling

We don't currently handle errors from gfxterm

---
 grub-core/gfxmenu/view.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
grub-core/gfxmenu/view.c +4 -1
index e02eba8b0..19d3f2f14 100644
@@ -539,7 +539,7 @@ init_terminal (grub_gfxmenu_view_t view)
   /* Note: currently there is no API for changing the gfxterm font
      on the fly, so whatever font the initially loaded theme specifies
      will be permanent.  */
-  grub_gfxterm_set_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY,
+  grub_err_t err = grub_gfxterm_set_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY,
                            view->terminal_rect.x,
                            view->terminal_rect.y,
                            view->terminal_rect.width,
@@ -547,6 +547,9 @@ init_terminal (grub_gfxmenu_view_t view)
                            view->double_repaint,
                            terminal_font,
                            view->terminal_border);
+  if (err)
+    return;
+
   grub_gfxterm_decorator_hook = grub_gfxmenu_draw_terminal_box;
 }
 
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#2 lore raw

PATCH 3/3 Improve font fallback scanning and validation for gfxterm

In reply to Vladimir Serbinenko

Choosing a font which is too large breaks gfxterm. Be more diligent in font choice. This being said it's better to specify the correct font explicitly in config when several fonts are loaded.

---
 grub-core/gfxmenu/view.c |  7 +----
 grub-core/term/gfxterm.c | 56 ++++++++++++++++++++++++++++++++--------
 2 files changed, 46 insertions(+), 17 deletions(-)
grub-core/gfxmenu/view.c +1 -6
index 19d3f2f14..d96b5cdc9 100644
@@ -524,12 +524,7 @@ init_terminal (grub_gfxmenu_view_t view)
 {
   grub_font_t terminal_font;
 
-  terminal_font = grub_font_get (view->terminal_font_name);
-  if (!terminal_font)
-    {
-      grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
-      return;
-    }
+  terminal_font = grub_font_get_no_fallback (view->terminal_font_name);
 
   /* Check that terminal window size and position are sane. */
   terminal_sanity_check (view);
grub-core/term/gfxterm.c +45 -11

90 lines not on this page · raw message

Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel