|
@@ -6,10 +6,44 @@
|
|
|
|
|
|
#include <LibPDF/ColorSpace.h>
|
|
|
#include <LibPDF/CommonNames.h>
|
|
|
+#include <LibPDF/Document.h>
|
|
|
#include <LibPDF/ObjectDerivatives.h>
|
|
|
|
|
|
namespace PDF {
|
|
|
|
|
|
+PDFErrorOr<NonnullRefPtr<ColorSpace>> ColorSpace::create(Document* document, FlyString const& name, Page const& page)
|
|
|
+{
|
|
|
+ // Simple color spaces with no parameters, which can be specified directly
|
|
|
+ if (name == CommonNames::DeviceGray)
|
|
|
+ return DeviceGrayColorSpace::the();
|
|
|
+ if (name == CommonNames::DeviceRGB)
|
|
|
+ return DeviceRGBColorSpace::the();
|
|
|
+ if (name == CommonNames::DeviceCMYK)
|
|
|
+ return DeviceCMYKColorSpace::the();
|
|
|
+ if (name == CommonNames::Pattern)
|
|
|
+ TODO();
|
|
|
+
|
|
|
+ // The color space is a complex color space with parameters that resides in
|
|
|
+ // the resource dictionary
|
|
|
+ auto color_space_resource_dict = TRY(page.resources->get_dict(document, CommonNames::ColorSpace));
|
|
|
+ if (!color_space_resource_dict->contains(name))
|
|
|
+ TODO();
|
|
|
+
|
|
|
+ auto color_space_array = TRY(color_space_resource_dict->get_array(document, name));
|
|
|
+ auto color_space_name = TRY(color_space_array->get_name_at(document, 0))->name();
|
|
|
+
|
|
|
+ Vector<Value> parameters;
|
|
|
+ parameters.ensure_capacity(color_space_array->size() - 1);
|
|
|
+ for (size_t i = 1; i < color_space_array->size(); i++)
|
|
|
+ parameters.unchecked_append(color_space_array->at(i));
|
|
|
+
|
|
|
+ if (color_space_name == CommonNames::CalRGB)
|
|
|
+ return TRY(CalRGBColorSpace::create(document, move(parameters)));
|
|
|
+
|
|
|
+ dbgln("Unknown color space: {}", color_space_name);
|
|
|
+ TODO();
|
|
|
+}
|
|
|
+
|
|
|
NonnullRefPtr<DeviceGrayColorSpace> DeviceGrayColorSpace::the()
|
|
|
{
|
|
|
static auto instance = adopt_ref(*new DeviceGrayColorSpace());
|
|
@@ -54,7 +88,7 @@ Color DeviceCMYKColorSpace::color(Vector<Value> const& arguments) const
|
|
|
return Color::from_cmyk(c, m, y, k);
|
|
|
}
|
|
|
|
|
|
-PDFErrorOr<NonnullRefPtr<CalRGBColorSpace>> CalRGBColorSpace::create(RefPtr<Document> document, Vector<Value>&& parameters)
|
|
|
+PDFErrorOr<NonnullRefPtr<CalRGBColorSpace>> CalRGBColorSpace::create(Document* document, Vector<Value>&& parameters)
|
|
|
{
|
|
|
if (parameters.size() != 1)
|
|
|
return Error { Error::Type::MalformedPDF, "RGB color space expects one parameter" };
|