ladybird/Userland/Libraries/LibPDF/Forward.h
Matthew Olsson 8c745ad0d9 LibPDF: Parse page structures
This commit introduces the ability to parse the document catalog dict,
as well as the page tree and individual pages. Pages obviously aren't
fully parsed, as we won't care about most of the fields until we
start actually rendering PDFs.

One of the primary benefits of the PDF format is laziness. PDFs are
not meant to be parsed all at once, and the same is true for pages.
When a Document is constructed, it builds a map of page number to
object index, but it does not fetch and parse any of the pages. A page
is only parsed when a caller requests that particular page (and is
cached going forwards).

Additionally, this commit also adds an object_cast function which
logs bad casts if DEBUG_PDF is set. Additionally, utility functions
were added to ArrayObject and DictObject to get all types of objects
from the collections to avoid having to manually cast.
2021-05-10 10:32:39 +02:00

42 lines
1 KiB
C++

/*
* Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
namespace PDF {
class Document;
class Object;
#define ENUMERATE_DIRECT_OBJECT_TYPES(V) \
V(StringObject, string) \
V(NameObject, name) \
V(ArrayObject, array) \
V(DictObject, dict) \
V(StreamObject, stream) \
V(IndirectValue, indirect_value)
#define ENUMERATE_OBJECT_TYPES(V) \
ENUMERATE_DIRECT_OBJECT_TYPES(V) \
V(IndirectValueRef, indirect_value_ref)
#define FORWARD_DECL(class_name, _) class class_name;
ENUMERATE_OBJECT_TYPES(FORWARD_DECL)
#undef FORWARD_DECL
template<typename T>
concept IsObject = IsBaseOf<Object, T>;
template<typename T>
concept IsValuePrimitive = IsSame<T, bool> || IsSame<T, int> || IsSame<T, float>;
template<typename T>
concept IsValueType = IsValuePrimitive<T> || IsObject<T>;
template<IsValueType T>
using UnwrappedValueType = Conditional<IsObject<T>, NonnullRefPtr<T>, T>;
}