/* * Copyright (c) 2021-2022, Matthew Olsson * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace PDF { template static NonnullRefPtr make_object(Args... args) requires(IsBaseOf) { return adopt_ref(*new T(forward(args)...)); } class Document; class Parser { public: static PDFErrorOr> parse_operators(Document*, ReadonlyBytes); Parser(ReadonlyBytes); Parser(Document*, ReadonlyBytes); void set_document(WeakPtr const&); DeprecatedString parse_comment(); void move_by(size_t count) { m_reader.move_by(count); } void move_to(size_t offset) { m_reader.move_to(offset); } enum class CanBeIndirectValue { No, Yes }; PDFErrorOr parse_value(CanBeIndirectValue = CanBeIndirectValue::Yes); PDFErrorOr parse_possible_indirect_value_or_ref(); PDFErrorOr> parse_indirect_value(u32 index, u32 generation); PDFErrorOr> parse_indirect_value(); PDFErrorOr parse_number(); PDFErrorOr> parse_name(); NonnullRefPtr parse_string(); DeprecatedString parse_literal_string(); DeprecatedString parse_hex_string(); PDFErrorOr> parse_array(); PDFErrorOr> parse_dict(); PDFErrorOr> parse_stream(NonnullRefPtr dict); PDFErrorOr> parse_operators(); protected: void push_reference(Reference const& ref) { m_current_reference_stack.append(ref); } void pop_reference() { m_current_reference_stack.take_last(); } Error error( DeprecatedString const& message #ifdef PDF_DEBUG , SourceLocation loc = SourceLocation::current() #endif ) const; Reader m_reader; WeakPtr m_document; Vector m_current_reference_stack; bool m_disable_encryption { false }; }; };