mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibGfx: Rename WOFF[2]::try_load_from_externally_owned_memory()
Typeface::try_load_from_externally_owned_memory() relies on that external owner keeping the memory around. However, neither WOFF nor WOFF2 do so - they both create separate ByteBuffers to hold the TTF data. So, rename them to make it clearer that they don't have any requirements on the byte owner.
This commit is contained in:
parent
23009779e1
commit
6b762331df
Notes:
github-actions[bot]
2025-05-03 11:03:42 +00:00
Author: https://github.com/AtkinsSJ
Commit: 6b762331df
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4536
10 changed files with 14 additions and 14 deletions
|
@ -70,7 +70,7 @@ static u16 pow_2_less_than_or_equal(u16 x)
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_resource(Core::Resource const& resource, unsigned index)
|
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_resource(Core::Resource const& resource, unsigned index)
|
||||||
{
|
{
|
||||||
return try_load_from_externally_owned_memory(resource.data(), index);
|
return try_load_from_bytes(resource.data(), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
using Uint8 = u8;
|
using Uint8 = u8;
|
||||||
|
@ -102,7 +102,7 @@ struct [[gnu::packed]] TableRecord {
|
||||||
};
|
};
|
||||||
static_assert(AssertSize<TableRecord, 16>());
|
static_assert(AssertSize<TableRecord, 16>());
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_externally_owned_memory(ReadonlyBytes buffer, unsigned int index)
|
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_bytes(ReadonlyBytes buffer, unsigned int index)
|
||||||
{
|
{
|
||||||
FixedMemoryStream stream(buffer);
|
FixedMemoryStream stream(buffer);
|
||||||
auto header = TRY(stream.read_value<Header>());
|
auto header = TRY(stream.read_value<Header>());
|
||||||
|
|
|
@ -14,6 +14,6 @@
|
||||||
namespace WOFF {
|
namespace WOFF {
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_resource(Core::Resource const&, unsigned index = 0);
|
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_resource(Core::Resource const&, unsigned index = 0);
|
||||||
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_externally_owned_memory(ReadonlyBytes bytes, unsigned index = 0);
|
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_bytes(ReadonlyBytes bytes, unsigned index = 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ private:
|
||||||
ByteBuffer& m_buffer;
|
ByteBuffer& m_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_externally_owned_memory(ReadonlyBytes bytes)
|
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_bytes(ReadonlyBytes bytes)
|
||||||
{
|
{
|
||||||
auto ttf_buffer = TRY(ByteBuffer::create_uninitialized(0));
|
auto ttf_buffer = TRY(ByteBuffer::create_uninitialized(0));
|
||||||
auto output = WOFF2ByteBufferOut { ttf_buffer };
|
auto output = WOFF2ByteBufferOut { ttf_buffer };
|
||||||
|
|
|
@ -13,6 +13,6 @@
|
||||||
|
|
||||||
namespace WOFF2 {
|
namespace WOFF2 {
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_externally_owned_memory(ReadonlyBytes);
|
ErrorOr<NonnullRefPtr<Gfx::Typeface>> try_load_from_bytes(ReadonlyBytes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,12 +41,12 @@ static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface const>>> load_vec
|
||||||
promise->resolve(ttf.release_value());
|
promise->resolve(ttf.release_value());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto woff = WOFF::try_load_from_externally_owned_memory(data);
|
auto woff = WOFF::try_load_from_bytes(data);
|
||||||
if (!woff.is_error()) {
|
if (!woff.is_error()) {
|
||||||
promise->resolve(woff.release_value());
|
promise->resolve(woff.release_value());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto woff2 = WOFF2::try_load_from_externally_owned_memory(data);
|
auto woff2 = WOFF2::try_load_from_bytes(data);
|
||||||
if (!woff2.is_error()) {
|
if (!woff2.is_error()) {
|
||||||
promise->resolve(woff2.release_value());
|
promise->resolve(woff2.release_value());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -274,12 +274,12 @@ ErrorOr<NonnullRefPtr<Gfx::Typeface const>> FontLoader::try_load_font()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mime_type->essence() == "font/woff"sv || mime_type->essence() == "application/font-woff"sv) {
|
if (mime_type->essence() == "font/woff"sv || mime_type->essence() == "application/font-woff"sv) {
|
||||||
if (auto result = WOFF::try_load_from_externally_owned_memory(resource()->encoded_data()); !result.is_error()) {
|
if (auto result = WOFF::try_load_from_bytes(resource()->encoded_data()); !result.is_error()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mime_type->essence() == "font/woff2"sv || mime_type->essence() == "application/font-woff2"sv) {
|
if (mime_type->essence() == "font/woff2"sv || mime_type->essence() == "application/font-woff2"sv) {
|
||||||
if (auto result = WOFF2::try_load_from_externally_owned_memory(resource()->encoded_data()); !result.is_error()) {
|
if (auto result = WOFF2::try_load_from_bytes(resource()->encoded_data()); !result.is_error()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@
|
||||||
extern "C" int LLVMFuzzerTestOneInput(u8 const* data, size_t size)
|
extern "C" int LLVMFuzzerTestOneInput(u8 const* data, size_t size)
|
||||||
{
|
{
|
||||||
AK::set_debug_enabled(false);
|
AK::set_debug_enabled(false);
|
||||||
(void)WOFF::try_load_from_externally_owned_memory({ data, size });
|
(void)WOFF::try_load_from_bytes({ data, size });
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@
|
||||||
extern "C" int LLVMFuzzerTestOneInput(u8 const* data, size_t size)
|
extern "C" int LLVMFuzzerTestOneInput(u8 const* data, size_t size)
|
||||||
{
|
{
|
||||||
AK::set_debug_enabled(false);
|
AK::set_debug_enabled(false);
|
||||||
(void)WOFF2::try_load_from_externally_owned_memory({ data, size });
|
(void)WOFF2::try_load_from_bytes({ data, size });
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ TEST_CASE(malformed_woff)
|
||||||
|
|
||||||
for (auto test_input : test_inputs) {
|
for (auto test_input : test_inputs) {
|
||||||
auto file = MUST(Core::MappedFile::map(test_input));
|
auto file = MUST(Core::MappedFile::map(test_input));
|
||||||
auto font_or_error = WOFF::try_load_from_externally_owned_memory(file->bytes());
|
auto font_or_error = WOFF::try_load_from_bytes(file->bytes());
|
||||||
EXPECT(font_or_error.is_error());
|
EXPECT(font_or_error.is_error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ struct Global {
|
||||||
TEST_CASE(tolerate_incorrect_sfnt_size)
|
TEST_CASE(tolerate_incorrect_sfnt_size)
|
||||||
{
|
{
|
||||||
auto file = MUST(Core::MappedFile::map(TEST_INPUT("woff2/incorrect_sfnt_size.woff2"sv)));
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("woff2/incorrect_sfnt_size.woff2"sv)));
|
||||||
auto font = TRY_OR_FAIL(WOFF2::try_load_from_externally_owned_memory(file->bytes()));
|
auto font = TRY_OR_FAIL(WOFF2::try_load_from_bytes(file->bytes()));
|
||||||
EXPECT_EQ(font->family(), "Test"_string);
|
EXPECT_EQ(font->family(), "Test"_string);
|
||||||
EXPECT_EQ(font->glyph_count(), 4u);
|
EXPECT_EQ(font->glyph_count(), 4u);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ TEST_CASE(malformed_woff2)
|
||||||
|
|
||||||
for (auto test_input : test_inputs) {
|
for (auto test_input : test_inputs) {
|
||||||
auto file = MUST(Core::MappedFile::map(test_input));
|
auto file = MUST(Core::MappedFile::map(test_input));
|
||||||
auto font_or_error = WOFF2::try_load_from_externally_owned_memory(file->bytes());
|
auto font_or_error = WOFF2::try_load_from_bytes(file->bytes());
|
||||||
EXPECT(font_or_error.is_error());
|
EXPECT(font_or_error.is_error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue