/src/serenity/Userland/Libraries/LibPDF/Parser.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021-2022, Matthew Olsson <mattco@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/SourceLocation.h> |
10 | | #include <AK/WeakPtr.h> |
11 | | #include <LibPDF/Object.h> |
12 | | #include <LibPDF/Operator.h> |
13 | | #include <LibPDF/Reader.h> |
14 | | #include <LibPDF/XRefTable.h> |
15 | | |
16 | | namespace PDF { |
17 | | |
18 | | template<typename T, typename... Args> |
19 | | NonnullRefPtr<T> make_object(Args... args) |
20 | | requires(IsBaseOf<Object, T>) |
21 | 81 | { |
22 | 81 | return adopt_ref(*new T(forward<Args>(args)...)); |
23 | 81 | } AK::NonnullRefPtr<PDF::DictObject> PDF::make_object<PDF::DictObject, AK::HashMap<AK::DeprecatedFlyString, PDF::Value, AK::Traits<AK::DeprecatedFlyString>, AK::Traits<PDF::Value>, false> >(AK::HashMap<AK::DeprecatedFlyString, PDF::Value, AK::Traits<AK::DeprecatedFlyString>, AK::Traits<PDF::Value>, false>) requires IsBaseOf<PDF::Object, PDF::DictObject> Line | Count | Source | 21 | 10 | { | 22 | 10 | return adopt_ref(*new T(forward<Args>(args)...)); | 23 | 10 | } |
AK::NonnullRefPtr<PDF::IndirectValue> PDF::make_object<PDF::IndirectValue, unsigned int, unsigned int, PDF::Value>(unsigned int, unsigned int, PDF::Value) requires IsBaseOf<PDF::Object, PDF::IndirectValue> Line | Count | Source | 21 | 8 | { | 22 | 8 | return adopt_ref(*new T(forward<Args>(args)...)); | 23 | 8 | } |
AK::NonnullRefPtr<PDF::NameObject> PDF::make_object<PDF::NameObject, AK::ByteString>(AK::ByteString) requires IsBaseOf<PDF::Object, PDF::NameObject> Line | Count | Source | 21 | 58 | { | 22 | 58 | return adopt_ref(*new T(forward<Args>(args)...)); | 23 | 58 | } |
Unexecuted instantiation: AK::NonnullRefPtr<PDF::StringObject> PDF::make_object<PDF::StringObject, AK::ByteString, bool>(AK::ByteString, bool) requires IsBaseOf<PDF::Object, PDF::StringObject> AK::NonnullRefPtr<PDF::ArrayObject> PDF::make_object<PDF::ArrayObject, AK::Vector<PDF::Value, 0ul> >(AK::Vector<PDF::Value, 0ul>) requires IsBaseOf<PDF::Object, PDF::ArrayObject> Line | Count | Source | 21 | 5 | { | 22 | 5 | return adopt_ref(*new T(forward<Args>(args)...)); | 23 | 5 | } |
Unexecuted instantiation: AK::NonnullRefPtr<PDF::StreamObject> PDF::make_object<PDF::StreamObject, AK::NonnullRefPtr<PDF::DictObject>, AK::Detail::ByteBuffer<32ul> >(AK::NonnullRefPtr<PDF::DictObject>, AK::Detail::ByteBuffer<32ul>) requires IsBaseOf<PDF::Object, PDF::StreamObject> |
24 | | |
25 | | class Document; |
26 | | |
27 | | class Parser { |
28 | | public: |
29 | | static PDFErrorOr<Vector<Operator>> parse_operators(Document*, ReadonlyBytes); |
30 | | |
31 | | Parser(ReadonlyBytes); |
32 | | Parser(Document*, ReadonlyBytes); |
33 | | |
34 | | void set_document(WeakPtr<Document> const&); |
35 | | |
36 | | ByteString parse_comment(); |
37 | 0 | void consume_whitespace() { m_reader.consume_whitespace(); } |
38 | | |
39 | 0 | void move_by(size_t count) { m_reader.move_by(count); } |
40 | 0 | void move_to(size_t offset) { m_reader.move_to(offset); } |
41 | | |
42 | | enum class CanBeIndirectValue { |
43 | | No, |
44 | | Yes |
45 | | }; |
46 | | |
47 | | PDFErrorOr<Value> parse_value(CanBeIndirectValue = CanBeIndirectValue::Yes); |
48 | | PDFErrorOr<Value> parse_possible_indirect_value_or_ref(); |
49 | | PDFErrorOr<NonnullRefPtr<IndirectValue>> parse_indirect_value(u32 index, u32 generation); |
50 | | PDFErrorOr<NonnullRefPtr<IndirectValue>> parse_indirect_value(); |
51 | | PDFErrorOr<Value> parse_number(); |
52 | | PDFErrorOr<NonnullRefPtr<NameObject>> parse_name(); |
53 | | PDFErrorOr<NonnullRefPtr<StringObject>> parse_string(); |
54 | | PDFErrorOr<ByteString> parse_literal_string(); |
55 | | PDFErrorOr<ByteString> parse_hex_string(); |
56 | | PDFErrorOr<NonnullRefPtr<ArrayObject>> parse_array(); |
57 | | PDFErrorOr<HashMap<DeprecatedFlyString, Value>> parse_dict_contents_until(char const*); |
58 | | PDFErrorOr<NonnullRefPtr<DictObject>> parse_dict(); |
59 | | PDFErrorOr<void> unfilter_stream(NonnullRefPtr<StreamObject>); |
60 | | PDFErrorOr<NonnullRefPtr<StreamObject>> parse_stream(NonnullRefPtr<DictObject> dict); |
61 | | PDFErrorOr<Vector<Operator>> parse_operators(); |
62 | | |
63 | | void set_filters_enabled(bool enabled) |
64 | 22 | { |
65 | 22 | m_enable_filters = enabled; |
66 | 22 | } |
67 | | |
68 | | void set_encryption_enabled(bool enabled) |
69 | 0 | { |
70 | 0 | m_enable_encryption = enabled; |
71 | 0 | } |
72 | | |
73 | 9 | void push_reference(Reference const& ref) { m_current_reference_stack.append(ref); } |
74 | 8 | void pop_reference() { m_current_reference_stack.take_last(); } |
75 | | |
76 | | protected: |
77 | | PDFErrorOr<NonnullRefPtr<StreamObject>> parse_inline_image(); |
78 | | |
79 | | Error error( |
80 | | ByteString const& message |
81 | | #ifdef PDF_DEBUG |
82 | | , |
83 | | SourceLocation loc = SourceLocation::current() |
84 | | #endif |
85 | | ) const; |
86 | | |
87 | | Reader m_reader; |
88 | | WeakPtr<Document> m_document; |
89 | | Vector<Reference> m_current_reference_stack; |
90 | | bool m_enable_encryption { true }; |
91 | | bool m_enable_filters { true }; |
92 | | }; |
93 | | |
94 | | }; |