1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:58:12 +00:00
serenity/Userland/Libraries/LibPDF/Document.h
Matthew Olsson 72f693e9ed LibPDF: Add a basic parser and Document structure
This commit adds a parser as well as the Reader class, which serves
as a utility to aid in reading the PDF both forwards and in reverse.
The parser currently is capable of reading xref tables, as well as
all values. We don't really do anything with any of this information,
however.
2021-05-10 10:32:39 +02:00

42 lines
925 B
C++

/*
* Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/RefCounted.h>
#include <LibPDF/Object.h>
#include <LibPDF/Parser.h>
#include <LibPDF/XRefTable.h>
namespace PDF {
class Document final : public RefCounted<Document> {
public:
explicit Document(const ReadonlyBytes& bytes);
ALWAYS_INLINE const XRefTable& xref_table() const { return m_xref_table; }
ALWAYS_INLINE const DictObject& trailer() const { return *m_trailer; }
ALWAYS_INLINE Value get_value(u32 index) const
{
return m_values.get(index).value_or({});
}
ALWAYS_INLINE void set_value(u32 index, const Value& value)
{
m_values.ensure_capacity(index);
m_values.set(index, value);
}
private:
Parser m_parser;
XRefTable m_xref_table;
RefPtr<DictObject> m_trailer;
HashMap<u32, Value> m_values;
};
}