PoDoFo 1.0.0-dev
Loading...
Searching...
No Matches
PdfXObject.h
1
7#ifndef PDF_XOBJECT_H
8#define PDF_XOBJECT_H
9
10#include "PdfElement.h"
11#include "PdfArray.h"
12#include <podofo/auxiliary/Matrix.h>
13#include <podofo/auxiliary/Rect.h>
14
15namespace PoDoFo {
16
17class PdfImage;
18class PdfXObjectForm;
19class PdfXObjectPostScript;
20class PdfAnnotation;
21
30class PODOFO_API PdfXObject : public PdfDictionaryElement
31{
32 friend class PdfXObjectForm;
33 friend class PdfImage;
34 friend class PdfXObjectPostScript;
35 friend class PdfContentStreamReader;
36 friend class PdfAnnotation;
37
38private:
39 PdfXObject(PdfDocument& doc, PdfXObjectType subType);
40 PdfXObject(PdfObject& obj, PdfXObjectType subType);
41
42public:
43 static bool TryCreateFromObject(PdfObject& obj, std::unique_ptr<PdfXObject>& xobj);
44
45 static bool TryCreateFromObject(const PdfObject& obj, std::unique_ptr<const PdfXObject>& xobj);
46
47 template <typename XObjectT>
48 static bool TryCreateFromObject(PdfObject& obj, std::unique_ptr<XObjectT>& xobj);
49
50 template <typename XObjectT>
51 static bool TryCreateFromObject(const PdfObject& obj, std::unique_ptr<const XObjectT>& xobj);
52
53 virtual Rect GetRect() const = 0;
54
55 virtual const Matrix& GetMatrix() const;
56
57 inline PdfXObjectType GetType() const { return m_Type; }
58
59protected:
60 virtual const PdfXObjectForm* GetForm() const;
61
62private:
63 // To be called from PdfContentStreamReader
64 static std::unique_ptr<PdfXObject> CreateFromObject(const PdfObject& obj, PdfXObjectType reqType, PdfXObjectType& detectedType);
65
66 static PdfXObject* createFromObject(const PdfObject& obj, PdfXObjectType reqType, PdfXObjectType& detectedType);
67 static PdfXObjectType getPdfXObjectType(const PdfObject& obj);
68 template <typename TXObject>
69 static constexpr PdfXObjectType GetXObjectType();
70
71private:
72 PdfXObjectType m_Type;
73};
74
75template<typename XObjectT>
76inline bool PdfXObject::TryCreateFromObject(PdfObject& obj, std::unique_ptr<XObjectT>& xobj)
77{
78 PdfXObjectType detectedType;
79 xobj.reset((XObjectT*)createFromObject(obj, GetXObjectType<XObjectT>(), detectedType));
80 return xobj != nullptr;
81}
82
83template<typename XObjectT>
84inline bool PdfXObject::TryCreateFromObject(const PdfObject& obj, std::unique_ptr<const XObjectT>& xobj)
85{
86 PdfXObjectType detectedType;
87 xobj.reset((const XObjectT*)createFromObject(obj, GetXObjectType<XObjectT>(), detectedType));
88 return xobj != nullptr;
89}
90
91template<typename TXObject>
92constexpr PdfXObjectType PdfXObject::GetXObjectType()
93{
94 if (std::is_same_v<TXObject, PdfXObjectForm>)
95 return PdfXObjectType::Form;
96 else if (std::is_same_v<TXObject, PdfImage>)
97 return PdfXObjectType::Image;
98 else if (std::is_same_v<TXObject, PdfXObjectPostScript>)
99 return PdfXObjectType::PostScript;
100 else
101 return PdfXObjectType::Unknown;
102}
103
104};
105
106#endif // PDF_XOBJECT_H
107
108
An annotation to a PdfPage To create an annotation use PdfPage::CreateAnnotation.
Definition PdfAnnotation.h:63
Reader class to read content streams.
Definition PdfContentStreamReader.h:82
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:111
A PdfImage object is needed when ever you want to embed an image file into a PDF document.
Definition PdfImage.h:78
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:35
A XObject is a content stream with several drawing commands and data which can be used throughout a P...
Definition PdfXObject.h:31
An normalized rectangle defined by position (left-bottom) and size.
Definition Rect.h:20
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