From 3dca11c4e2b425fd26d374b68316648aeec9249e Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 3 Nov 2023 01:44:18 -0400 Subject: [PATCH] LibPDF: Move color space creation from name or array into ColorSpace No behavior change. --- Userland/Libraries/LibPDF/ColorSpace.cpp | 13 +++++++++++++ Userland/Libraries/LibPDF/ColorSpace.h | 1 + Userland/Libraries/LibPDF/Renderer.cpp | 11 +---------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibPDF/ColorSpace.cpp b/Userland/Libraries/LibPDF/ColorSpace.cpp index a3352db524..84556b3bf9 100644 --- a/Userland/Libraries/LibPDF/ColorSpace.cpp +++ b/Userland/Libraries/LibPDF/ColorSpace.cpp @@ -31,6 +31,19 @@ PDFErrorOr ColorSpaceFamily::get(DeprecatedFlyString const& fa return Error(Error::Type::MalformedPDF, "Unknown ColorSpace family"_string); } +PDFErrorOr> ColorSpace::create(Document* document, NonnullRefPtr color_space_object) +{ + // "A color space is defined by an array object whose first element is a name object identifying the color space family. + // The remaining array elements, if any, are parameters that further characterize the color space; + // their number and types vary according to the particular family. + // For families that do not require parameters, the color space can be specified simply by the family name itself instead of an array." + if (color_space_object->is()) + return ColorSpace::create(color_space_object->cast()->name()); + if (color_space_object->is()) + return ColorSpace::create(document, color_space_object->cast()); + return Error { Error::Type::MalformedPDF, "Color space must be name or array" }; +} + PDFErrorOr> ColorSpace::create(DeprecatedFlyString const& name) { // Simple color spaces with no parameters, which can be specified directly diff --git a/Userland/Libraries/LibPDF/ColorSpace.h b/Userland/Libraries/LibPDF/ColorSpace.h index d79dfe807c..a7d4314633 100644 --- a/Userland/Libraries/LibPDF/ColorSpace.h +++ b/Userland/Libraries/LibPDF/ColorSpace.h @@ -50,6 +50,7 @@ private: class ColorSpace : public RefCounted { public: + static PDFErrorOr> create(Document*, NonnullRefPtr); static PDFErrorOr> create(DeprecatedFlyString const&); static PDFErrorOr> create(Document*, NonnullRefPtr); diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index 4a175ff582..2dce468dc7 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -980,16 +980,7 @@ PDFErrorOr> Renderer::get_color_space_from_resources(V PDFErrorOr> Renderer::get_color_space_from_document(NonnullRefPtr color_space_object) { - // "A color space is defined by an array object whose first element is a name object identifying the color space family. - // The remaining array elements, if any, are parameters that further characterize the color space; - // their number and types vary according to the particular family. - // For families that do not require parameters, the color space can be specified simply by the family name itself instead of an array." - - // Pattern cannot be a name in these cases - if (color_space_object->is()) { - return ColorSpace::create(color_space_object->cast()->name()); - } - return ColorSpace::create(m_document, color_space_object->cast()); + return ColorSpace::create(m_document, color_space_object); } Gfx::AffineTransform const& Renderer::calculate_text_rendering_matrix()