mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:47:35 +00:00
LibPDF: Require Document* in Parser constructor
This makes it a bit easier to avoid calling parser->set_document, an issue which cost me ~30 minutes to find.
This commit is contained in:
parent
a8de9cf541
commit
60c3e786be
3 changed files with 7 additions and 6 deletions
|
@ -22,14 +22,15 @@ static NonnullRefPtr<T> make_object(Args... args) requires(IsBaseOf<Object, T>)
|
||||||
return adopt_ref(*new T(forward<Args>(args)...));
|
return adopt_ref(*new T(forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFErrorOr<Vector<Command>> Parser::parse_graphics_commands(ReadonlyBytes bytes)
|
PDFErrorOr<Vector<Command>> Parser::parse_graphics_commands(Document* document, ReadonlyBytes bytes)
|
||||||
{
|
{
|
||||||
auto parser = adopt_ref(*new Parser(bytes));
|
auto parser = adopt_ref(*new Parser(document, bytes));
|
||||||
return parser->parse_graphics_commands();
|
return parser->parse_graphics_commands();
|
||||||
}
|
}
|
||||||
|
|
||||||
Parser::Parser(Badge<Document>, ReadonlyBytes bytes)
|
Parser::Parser(Document* document, ReadonlyBytes bytes)
|
||||||
: m_reader(bytes)
|
: m_reader(bytes)
|
||||||
|
, m_document(document)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,9 @@ public:
|
||||||
Linearized,
|
Linearized,
|
||||||
};
|
};
|
||||||
|
|
||||||
static PDFErrorOr<Vector<Command>> parse_graphics_commands(ReadonlyBytes);
|
static PDFErrorOr<Vector<Command>> parse_graphics_commands(Document*, ReadonlyBytes);
|
||||||
|
|
||||||
Parser(Badge<Document>, ReadonlyBytes);
|
Parser(Document*, ReadonlyBytes);
|
||||||
|
|
||||||
[[nodiscard]] ALWAYS_INLINE RefPtr<DictObject> const& trailer() const { return m_trailer; }
|
[[nodiscard]] ALWAYS_INLINE RefPtr<DictObject> const& trailer() const { return m_trailer; }
|
||||||
void set_document(WeakPtr<Document> const&);
|
void set_document(WeakPtr<Document> const&);
|
||||||
|
|
|
@ -77,7 +77,7 @@ PDFErrorOr<void> Renderer::render()
|
||||||
byte_buffer.append(bytes.data(), bytes.size());
|
byte_buffer.append(bytes.data(), bytes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto commands = TRY(Parser::parse_graphics_commands(byte_buffer));
|
auto commands = TRY(Parser::parse_graphics_commands(m_document, byte_buffer));
|
||||||
|
|
||||||
for (auto& command : commands)
|
for (auto& command : commands)
|
||||||
TRY(handle_command(command));
|
TRY(handle_command(command));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue