diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp index 1ef9234ff6..f3f5bd9fac 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -224,13 +225,31 @@ ErrorOr> BitmapFont::try_load_from_stream(FixedMemoryS return font; } +ErrorOr> BitmapFont::try_load_from_resource(NonnullRefPtr resource) +{ + auto stream = resource->stream(); + auto font = TRY(try_load_from_stream(stream)); + font->m_owned_data = move(resource); + return font; +} + ErrorOr> BitmapFont::try_load_from_mapped_file(NonnullOwnPtr mapped_file) { auto font = TRY(try_load_from_stream(*mapped_file)); - font->m_mapped_file = move(mapped_file); + font->m_owned_data = move(mapped_file); return font; } +NonnullRefPtr BitmapFont::load_from_uri(StringView uri) +{ + return MUST(try_load_from_uri(uri)); +} + +ErrorOr> BitmapFont::try_load_from_uri(StringView uri) +{ + return try_load_from_resource(TRY(Core::Resource::load_from_uri(uri))); +} + RefPtr BitmapFont::load_from_file(DeprecatedString const& path) { return MUST(try_load_from_file(move(path))); diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.h b/Userland/Libraries/LibGfx/Font/BitmapFont.h index e3963f3882..333e60a37c 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.h +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -29,7 +30,10 @@ public: ErrorOr> masked_character_set() const; ErrorOr> unmasked_character_set() const; + static NonnullRefPtr load_from_uri(StringView); static RefPtr load_from_file(DeprecatedString const& path); + static ErrorOr> try_load_from_uri(StringView); + static ErrorOr> try_load_from_resource(NonnullRefPtr); static ErrorOr> try_load_from_file(DeprecatedString const& path); static ErrorOr> try_load_from_mapped_file(NonnullOwnPtr); static ErrorOr> try_load_from_stream(FixedMemoryStream&); @@ -151,7 +155,7 @@ private: Bytes m_rows; Span m_glyph_widths; - OwnPtr m_mapped_file; + Variant, NonnullRefPtr> m_owned_data = Empty {}; u8 m_glyph_width { 0 }; u8 m_glyph_height { 0 };