PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfColor.h
1// SPDX-FileCopyrightText: 2005 Dominik Seichter <domseichter@web.de>
2// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
3
4#ifndef PDF_COLOR_H
5#define PDF_COLOR_H
6
7#include "PdfName.h"
8#include "PdfArray.h"
9
10namespace PoDoFo {
11
12using PdfColorRaw = std::array<double, 6>;
13
19class PODOFO_API PdfColor final
20{
21public:
23 PdfColor();
24
29 explicit PdfColor(double gray);
30
37 PdfColor(double red, double green, double blue);
38
46 PdfColor(double cyan, double magenta, double yellow, double black);
47
51 PdfColor(const PdfColor& rhs) = default;
52
53public:
59 static bool TryCreateFromObject(const PdfObject& obj, PdfColor& color);
60 static PdfColor CreateFromObject(const PdfObject& obj);
61
62 static PdfColor CreateTransparent();
63
64public:
68 bool IsGrayScale() const;
69
73 bool IsRGB() const;
74
78 bool IsCMYK() const;
79
80 bool IsTransparent() const;
81
85 inline PdfColorSpaceType GetColorSpace() const { return m_ColorSpace; }
86
95 double GetGrayScale() const;
96
105 double GetRed() const;
106
115 double GetGreen() const;
116
125 double GetBlue() const;
126
135 double GetCyan() const;
136
145 double GetMagenta() const;
146
155 double GetYellow() const;
156
165 double GetBlack() const;
166
176 PdfColor ConvertToGrayScale() const;
177
187 PdfColor ConvertToRGB() const;
188
198 PdfColor ConvertToCMYK() const;
199
202 PdfArray ToArray() const;
203
215 static PdfColor CreateFromString(const std::string_view& name);
216
217public:
218 unsigned char GetComponentCount() const { return m_ComponentCount; }
219
220 const PdfColorRaw& GetRawColor() const { return m_RawColor; }
221
227 PdfColor& operator=(const PdfColor& rhs) = default;
228
234 bool operator==(const PdfColor& rhs) const;
235
241 bool operator!=(const PdfColor& rhs) const;
242
243private:
244 PdfColor(bool isTransparent, PdfColorSpaceType colorSpace, unsigned char componentCount, const PdfColorRaw& data);
245
246 static bool tryCreateFromArray(const PdfArray& arr, PdfColor& color);
247
248private:
249 bool m_IsTransparent;
250 PdfColorSpaceType m_ColorSpace;
251 unsigned char m_ComponentCount;
252 PdfColorRaw m_RawColor;
253};
254
255};
256
257#endif // PDF_COLOR_H
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition PdfArray.h:76
A color object can represent either a grayscale value, a RGB color, a CMYK color.
Definition PdfColor.h:20
PdfColor & operator=(const PdfColor &rhs)=default
Assignment operator.
PdfColor(const PdfColor &rhs)=default
Copy constructor.
PdfColorSpaceType GetColorSpace() const
Get the colorspace of this PdfColor object.
Definition PdfColor.h:85
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:31
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
PdfColorSpaceType
Enum for the colorspaces supported by PDF.
Definition PdfDeclarations.h:333