mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:18:12 +00:00
LibGfx: Add helpers to load BitmapFont from Core::Resource
This commit is contained in:
parent
897f4d05eb
commit
d587bd0a04
2 changed files with 25 additions and 2 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <AK/Utf32View.h>
|
||||
#include <AK/Utf8View.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Resource.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibGfx/Font/FontDatabase.h>
|
||||
#include <LibGfx/Font/FontStyleMapping.h>
|
||||
|
@ -224,13 +225,31 @@ ErrorOr<NonnullRefPtr<BitmapFont>> BitmapFont::try_load_from_stream(FixedMemoryS
|
|||
return font;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<BitmapFont>> BitmapFont::try_load_from_resource(NonnullRefPtr<Core::Resource> resource)
|
||||
{
|
||||
auto stream = resource->stream();
|
||||
auto font = TRY(try_load_from_stream(stream));
|
||||
font->m_owned_data = move(resource);
|
||||
return font;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<BitmapFont>> BitmapFont::try_load_from_mapped_file(NonnullOwnPtr<Core::MappedFile> 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> BitmapFont::load_from_uri(StringView uri)
|
||||
{
|
||||
return MUST(try_load_from_uri(uri));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<BitmapFont>> BitmapFont::try_load_from_uri(StringView uri)
|
||||
{
|
||||
return try_load_from_resource(TRY(Core::Resource::load_from_uri(uri)));
|
||||
}
|
||||
|
||||
RefPtr<BitmapFont> BitmapFont::load_from_file(DeprecatedString const& path)
|
||||
{
|
||||
return MUST(try_load_from_file(move(path)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue