mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:37:35 +00:00
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.
This commit is contained in:
parent
a8f5b6aaa3
commit
72f693e9ed
7 changed files with 1008 additions and 0 deletions
42
Userland/Libraries/LibPDF/Document.h
Normal file
42
Userland/Libraries/LibPDF/Document.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue