PoDoFo  1.0.0-dev
PdfColor.h
1 
6 #ifndef PDF_COLOR_H
7 #define PDF_COLOR_H
8 
9 #include "PdfDeclarations.h"
10 
11 #include "PdfName.h"
12 #include "PdfArray.h"
13 
14 namespace PoDoFo {
15 
16 using PdfColorRaw = std::array<double, 6>;
17 
24 class PODOFO_API PdfColor final
25 {
26 public:
29  PdfColor();
30 
36  explicit PdfColor(double gray);
37 
45  PdfColor(double red, double green, double blue);
46 
55  PdfColor(double cyan, double magenta, double yellow, double black);
56 
61  PdfColor(const PdfColor& rhs) = default;
62 
63 public:
68  static bool TryCreateFromObject(const PdfObject& obj, PdfColor& color);
69  static PdfColor CreateFromObject(const PdfObject& obj);
70 
71  static PdfColor CreateTransparent();
72 
73 public:
78  bool IsGrayScale() const;
79 
84  bool IsRGB() const;
85 
90  bool IsCMYK() const;
91 
92  bool IsTransparent() const;
93 
98  inline PdfColorSpaceType GetColorSpace() const { return m_ColorSpace; }
99 
109  double GetGrayScale() const;
110 
120  double GetRed() const;
121 
131  double GetGreen() const;
132 
142  double GetBlue() const;
143 
153  double GetCyan() const;
154 
164  double GetMagenta() const;
165 
175  double GetYellow() const;
176 
186  double GetBlack() const;
187 
198  PdfColor ConvertToGrayScale() const;
199 
210  PdfColor ConvertToRGB() const;
211 
222  PdfColor ConvertToCMYK() const;
223 
227  PdfArray ToArray() const;
228 
241  static PdfColor CreateFromString(const std::string_view& name);
242 
243 public:
244  unsigned char GetComponentCount() const { return m_ComponentCount; }
245 
246  const PdfColorRaw& GetRawColor() const { return m_RawColor; }
247 
254  PdfColor& operator=(const PdfColor& rhs) = default;
255 
262  bool operator==(const PdfColor& rhs) const;
263 
270  bool operator!=(const PdfColor& rhs) const;
271 
272 private:
273  PdfColor(bool isTransparent, PdfColorSpaceType colorSpace, unsigned char componentCount, const PdfColorRaw& data);
274 
275  static bool tryCreateFromArray(const PdfArray& arr, PdfColor& color);
276 
277 private:
278  bool m_IsTransparent;
279  PdfColorSpaceType m_ColorSpace;
280  unsigned char m_ComponentCount;
281  PdfColorRaw m_RawColor;
282 };
283 
284 };
285 
286 #endif // PDF_COLOR_H
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition: PdfArray.h:81
A color object can represent either a grayscale value, a RGB color, a CMYK color.
Definition: PdfColor.h:25
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:98
This class represents a PDF indirect Object in memory.
Definition: PdfObject.h:35
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition: basetypes.h:16
PdfColorSpaceType
Enum for the colorspaces supported by PDF.
Definition: PdfDeclarations.h:330