PoDoFo 1.1.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
20class PODOFO_API PdfColor final
21{
22public:
25 PdfColor();
26
32 explicit PdfColor(double gray);
33
41 PdfColor(double red, double green, double blue);
42
51 PdfColor(double cyan, double magenta, double yellow, double black);
52
57 PdfColor(const PdfColor& rhs) = default;
58
59public:
64 static bool TryCreateFromObject(const PdfObject& obj, PdfColor& color);
65 static PdfColor CreateFromObject(const PdfObject& obj);
66
67 static PdfColor CreateTransparent();
68
69public:
74 bool IsGrayScale() const;
75
80 bool IsRGB() const;
81
86 bool IsCMYK() const;
87
88 bool IsTransparent() const;
89
94 inline PdfColorSpaceType GetColorSpace() const { return m_ColorSpace; }
95
105 double GetGrayScale() const;
106
116 double GetRed() const;
117
127 double GetGreen() const;
128
138 double GetBlue() const;
139
149 double GetCyan() const;
150
160 double GetMagenta() const;
161
171 double GetYellow() const;
172
182 double GetBlack() const;
183
194 PdfColor ConvertToGrayScale() const;
195
206 PdfColor ConvertToRGB() const;
207
218 PdfColor ConvertToCMYK() const;
219
223 PdfArray ToArray() const;
224
237 static PdfColor CreateFromString(const std::string_view& name);
238
239public:
240 unsigned char GetComponentCount() const { return m_ComponentCount; }
241
242 const PdfColorRaw& GetRawColor() const { return m_RawColor; }
243
250 PdfColor& operator=(const PdfColor& rhs) = default;
251
258 bool operator==(const PdfColor& rhs) const;
259
266 bool operator!=(const PdfColor& rhs) const;
267
268private:
269 PdfColor(bool isTransparent, PdfColorSpaceType colorSpace, unsigned char componentCount, const PdfColorRaw& data);
270
271 static bool tryCreateFromArray(const PdfArray& arr, PdfColor& color);
272
273private:
274 bool m_IsTransparent;
275 PdfColorSpaceType m_ColorSpace;
276 unsigned char m_ComponentCount;
277 PdfColorRaw m_RawColor;
278};
279
280};
281
282#endif // PDF_COLOR_H
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition PdfArray.h:79
A color object can represent either a grayscale value, a RGB color, a CMYK color.
Definition PdfColor.h:21
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:94
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:33
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
PdfColorSpaceType
Enum for the colorspaces supported by PDF.
Definition PdfDeclarations.h:357