10 #include "PdfVariant.h"
11 #include "PdfObjectStream.h"
16 class PdfIndirectObjectList;
20 class PdfDataContainer;
41 friend class PdfObjectOutputStream;
43 friend class PdfDictionaryElement;
44 friend class PdfArrayElement;
46 PODOFO_PRIVATE_FRIEND(
class PdfStreamedObjectStream);
47 PODOFO_PRIVATE_FRIEND(
class PdfObjectStreamParser);
48 PODOFO_PRIVATE_FRIEND(
class PdfParser);
49 PODOFO_PRIVATE_FRIEND(
class PdfParserObject);
50 PODOFO_PRIVATE_FRIEND(
class PdfWriter);
51 PODOFO_PRIVATE_FRIEND(
class PdfImmediateWriter);
52 PODOFO_PRIVATE_FRIEND(
class PdfXRef);
53 PODOFO_PRIVATE_FRIEND(
class PdfXRefStream);
143 std::string_view GetDataTypeString()
const;
151 bool IsNumber()
const;
157 bool IsRealStrict()
const;
161 bool IsNumberOrReal()
const;
165 bool IsString()
const;
173 bool IsArray()
const;
177 bool IsDictionary()
const;
181 bool IsRawData()
const;
189 bool IsReference()
const;
195 std::string ToString(
PdfWriteFlags writeFlags = PdfWriteFlags::None)
const;
196 void ToString(std::string& str,
PdfWriteFlags writeFlags = PdfWriteFlags::None)
const;
201 bool GetBool()
const;
202 bool TryGetBool(
bool& value)
const;
209 int64_t GetNumberLenient()
const;
210 bool TryGetNumberLenient(int64_t& value)
const;
217 int64_t GetNumber()
const;
218 bool TryGetNumber(int64_t& value)
const;
225 double GetReal()
const;
226 bool TryGetReal(
double& value)
const;
233 double GetRealStrict()
const;
234 bool TryGetRealStrict(
double& value)
const;
240 bool TryGetString(
const PdfString*& str)
const;
244 const PdfName& GetName()
const;
245 bool TryGetName(
PdfName& name)
const;
246 bool TryGetName(
const PdfName*& name)
const;
259 bool TryGetArray(
const PdfArray*& arr)
const;
276 void SetBool(
bool b);
284 void SetNumber(int64_t l);
292 void SetReal(
double d);
300 void SetName(
const PdfName& name);
312 void ForceCreateStream();
323 const PdfStatefulEncrypt* encrypt,
charbuff& buffer)
const;
353 virtual bool TryUnload();
360 bool HasStream()
const;
362 bool IsIndirect()
const;
371 bool operator<(
const PdfObject& rhs)
const;
376 bool operator==(
const PdfObject& rhs)
const;
381 bool operator!=(
const PdfObject& rhs)
const;
414 inline bool IsDirty()
const {
return m_IsDirty; }
440 inline bool IsDelayedLoadStreamDone()
const {
return m_IsDelayedLoadStreamDone; }
442 const PdfObjectStream* GetStream()
const;
443 PdfObjectStream* GetStream();
446 PdfObject(PdfVariant&& var,
const PdfReference& indirectReference,
bool isDirty);
457 void DelayedLoad()
const;
473 virtual void delayedLoad();
475 virtual void delayedLoadStream();
480 virtual bool removeStream();
482 virtual bool HasStreamToParse()
const;
497 void SetDocument(PdfDocument* document);
499 void SetVariantOwner();
503 PdfObjectStream& getOrCreateStream();
505 void forceCreateStream();
507 PdfObjectStream* getStream();
509 void DelayedLoadStream()
const;
511 void delayedLoadStream()
const;
513 void EnableDelayedLoadingStream();
515 inline void SetIndirectReference(
const PdfReference& reference) { m_IndirectReference = reference; }
525 void EnableDelayedLoading();
530 virtual void SetRevised();
534 PdfVariant& GetVariantUnsafe() {
return m_Variant; }
535 PdfReference GetReferenceUnsafe()
const {
return m_Variant.GetReferenceUnsafe(); }
536 const PdfDictionary& GetDictionaryUnsafe()
const {
return m_Variant.GetDictionaryUnsafe(); }
537 const PdfArray& GetArrayUnsafe()
const {
return m_Variant.GetArrayUnsafe(); }
538 PdfDictionary& GetDictionaryUnsafe() {
return m_Variant.GetDictionaryUnsafe(); }
539 PdfArray& GetArrayUnsafe() {
return m_Variant.GetArrayUnsafe(); }
540 void WriteFinal(OutputStream& stream,
PdfWriteFlags writeMode,
541 const PdfStatefulEncrypt* encrypt, charbuff& buffer);
544 void SetNumberNoDirtySet(int64_t l);
548 void WriteHeader(OutputStream& stream,
PdfWriteFlags writeMode, charbuff& buffer)
const;
551 bool IsImmutable()
const {
return m_IsImmutable; }
554 void AssignNoDirtySet(PdfObject&& rhs);
555 void AssignNoDirtySet(PdfVariant&& rhs);
556 void AssignNoDirtySet(
const PdfObject& rhs);
558 void SetParent(PdfDataContainer& parent);
561 void write(OutputStream& stream,
bool skipLengthFix,
562 PdfWriteFlags writeMode,
const PdfStatefulEncrypt* encrypt, charbuff& buffer)
const;
564 void assertMutable()
const;
566 void assign(
const PdfObject& rhs);
568 void moveFrom(PdfObject&& rhs);
578 PdfObject(T*) =
delete;
580 void copyStreamFrom(
const PdfObject& obj);
582 void moveStreamFrom(PdfObject& obj);
588 PdfVariant m_Variant;
591 PdfReference m_IndirectReference;
592 PdfDocument* m_Document;
593 PdfDataContainer* m_Parent;
594 std::unique_ptr<PdfObjectStream> m_Stream;
597 mutable bool m_IsDelayedLoadDone;
598 mutable bool m_IsDelayedLoadStreamDone;
605 template <
typename T>
611 static_assert(always_false<T>,
"Unsupported type");
615 static bool TryGet(
const PdfObject& obj, T& value)
619 static_assert(always_false<T>,
"Unsupported type");
632 static bool TryGet(
const PdfObject& obj,
bool& value)
634 return obj.TryGetBool(value);
639 struct Object<int64_t>
641 static int64_t Get(
const PdfObject& obj)
643 return obj.GetNumber();
646 static bool TryGet(
const PdfObject& obj, int64_t& value)
648 return obj.TryGetNumber(value);
653 struct Object<double>
655 static double Get(
const PdfObject& obj)
657 return obj.GetReal();
660 static bool TryGet(
const PdfObject& obj,
double& value)
662 return obj.TryGetReal(value);
667 struct Object<PdfReference>
669 static PdfReference Get(
const PdfObject& obj)
671 return obj.GetReference();
674 static bool TryGet(
const PdfObject& obj, PdfReference& value)
676 return obj.TryGetReference(value);
681 struct Object<PdfName>
683 static PdfName Get(
const PdfObject& obj)
685 return obj.GetName();
688 static bool TryGet(
const PdfObject& obj, PdfName& value)
690 return obj.TryGetName(value);
695 struct Object<const PdfName*>
697 static const PdfName* Get(
const PdfObject& obj)
699 return &obj.GetName();
702 static bool TryGet(
const PdfObject& obj,
const PdfName*& value)
704 return obj.TryGetName(value);
709 struct Object<PdfString>
711 static PdfString Get(
const PdfObject& obj)
713 return obj.GetString();
716 static bool TryGet(
const PdfObject& obj, PdfString& value)
718 return obj.TryGetString(value);
723 struct Object<const PdfString*>
725 static const PdfString* Get(
const PdfObject& obj)
727 return &obj.GetString();
730 static bool TryGet(
const PdfObject& obj,
const PdfString*& value)
732 return obj.TryGetString(value);
737 struct Object<const PdfDictionary*>
739 static const PdfDictionary* Get(
const PdfObject& obj)
741 return &obj.GetDictionary();
744 static bool TryGet(
const PdfObject& obj,
const PdfDictionary*& value)
746 return obj.TryGetDictionary(value);
751 struct Object<PdfDictionary*>
753 static PdfDictionary* Get(PdfObject& obj)
755 return &obj.GetDictionary();
758 static bool TryGet(PdfObject& obj, PdfDictionary*& value)
760 return obj.TryGetDictionary(value);
765 struct Object<const PdfArray*>
767 static const PdfArray* Get(
const PdfObject& obj)
769 return &obj.GetArray();
772 static bool TryGet(
const PdfObject& obj,
const PdfArray*& value)
774 return obj.TryGetArray(value);
779 struct Object<PdfArray*>
781 static PdfArray* Get(PdfObject& obj)
783 return &obj.GetArray();
786 static bool TryGet(PdfObject& obj, PdfArray*& value)
788 return obj.TryGetArray(value);
795 struct PODOFO_API PdfObjectInequality final
797 using is_transparent = std::true_type;
799 bool operator()(
const PdfObject* lhs,
const PdfObject* rhs)
const
801 return lhs->GetIndirectReference() < rhs->GetIndirectReference();
803 bool operator()(
const PdfObject* lhs,
const PdfReference& rhs)
const
805 return lhs->GetIndirectReference() < rhs;
807 bool operator()(
const PdfReference& lhs,
const PdfObject* rhs)
const
809 return lhs < rhs->GetIndirectReference();
811 bool operator()(
const PdfObject& lhs,
const PdfObject& rhs)
const
813 return lhs.GetIndirectReference() < rhs.GetIndirectReference();
815 bool operator()(
const PdfObject& lhs,
const PdfReference& rhs)
const
817 return lhs.GetIndirectReference() < rhs;
819 bool operator()(
const PdfReference& lhs,
const PdfObject& rhs)
const
821 return lhs < rhs.GetIndirectReference();
An interface for writing blocks of data to a data source.
Definition: OutputStream.h:18
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition: PdfArray.h:81
A PdfDataProvider object with a PdfObject owner, specialized in holding objects.
Definition: PdfDataContainer.h:22
The PDF dictionary data type of PoDoFo (inherits from PdfDataContainer, the base class for such repre...
Definition: PdfDictionary.h:82
PdfDocument is the core interface for working with PDF documents.
Definition: PdfDocument.h:108
A list of PdfObjects that constitutes the indirect object list of the document The PdfParser will rea...
Definition: PdfIndirectObjectList.h:30
This class represents a PdfName.
Definition: PdfName.h:24
A PDF stream can be appended to any PdfObject and can contain arbitrary data.
Definition: PdfObjectStream.h:87
This class represents a PDF indirect Object in memory.
Definition: PdfObject.h:35
const PdfReference & GetIndirectReference() const
Get an indirect reference to this object.
Definition: PdfObject.h:429
PdfDocument * GetDocument() const
Get the document of this object.
Definition: PdfObject.h:419
bool IsDelayedLoadDone() const
Returns true if delayed loading is disabled, or if it is enabled and loading has completed.
Definition: PdfObject.h:438
PdfObject(std::nullptr_t)
Create a "null" PDF object.
bool IsDirty() const
The dirty flag is set if this variant has been modified after construction.
Definition: PdfObject.h:414
bool GetBool() const
Get the value if this object is a bool.
Definition: PdfObject.cpp:641
A reference is a pointer to a object in the PDF file of the form "4 0 R", where 4 is the object numbe...
Definition: PdfReference.h:24
A string that can be written to a PDF document.
Definition: PdfString.h:24
A simple tokenizer for PDF files and PDF content streams.
Definition: PdfTokenizer.h:53
A variant data type which supports all data types supported by the PDF standard.
Definition: PdfVariant.h:33
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition: basetypes.h:38
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition: basetypes.h:16
PdfDataType
Every PDF datatype that can occur in a PDF file is referenced by an own enum (e.g.
Definition: PdfDeclarations.h:155
@ Null
The null datatype is always null.
PdfWriteFlags
Specify additional options for writing the PDF.
Definition: PdfDeclarations.h:137
Templatized object type getter helper.
Definition: PdfObject.h:607