|
@@ -10,7 +10,7 @@
|
|
|
|
|
|
namespace PDF {
|
|
namespace PDF {
|
|
|
|
|
|
-RefPtr<DeviceGrayColorSpace> DeviceGrayColorSpace::the()
|
|
|
|
|
|
+NonnullRefPtr<DeviceGrayColorSpace> DeviceGrayColorSpace::the()
|
|
{
|
|
{
|
|
static auto instance = adopt_ref(*new DeviceGrayColorSpace());
|
|
static auto instance = adopt_ref(*new DeviceGrayColorSpace());
|
|
return instance;
|
|
return instance;
|
|
@@ -23,7 +23,7 @@ Color DeviceGrayColorSpace::color(Vector<Value> const& arguments) const
|
|
return Color(gray, gray, gray);
|
|
return Color(gray, gray, gray);
|
|
}
|
|
}
|
|
|
|
|
|
-RefPtr<DeviceRGBColorSpace> DeviceRGBColorSpace::the()
|
|
|
|
|
|
+NonnullRefPtr<DeviceRGBColorSpace> DeviceRGBColorSpace::the()
|
|
{
|
|
{
|
|
static auto instance = adopt_ref(*new DeviceRGBColorSpace());
|
|
static auto instance = adopt_ref(*new DeviceRGBColorSpace());
|
|
return instance;
|
|
return instance;
|
|
@@ -38,7 +38,7 @@ Color DeviceRGBColorSpace::color(Vector<Value> const& arguments) const
|
|
return Color(r, g, b);
|
|
return Color(r, g, b);
|
|
}
|
|
}
|
|
|
|
|
|
-RefPtr<DeviceCMYKColorSpace> DeviceCMYKColorSpace::the()
|
|
|
|
|
|
+NonnullRefPtr<DeviceCMYKColorSpace> DeviceCMYKColorSpace::the()
|
|
{
|
|
{
|
|
static auto instance = adopt_ref(*new DeviceCMYKColorSpace());
|
|
static auto instance = adopt_ref(*new DeviceCMYKColorSpace());
|
|
return instance;
|
|
return instance;
|
|
@@ -54,23 +54,22 @@ Color DeviceCMYKColorSpace::color(Vector<Value> const& arguments) const
|
|
return Color::from_cmyk(c, m, y, k);
|
|
return Color::from_cmyk(c, m, y, k);
|
|
}
|
|
}
|
|
|
|
|
|
-RefPtr<CalRGBColorSpace> CalRGBColorSpace::create(RefPtr<Document> document, Vector<Value>&& parameters)
|
|
|
|
|
|
+PDFErrorOr<NonnullRefPtr<CalRGBColorSpace>> CalRGBColorSpace::create(RefPtr<Document> document, Vector<Value>&& parameters)
|
|
{
|
|
{
|
|
if (parameters.size() != 1)
|
|
if (parameters.size() != 1)
|
|
- return {};
|
|
|
|
|
|
+ return Error { Error::Type::MalformedPDF, "RGB color space expects one parameter" };
|
|
|
|
|
|
auto param = parameters[0];
|
|
auto param = parameters[0];
|
|
if (!param.has<NonnullRefPtr<Object>>() || !param.get<NonnullRefPtr<Object>>()->is<DictObject>())
|
|
if (!param.has<NonnullRefPtr<Object>>() || !param.get<NonnullRefPtr<Object>>()->is<DictObject>())
|
|
- return {};
|
|
|
|
|
|
+ return Error { Error::Type::MalformedPDF, "RGB color space expects a dict parameter" };
|
|
|
|
|
|
auto dict = param.get<NonnullRefPtr<Object>>()->cast<DictObject>();
|
|
auto dict = param.get<NonnullRefPtr<Object>>()->cast<DictObject>();
|
|
if (!dict->contains(CommonNames::WhitePoint))
|
|
if (!dict->contains(CommonNames::WhitePoint))
|
|
- return {};
|
|
|
|
|
|
+ return Error { Error::Type::MalformedPDF, "RGB color space expects a Whitepoint key" };
|
|
|
|
|
|
- // FIXME: Propagate errors
|
|
|
|
- auto white_point_array = MUST(dict->get_array(document, CommonNames::WhitePoint));
|
|
|
|
|
|
+ auto white_point_array = TRY(dict->get_array(document, CommonNames::WhitePoint));
|
|
if (white_point_array->size() != 3)
|
|
if (white_point_array->size() != 3)
|
|
- return {};
|
|
|
|
|
|
+ return Error { Error::Type::MalformedPDF, "RGB color space expects 3 Whitepoint parameters" };
|
|
|
|
|
|
auto color_space = adopt_ref(*new CalRGBColorSpace());
|
|
auto color_space = adopt_ref(*new CalRGBColorSpace());
|
|
|
|
|
|
@@ -79,10 +78,10 @@ RefPtr<CalRGBColorSpace> CalRGBColorSpace::create(RefPtr<Document> document, Vec
|
|
color_space->m_whitepoint[2] = white_point_array->at(2).to_float();
|
|
color_space->m_whitepoint[2] = white_point_array->at(2).to_float();
|
|
|
|
|
|
if (color_space->m_whitepoint[1] != 1.0f)
|
|
if (color_space->m_whitepoint[1] != 1.0f)
|
|
- return {};
|
|
|
|
|
|
+ return Error { Error::Type::MalformedPDF, "RGB color space expects 2nd Whitepoint to be 1.0" };
|
|
|
|
|
|
if (dict->contains(CommonNames::BlackPoint)) {
|
|
if (dict->contains(CommonNames::BlackPoint)) {
|
|
- auto black_point_array = MUST(dict->get_array(document, CommonNames::BlackPoint));
|
|
|
|
|
|
+ auto black_point_array = TRY(dict->get_array(document, CommonNames::BlackPoint));
|
|
if (black_point_array->size() == 3) {
|
|
if (black_point_array->size() == 3) {
|
|
color_space->m_blackpoint[0] = black_point_array->at(0).to_float();
|
|
color_space->m_blackpoint[0] = black_point_array->at(0).to_float();
|
|
color_space->m_blackpoint[1] = black_point_array->at(1).to_float();
|
|
color_space->m_blackpoint[1] = black_point_array->at(1).to_float();
|
|
@@ -91,7 +90,7 @@ RefPtr<CalRGBColorSpace> CalRGBColorSpace::create(RefPtr<Document> document, Vec
|
|
}
|
|
}
|
|
|
|
|
|
if (dict->contains(CommonNames::Gamma)) {
|
|
if (dict->contains(CommonNames::Gamma)) {
|
|
- auto gamma_array = MUST(dict->get_array(document, CommonNames::Gamma));
|
|
|
|
|
|
+ auto gamma_array = TRY(dict->get_array(document, CommonNames::Gamma));
|
|
if (gamma_array->size() == 3) {
|
|
if (gamma_array->size() == 3) {
|
|
color_space->m_gamma[0] = gamma_array->at(0).to_float();
|
|
color_space->m_gamma[0] = gamma_array->at(0).to_float();
|
|
color_space->m_gamma[1] = gamma_array->at(1).to_float();
|
|
color_space->m_gamma[1] = gamma_array->at(1).to_float();
|
|
@@ -100,7 +99,7 @@ RefPtr<CalRGBColorSpace> CalRGBColorSpace::create(RefPtr<Document> document, Vec
|
|
}
|
|
}
|
|
|
|
|
|
if (dict->contains(CommonNames::Matrix)) {
|
|
if (dict->contains(CommonNames::Matrix)) {
|
|
- auto matrix_array = MUST(dict->get_array(document, CommonNames::Matrix));
|
|
|
|
|
|
+ auto matrix_array = TRY(dict->get_array(document, CommonNames::Matrix));
|
|
if (matrix_array->size() == 3) {
|
|
if (matrix_array->size() == 3) {
|
|
color_space->m_matrix[0] = matrix_array->at(0).to_float();
|
|
color_space->m_matrix[0] = matrix_array->at(0).to_float();
|
|
color_space->m_matrix[1] = matrix_array->at(1).to_float();
|
|
color_space->m_matrix[1] = matrix_array->at(1).to_float();
|