Преглед на файлове

LibPDF: Move color space creation from name or array into ColorSpace

No behavior change.
Nico Weber преди 1 година
родител
ревизия
3dca11c4e2
променени са 3 файла, в които са добавени 15 реда и са изтрити 10 реда
  1. 13 0
      Userland/Libraries/LibPDF/ColorSpace.cpp
  2. 1 0
      Userland/Libraries/LibPDF/ColorSpace.h
  3. 1 10
      Userland/Libraries/LibPDF/Renderer.cpp

+ 13 - 0
Userland/Libraries/LibPDF/ColorSpace.cpp

@@ -31,6 +31,19 @@ PDFErrorOr<ColorSpaceFamily> ColorSpaceFamily::get(DeprecatedFlyString const& fa
     return Error(Error::Type::MalformedPDF, "Unknown ColorSpace family"_string);
 }
 
+PDFErrorOr<NonnullRefPtr<ColorSpace>> ColorSpace::create(Document* document, NonnullRefPtr<Object> 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<NameObject>())
+        return ColorSpace::create(color_space_object->cast<NameObject>()->name());
+    if (color_space_object->is<ArrayObject>())
+        return ColorSpace::create(document, color_space_object->cast<ArrayObject>());
+    return Error { Error::Type::MalformedPDF, "Color space must be name or array" };
+}
+
 PDFErrorOr<NonnullRefPtr<ColorSpace>> ColorSpace::create(DeprecatedFlyString const& name)
 {
     // Simple color spaces with no parameters, which can be specified directly

+ 1 - 0
Userland/Libraries/LibPDF/ColorSpace.h

@@ -50,6 +50,7 @@ private:
 
 class ColorSpace : public RefCounted<ColorSpace> {
 public:
+    static PDFErrorOr<NonnullRefPtr<ColorSpace>> create(Document*, NonnullRefPtr<Object>);
     static PDFErrorOr<NonnullRefPtr<ColorSpace>> create(DeprecatedFlyString const&);
     static PDFErrorOr<NonnullRefPtr<ColorSpace>> create(Document*, NonnullRefPtr<ArrayObject>);
 

+ 1 - 10
Userland/Libraries/LibPDF/Renderer.cpp

@@ -980,16 +980,7 @@ PDFErrorOr<NonnullRefPtr<ColorSpace>> Renderer::get_color_space_from_resources(V
 
 PDFErrorOr<NonnullRefPtr<ColorSpace>> Renderer::get_color_space_from_document(NonnullRefPtr<Object> 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<NameObject>()) {
-        return ColorSpace::create(color_space_object->cast<NameObject>()->name());
-    }
-    return ColorSpace::create(m_document, color_space_object->cast<ArrayObject>());
+    return ColorSpace::create(m_document, color_space_object);
 }
 
 Gfx::AffineTransform const& Renderer::calculate_text_rendering_matrix()