From 86203974f55decc0affbddc8bfda336816fdd925 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 28 Feb 2024 08:16:41 -0500 Subject: [PATCH] LibGfx/OpenType: Extract read_tag() function --- Userland/Libraries/LibGfx/Font/OpenType/Font.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp index bb02007192..3ac9c04ff4 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp @@ -156,14 +156,18 @@ ErrorOr> Font::try_load_from_resource(Core::Resource const& return font; } -ErrorOr> Font::try_load_from_externally_owned_memory(ReadonlyBytes buffer, Options options) +static ErrorOr read_tag(ReadonlyBytes buffer) { FixedMemoryStream stream { buffer }; + return stream.read_value(); +} - auto tag = TRY(stream.read_value()); +ErrorOr> 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()); // FIXME: Check for major_version == 2.