2023-10-24 07:54:20 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2023, Tim Ledbetter <timledbetter@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2024-10-11 18:17:07 -06:00
|
|
|
#include <LibGfx/Font/FontDatabase.h>
|
|
|
|
|
#include <LibGfx/Font/PathFontProvider.h>
|
2024-07-22 14:03:58 +03:00
|
|
|
#include <LibGfx/Font/WOFF2/Loader.h>
|
2023-10-24 07:54:20 +01:00
|
|
|
#include <LibTest/TestCase.h>
|
|
|
|
|
|
2024-07-04 22:39:15 +01:00
|
|
|
#define TEST_INPUT(x) ("test-inputs/" x)
|
2023-10-24 07:54:20 +01:00
|
|
|
|
2024-10-11 18:17:07 -06:00
|
|
|
namespace {
|
2025-05-13 07:06:33 -04:00
|
|
|
|
2024-10-11 18:17:07 -06:00
|
|
|
struct Global {
|
|
|
|
|
Global()
|
|
|
|
|
{
|
|
|
|
|
Gfx::FontDatabase::the().install_system_font_provider(make<Gfx::PathFontProvider>());
|
|
|
|
|
}
|
|
|
|
|
} global;
|
2025-05-13 07:06:33 -04:00
|
|
|
|
2024-10-11 18:17:07 -06:00
|
|
|
}
|
|
|
|
|
|
2023-10-24 07:54:20 +01:00
|
|
|
TEST_CASE(tolerate_incorrect_sfnt_size)
|
|
|
|
|
{
|
|
|
|
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("woff2/incorrect_sfnt_size.woff2"sv)));
|
2025-05-02 17:46:51 +01:00
|
|
|
auto font = TRY_OR_FAIL(WOFF2::try_load_from_bytes(file->bytes()));
|
2023-10-24 07:54:20 +01:00
|
|
|
EXPECT_EQ(font->family(), "Test"_string);
|
|
|
|
|
EXPECT_EQ(font->glyph_count(), 4u);
|
|
|
|
|
}
|
2023-10-24 07:54:20 +01:00
|
|
|
|
|
|
|
|
TEST_CASE(malformed_woff2)
|
|
|
|
|
{
|
|
|
|
|
Array test_inputs = {
|
2023-10-25 21:46:50 +01:00
|
|
|
TEST_INPUT("woff2/incorrect_compressed_size.woff2"sv),
|
|
|
|
|
TEST_INPUT("woff2/invalid_numtables.woff2"sv)
|
2023-10-24 07:54:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (auto test_input : test_inputs) {
|
|
|
|
|
auto file = MUST(Core::MappedFile::map(test_input));
|
2025-05-02 17:46:51 +01:00
|
|
|
auto font_or_error = WOFF2::try_load_from_bytes(file->bytes());
|
2023-10-24 07:54:20 +01:00
|
|
|
EXPECT(font_or_error.is_error());
|
|
|
|
|
}
|
|
|
|
|
}
|