mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
LibPDF: Communicate resources to ColorSpace, not Page
Resources can come from other sources (e.g., XObjects), and since the only attribute we are reading from Page are its resources it makes sense to receive resources instead. That way we'll be able to pass down arbitrary resources that are not necessarily declared at the page level.
This commit is contained in:
parent
164422f8d8
commit
fe5c823989
4 changed files with 12 additions and 12 deletions
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace PDF {
|
||||
|
||||
PDFErrorOr<NonnullRefPtr<ColorSpace>> ColorSpace::create(Document* document, FlyString const& name, Page const& page)
|
||||
PDFErrorOr<NonnullRefPtr<ColorSpace>> ColorSpace::create(Document* document, FlyString const& name, NonnullRefPtr<DictObject> resources)
|
||||
{
|
||||
// Simple color spaces with no parameters, which can be specified directly
|
||||
if (name == CommonNames::DeviceGray)
|
||||
|
@ -25,7 +25,7 @@ PDFErrorOr<NonnullRefPtr<ColorSpace>> ColorSpace::create(Document* document, Fly
|
|||
|
||||
// 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));
|
||||
auto color_space_resource_dict = TRY(resources->get_dict(document, CommonNames::ColorSpace));
|
||||
if (!color_space_resource_dict->contains(name))
|
||||
TODO();
|
||||
|
||||
|
@ -41,7 +41,7 @@ PDFErrorOr<NonnullRefPtr<ColorSpace>> ColorSpace::create(Document* document, Fly
|
|||
return TRY(CalRGBColorSpace::create(document, move(parameters)));
|
||||
|
||||
if (color_space_name == CommonNames::ICCBased)
|
||||
return TRY(ICCBasedColorSpace::create(document, page, move(parameters)));
|
||||
return TRY(ICCBasedColorSpace::create(document, resources, move(parameters)));
|
||||
|
||||
dbgln("Unknown color space: {}", color_space_name);
|
||||
TODO();
|
||||
|
@ -261,7 +261,7 @@ Color CalRGBColorSpace::color(Vector<Value> const& arguments) const
|
|||
return Color(red, green, blue);
|
||||
}
|
||||
|
||||
PDFErrorOr<NonnullRefPtr<ColorSpace>> ICCBasedColorSpace::create(Document* document, Page const& page, Vector<Value>&& parameters)
|
||||
PDFErrorOr<NonnullRefPtr<ColorSpace>> ICCBasedColorSpace::create(Document* document, NonnullRefPtr<DictObject> resources, Vector<Value>&& parameters)
|
||||
{
|
||||
if (parameters.is_empty())
|
||||
return Error { Error::Type::MalformedPDF, "ICCBased color space expected one parameter" };
|
||||
|
@ -287,7 +287,7 @@ PDFErrorOr<NonnullRefPtr<ColorSpace>> ICCBasedColorSpace::create(Document* docum
|
|||
name = TRY(dict->get_name(document, CommonNames::Alternate))->name();
|
||||
}
|
||||
|
||||
return TRY(ColorSpace::create(document, name, page));
|
||||
return TRY(ColorSpace::create(document, name, resources));
|
||||
}
|
||||
|
||||
Color ICCBasedColorSpace::color(Vector<Value> const&) const
|
||||
|
|
|
@ -29,7 +29,7 @@ struct Page;
|
|||
|
||||
class ColorSpace : public RefCounted<ColorSpace> {
|
||||
public:
|
||||
static PDFErrorOr<NonnullRefPtr<ColorSpace>> create(Document*, FlyString const& name, Page const& page);
|
||||
static PDFErrorOr<NonnullRefPtr<ColorSpace>> create(Document*, FlyString const& name, NonnullRefPtr<DictObject> resources);
|
||||
|
||||
virtual ~ColorSpace() = default;
|
||||
|
||||
|
@ -91,7 +91,7 @@ private:
|
|||
|
||||
class ICCBasedColorSpace final : public ColorSpace {
|
||||
public:
|
||||
static PDFErrorOr<NonnullRefPtr<ColorSpace>> create(Document*, Page const&, Vector<Value>&& parameters);
|
||||
static PDFErrorOr<NonnullRefPtr<ColorSpace>> create(Document*, NonnullRefPtr<DictObject> resources, Vector<Value>&& parameters);
|
||||
|
||||
~ICCBasedColorSpace() override = default;
|
||||
|
||||
|
|
|
@ -496,14 +496,14 @@ RENDERER_TODO(type3_font_set_glyph_width_and_bbox)
|
|||
|
||||
RENDERER_HANDLER(set_stroking_space)
|
||||
{
|
||||
state().stroke_color_space = TRY(get_color_space(args[0]));
|
||||
state().stroke_color_space = TRY(get_color_space(args[0], m_page.resources));
|
||||
VERIFY(state().stroke_color_space);
|
||||
return {};
|
||||
}
|
||||
|
||||
RENDERER_HANDLER(set_painting_space)
|
||||
{
|
||||
state().paint_color_space = TRY(get_color_space(args[0]));
|
||||
state().paint_color_space = TRY(get_color_space(args[0], m_page.resources));
|
||||
VERIFY(state().paint_color_space);
|
||||
return {};
|
||||
}
|
||||
|
@ -701,10 +701,10 @@ void Renderer::show_text(String const& string)
|
|||
m_text_matrix.translate(delta_x / text_rendering_matrix.x_scale(), 0.0f);
|
||||
}
|
||||
|
||||
PDFErrorOr<NonnullRefPtr<ColorSpace>> Renderer::get_color_space(Value const& value)
|
||||
PDFErrorOr<NonnullRefPtr<ColorSpace>> Renderer::get_color_space(Value const& value, NonnullRefPtr<DictObject> resources)
|
||||
{
|
||||
auto name = value.get<NonnullRefPtr<Object>>()->cast<NameObject>()->name();
|
||||
return TRY(ColorSpace::create(m_document, name, m_page));
|
||||
return TRY(ColorSpace::create(m_document, name, resources));
|
||||
}
|
||||
|
||||
Gfx::AffineTransform const& Renderer::calculate_text_rendering_matrix()
|
||||
|
|
|
@ -109,7 +109,7 @@ private:
|
|||
void end_path_paint();
|
||||
PDFErrorOr<void> set_graphics_state_from_dict(NonnullRefPtr<DictObject>);
|
||||
void show_text(String const&);
|
||||
PDFErrorOr<NonnullRefPtr<ColorSpace>> get_color_space(Value const&);
|
||||
PDFErrorOr<NonnullRefPtr<ColorSpace>> get_color_space(Value const&, NonnullRefPtr<DictObject>);
|
||||
|
||||
ALWAYS_INLINE GraphicsState const& state() const { return m_graphics_state_stack.last(); }
|
||||
ALWAYS_INLINE GraphicsState& state() { return m_graphics_state_stack.last(); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue