|
|
fd0330 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
fd0330 |
From: Chris Coulson <chris.coulson@canonical.com>
|
|
|
fd0330 |
Date: Wed, 16 Nov 2022 14:40:04 +0000
|
|
|
fd0330 |
Subject: [PATCH] font: Try opening fonts from the bundled memdisk
|
|
|
fd0330 |
|
|
|
fd0330 |
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
|
|
|
fd0330 |
---
|
|
|
fd0330 |
grub-core/font/font.c | 48 +++++++++++++++++++++++++++++++-----------------
|
|
|
fd0330 |
1 file changed, 31 insertions(+), 17 deletions(-)
|
|
|
fd0330 |
|
|
|
fd0330 |
diff --git a/grub-core/font/font.c b/grub-core/font/font.c
|
|
|
fd0330 |
index e6616e610c..e421d1ae6f 100644
|
|
|
fd0330 |
--- a/grub-core/font/font.c
|
|
|
fd0330 |
+++ b/grub-core/font/font.c
|
|
|
fd0330 |
@@ -409,6 +409,27 @@ read_section_as_short (struct font_file_section *section,
|
|
|
fd0330 |
return 0;
|
|
|
fd0330 |
}
|
|
|
fd0330 |
|
|
|
fd0330 |
+static grub_file_t
|
|
|
fd0330 |
+try_open_from_prefix (const char *prefix, const char *filename)
|
|
|
fd0330 |
+{
|
|
|
fd0330 |
+ grub_file_t file;
|
|
|
fd0330 |
+ char *fullname, *ptr;
|
|
|
fd0330 |
+
|
|
|
fd0330 |
+ fullname = grub_malloc (grub_strlen (prefix) + grub_strlen (filename) + 1
|
|
|
fd0330 |
+ + sizeof ("/fonts/") + sizeof (".pf2"));
|
|
|
fd0330 |
+ if (!fullname)
|
|
|
fd0330 |
+ return 0;
|
|
|
fd0330 |
+ ptr = grub_stpcpy (fullname, prefix);
|
|
|
fd0330 |
+ ptr = grub_stpcpy (ptr, "/fonts/");
|
|
|
fd0330 |
+ ptr = grub_stpcpy (ptr, filename);
|
|
|
fd0330 |
+ ptr = grub_stpcpy (ptr, ".pf2");
|
|
|
fd0330 |
+ *ptr = 0;
|
|
|
fd0330 |
+
|
|
|
fd0330 |
+ file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024);
|
|
|
fd0330 |
+ grub_free (fullname);
|
|
|
fd0330 |
+ return file;
|
|
|
fd0330 |
+}
|
|
|
fd0330 |
+
|
|
|
fd0330 |
/* Load a font and add it to the beginning of the global font list.
|
|
|
fd0330 |
Returns 0 upon success, nonzero upon failure. */
|
|
|
fd0330 |
grub_font_t
|
|
|
fd0330 |
@@ -427,25 +448,18 @@ grub_font_load (const char *filename)
|
|
|
fd0330 |
file = grub_buffile_open (filename, GRUB_FILE_TYPE_FONT, 1024);
|
|
|
fd0330 |
else
|
|
|
fd0330 |
{
|
|
|
fd0330 |
- const char *prefix = grub_env_get ("prefix");
|
|
|
fd0330 |
- char *fullname, *ptr;
|
|
|
fd0330 |
- if (!prefix)
|
|
|
fd0330 |
+ file = try_open_from_prefix ("(memdisk)", filename);
|
|
|
fd0330 |
+ if (!file)
|
|
|
fd0330 |
{
|
|
|
fd0330 |
- grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"),
|
|
|
fd0330 |
- "prefix");
|
|
|
fd0330 |
- goto fail;
|
|
|
fd0330 |
+ const char *prefix = grub_env_get ("prefix");
|
|
|
fd0330 |
+ if (!prefix)
|
|
|
fd0330 |
+ {
|
|
|
fd0330 |
+ grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"),
|
|
|
fd0330 |
+ "prefix");
|
|
|
fd0330 |
+ goto fail;
|
|
|
fd0330 |
+ }
|
|
|
fd0330 |
+ file = try_open_from_prefix (prefix, filename);
|
|
|
fd0330 |
}
|
|
|
fd0330 |
- fullname = grub_malloc (grub_strlen (prefix) + grub_strlen (filename) + 1
|
|
|
fd0330 |
- + sizeof ("/fonts/") + sizeof (".pf2"));
|
|
|
fd0330 |
- if (!fullname)
|
|
|
fd0330 |
- goto fail;
|
|
|
fd0330 |
- ptr = grub_stpcpy (fullname, prefix);
|
|
|
fd0330 |
- ptr = grub_stpcpy (ptr, "/fonts/");
|
|
|
fd0330 |
- ptr = grub_stpcpy (ptr, filename);
|
|
|
fd0330 |
- ptr = grub_stpcpy (ptr, ".pf2");
|
|
|
fd0330 |
- *ptr = 0;
|
|
|
fd0330 |
- file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024);
|
|
|
fd0330 |
- grub_free (fullname);
|
|
|
fd0330 |
}
|
|
|
fd0330 |
if (!file)
|
|
|
fd0330 |
goto fail;
|