1 // Copyright 2016 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FPDFAPI_PAGE_CPDF_COLOR_H_ 8 #define CORE_FPDFAPI_PAGE_CPDF_COLOR_H_ 9 10 #include <stdint.h> 11 12 #include <memory> 13 #include <vector> 14 15 #include "core/fxcrt/retain_ptr.h" 16 #include "third_party/base/containers/span.h" 17 18 class CPDF_ColorSpace; 19 class CPDF_Pattern; 20 class PatternValue; 21 22 class CPDF_Color { 23 public: 24 CPDF_Color(); 25 CPDF_Color(const CPDF_Color& that); 26 27 ~CPDF_Color(); 28 29 CPDF_Color& operator=(const CPDF_Color& that); 30 IsNull()31 bool IsNull() const { return m_Buffer.empty() && !m_pValue; } 32 bool IsPattern() const; 33 void SetColorSpace(RetainPtr<CPDF_ColorSpace> colorspace); 34 void SetValueForNonPattern(std::vector<float> values); 35 void SetValueForPattern(RetainPtr<CPDF_Pattern> pattern, 36 pdfium::span<float> values); 37 38 uint32_t CountComponents() const; 39 bool IsColorSpaceRGB() const; 40 bool GetRGB(int* R, int* G, int* B) const; 41 42 // Should only be called if IsPattern() returns true. 43 RetainPtr<CPDF_Pattern> GetPattern() const; 44 45 protected: 46 bool IsPatternInternal() const; 47 48 std::vector<float> m_Buffer; // Used for non-pattern colorspaces. 49 std::unique_ptr<PatternValue> m_pValue; // Used for pattern colorspaces. 50 RetainPtr<CPDF_ColorSpace> m_pCS; 51 }; 52 53 #endif // CORE_FPDFAPI_PAGE_CPDF_COLOR_H_ 54