PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfXObject.h
1// SPDX-FileCopyrightText: 2006 Dominik Seichter <domseichter@web.de>
2// SPDX-FileCopyrightText: 2020 Francesco Pretto <ceztko@gmail.com>
3// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
4
5#ifndef PDF_XOBJECT_H
6#define PDF_XOBJECT_H
7
8#include "PdfElement.h"
9#include "PdfArray.h"
10#include <podofo/auxiliary/Matrix.h>
11#include <podofo/auxiliary/Rect.h>
12
13namespace PoDoFo {
14
15class PdfImage;
16class PdfXObjectForm;
17class PdfXObjectPostScript;
18class PdfAnnotation;
19
27class PODOFO_API PdfXObject : public PdfDictionaryElement
28{
29 friend class PdfXObjectForm;
30 friend class PdfImage;
31 friend class PdfXObjectPostScript;
32 friend class PdfContentStreamReader;
33 friend class PdfAnnotation;
34
35private:
36 PdfXObject(PdfDocument& doc, PdfXObjectType subType);
37 PdfXObject(PdfObject& obj, PdfXObjectType subType);
38
39public:
40 static bool TryCreateFromObject(PdfObject& obj, std::unique_ptr<PdfXObject>& xobj);
41
42 static bool TryCreateFromObject(const PdfObject& obj, std::unique_ptr<const PdfXObject>& xobj);
43
44 template <typename XObjectT>
45 static bool TryCreateFromObject(PdfObject& obj, std::unique_ptr<XObjectT>& xobj);
46
47 template <typename XObjectT>
48 static bool TryCreateFromObject(const PdfObject& obj, std::unique_ptr<const XObjectT>& xobj);
49
50 virtual Rect GetRect() const = 0;
51
52 virtual const Matrix& GetMatrix() const;
53
54 inline PdfXObjectType GetType() const { return m_Type; }
55
56protected:
57 virtual PdfXObjectForm* getForm() const;
58
59private:
60 // To be called from PdfContentStreamReader
61 static std::unique_ptr<PdfXObject> CreateFromObject(const PdfObject& obj, PdfXObjectType reqType, PdfXObjectType& detectedType);
62
63 static PdfXObject* createFromObject(const PdfObject& obj, PdfXObjectType reqType, PdfXObjectType& detectedType);
64 template <typename TXObject>
65 static constexpr PdfXObjectType GetXObjectType();
66
67 PdfXObjectForm* GetForm() { return getForm(); }
68
69 const PdfXObjectForm* GetForm() const { return getForm(); }
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:68
Reader class to read content streams.
Definition PdfContentStreamReader.h:123
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:108
A PdfImage object is needed when ever you want to embed an image file into a PDF document.
Definition PdfImage.h:68
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:31
A XObject is a content stream with several drawing commands and data which can be used throughout a P...
Definition PdfXObject.h:28
An normalized rectangle defined by position (left-bottom) and size.
Definition Rect.h:17
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:30
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13