mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
Tests: Add a PDF rendering test
Having some rendering test coverage is motivated by #22362, but this test wouldn't have found the crashes over there (since colorspaces.pdf does not contain pattern color spaces). Still, good to have some in-repo test coverage of PDF rendering.
This commit is contained in:
parent
d577d181e3
commit
4107c2985e
Notes:
sideshowbarker
2024-07-17 07:06:47 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/4107c2985e Pull-request: https://github.com/SerenityOS/serenity/pull/22363 Reviewed-by: https://github.com/LucasChollet
@ -3,7 +3,7 @@ set(TEST_SOURCES
|
||||
)
|
||||
|
||||
foreach(source IN LISTS TEST_SOURCES)
|
||||
serenity_test("${source}" LibPDF LIBS LibCore LibPDF)
|
||||
serenity_test("${source}" LibPDF LIBS LibCore LibGfx LibPDF)
|
||||
endforeach()
|
||||
|
||||
set(TEST_FILES
|
||||
|
@ -7,9 +7,11 @@
|
||||
#include <AK/ByteString.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <LibCore/MappedFile.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibPDF/CommonNames.h>
|
||||
#include <LibPDF/Document.h>
|
||||
#include <LibPDF/Function.h>
|
||||
#include <LibPDF/Renderer.h>
|
||||
#include <LibTest/Macros.h>
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
@ -267,3 +269,34 @@ TEST_CASE(postscript)
|
||||
check_evaluate("{ 3 1 roll }"sv, { 0.5f, 1.0f, 2.0f }, { 2.0f, 0.5f, 1.0f });
|
||||
check_evaluate("{ 3 -1 roll }"sv, { 0.5f, 1.0f, 2.0f }, { 1.0f, 2.0f, 0.5f });
|
||||
}
|
||||
|
||||
TEST_CASE(render)
|
||||
{
|
||||
auto file = MUST(Core::MappedFile::map("colorspaces.pdf"sv));
|
||||
auto document = MUST(PDF::Document::create(file->bytes()));
|
||||
MUST(document->initialize());
|
||||
EXPECT_EQ(document->get_page_count(), 1U);
|
||||
|
||||
auto page = MUST(document->get_page(0));
|
||||
auto page_size = Gfx::IntSize { 310, 370 };
|
||||
auto bitmap = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, page_size));
|
||||
MUST(PDF::Renderer::render(document, page, bitmap, Color::White, PDF::RenderingPreferences {}));
|
||||
|
||||
// DeviceGray
|
||||
EXPECT_EQ(bitmap->get_pixel(270, 370 - 20), Gfx::Color::NamedColor::Black);
|
||||
|
||||
// MyCalRGB
|
||||
EXPECT_EQ(bitmap->get_pixel(270, 370 - 80), Gfx::Color::NamedColor::Black);
|
||||
|
||||
// DeviceRGB
|
||||
EXPECT_EQ(bitmap->get_pixel(270, 370 - 140), Gfx::Color::NamedColor::Black);
|
||||
|
||||
// DeviceCMYK (note: black one box further left)
|
||||
EXPECT_EQ(bitmap->get_pixel(220, 370 - 200), Gfx::Color::NamedColor::Black);
|
||||
|
||||
// MyLab
|
||||
EXPECT_EQ(bitmap->get_pixel(270, 370 - 260), Gfx::Color::NamedColor::Black);
|
||||
|
||||
// MyCalGray
|
||||
EXPECT_EQ(bitmap->get_pixel(270, 370 - 320), Gfx::Color::NamedColor::Black);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user