1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:57:46 +00:00

LibGfx+Utilities: Add helpers to load vector fonts from Core::Resources

This commit is contained in:
Andrew Kaster 2023-10-18 14:12:42 -06:00 committed by Andrew Kaster
parent 286dc6df7f
commit 86ce502ae2
8 changed files with 19 additions and 21 deletions

View file

@ -9,6 +9,7 @@
#include <AK/IntegralMath.h>
#include <AK/MemoryStream.h>
#include <LibCompress/Zlib.h>
#include <LibCore/Resource.h>
#include <LibGfx/Font/OpenType/Font.h>
#include <LibGfx/Font/WOFF/Font.h>
@ -68,10 +69,9 @@ static u16 pow_2_less_than_or_equal(u16 x)
return 1 << (sizeof(u16) * 8 - count_leading_zeroes_safe<u16>(x - 1));
}
ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_file(DeprecatedString path, unsigned int index)
ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_resource(Core::Resource const& resource, unsigned index)
{
auto file = TRY(Core::MappedFile::map(path));
return try_load_from_externally_owned_memory(file->bytes(), index);
return try_load_from_externally_owned_memory(resource.data(), index);
}
ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(ReadonlyBytes buffer, unsigned int index)