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