From 0d2ca125b3dbe02ec21590fa1959b079bc4ec593 Mon Sep 17 00:00:00 2001 From: Caoimhe Date: Fri, 24 Mar 2023 18:20:27 +0000 Subject: [PATCH] LibGfx: Add a `MappedFile` variant of `BitmapFont::try_load_from_file` Let's make it possible to create a BitmapFont directly from a MappedFile instead of a file path. --- Userland/Libraries/LibGfx/Font/BitmapFont.cpp | 11 ++++++++--- Userland/Libraries/LibGfx/Font/BitmapFont.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp index 6c011d4df4..c24c1eb2db 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp @@ -233,9 +233,14 @@ RefPtr BitmapFont::load_from_file(DeprecatedString const& path) ErrorOr> BitmapFont::try_load_from_file(DeprecatedString const& path) { - auto file = TRY(Core::MappedFile::map(path)); - auto font = TRY(load_from_memory((u8 const*)file->data())); - font->m_mapped_file = file; + auto mapped_file = TRY(Core::MappedFile::map(path)); + return try_load_from_mapped_file(move(mapped_file)); +} + +ErrorOr> BitmapFont::try_load_from_mapped_file(RefPtr const& mapped_file) +{ + auto font = TRY(load_from_memory((u8 const*)mapped_file->data())); + font->m_mapped_file = mapped_file; return font; } diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.h b/Userland/Libraries/LibGfx/Font/BitmapFont.h index 514b358a7e..e6fd644cf5 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.h +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.h @@ -32,6 +32,7 @@ public: static RefPtr load_from_file(DeprecatedString const& path); static ErrorOr> try_load_from_file(DeprecatedString const& path); + static ErrorOr> try_load_from_mapped_file(RefPtr const&); ErrorOr write_to_file(DeprecatedString const& path); ~BitmapFont();