1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 12:17:35 +00:00

LibPDF: Refine the distinction between the Document and Parser

The Parser should hold information relevant for parsing, whereas the
Document should hold information relevant for displaying pages.
With this in mind, there is no reason for the Document to hold the
xref table and trailer. These objects have been moved to the Parser,
which allows the Parser to expose less public methods (which will be
even more evident once linearized PDFs are supported).
This commit is contained in:
Matthew Olsson 2021-05-25 08:55:15 -07:00 committed by Ali Mohammad Pur
parent 69410d7f4e
commit 78bc9d1539
4 changed files with 43 additions and 56 deletions

View file

@ -22,19 +22,19 @@ public:
Parser(Badge<Document>, const ReadonlyBytes&);
void set_document(RefPtr<Document> document) { m_document = document; }
[[nodiscard]] ALWAYS_INLINE const RefPtr<DictObject>& trailer() const { return m_trailer; }
void set_document(const RefPtr<Document>& document) { m_document = document; }
bool perform_validation();
// Parses the header and initializes the xref table and trailer
bool initialize();
struct XRefTableAndTrailer {
XRefTable xref_table;
NonnullRefPtr<DictObject> trailer;
};
Optional<XRefTableAndTrailer> parse_last_xref_table_and_trailer();
Value parse_object_with_index(u32 index);
RefPtr<IndirectValue> parse_indirect_value_at_offset(size_t offset);
RefPtr<DictObject> conditionally_parse_page_tree_node_at_offset(size_t offset, bool& ok);
// Specialized version of parse_dict which aborts early if the dict being parsed
// is not a page object. A null RefPtr return indicates that the dict at this index
// is not a page tree node, whereas ok == false indicates a malformed PDF file and
// should cause an abort of the current operation.
RefPtr<DictObject> conditionally_parse_page_tree_node(u32 object_index, bool& ok);
private:
explicit Parser(const ReadonlyBytes&);
@ -85,6 +85,8 @@ private:
Reader m_reader;
RefPtr<Document> m_document;
XRefTable m_xref_table;
RefPtr<DictObject> m_trailer;
};
}