1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:07:44 +00:00

LibGfx/OpenType: Extract read_tag() function

This commit is contained in:
Nico Weber 2024-02-28 08:16:41 -05:00 committed by Tim Flynn
parent 93038f6f24
commit 86203974f5

View file

@ -156,14 +156,18 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_resource(Core::Resource const&
return font;
}
ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(ReadonlyBytes buffer, Options options)
static ErrorOr<Tag> read_tag(ReadonlyBytes buffer)
{
FixedMemoryStream stream { buffer };
return stream.read_value<Tag>();
}
auto tag = TRY(stream.read_value<Tag>());
ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(ReadonlyBytes buffer, Options options)
{
auto tag = TRY(read_tag(buffer));
if (tag == Tag("ttcf")) {
// It's a font collection
TRY(stream.seek(0, SeekMode::SetPosition));
FixedMemoryStream stream { buffer };
auto ttc_header_v1 = TRY(stream.read_in_place<TTCHeaderV1>());
// FIXME: Check for major_version == 2.