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_COLORSTATE_H_ 8 #define CORE_FPDFAPI_PAGE_CPDF_COLORSTATE_H_ 9 10 #include <vector> 11 12 #include "core/fpdfapi/page/cpdf_color.h" 13 #include "core/fxcrt/retain_ptr.h" 14 #include "core/fxcrt/shared_copy_on_write.h" 15 #include "core/fxge/dib/fx_dib.h" 16 #include "third_party/base/containers/span.h" 17 18 class CPDF_ColorSpace; 19 class CPDF_Pattern; 20 21 class CPDF_ColorState { 22 public: 23 CPDF_ColorState(); 24 CPDF_ColorState(const CPDF_ColorState& that); 25 ~CPDF_ColorState(); 26 27 void Emplace(); 28 void SetDefault(); 29 30 FX_COLORREF GetFillColorRef() const; 31 void SetFillColorRef(FX_COLORREF colorref); 32 33 FX_COLORREF GetStrokeColorRef() const; 34 void SetStrokeColorRef(FX_COLORREF colorref); 35 36 const CPDF_Color* GetFillColor() const; 37 CPDF_Color* GetMutableFillColor(); 38 bool HasFillColor() const; 39 40 const CPDF_Color* GetStrokeColor() const; 41 CPDF_Color* GetMutableStrokeColor(); 42 bool HasStrokeColor() const; 43 44 void SetFillColor(RetainPtr<CPDF_ColorSpace> colorspace, 45 std::vector<float> values); 46 void SetStrokeColor(RetainPtr<CPDF_ColorSpace> colorspace, 47 std::vector<float> values); 48 void SetFillPattern(RetainPtr<CPDF_Pattern> pattern, 49 pdfium::span<float> values); 50 void SetStrokePattern(RetainPtr<CPDF_Pattern> pattern, 51 pdfium::span<float> values); 52 HasRef()53 bool HasRef() const { return !!m_Ref; } 54 55 private: 56 class ColorData final : public Retainable { 57 public: 58 CONSTRUCT_VIA_MAKE_RETAIN; 59 60 RetainPtr<ColorData> Clone() const; 61 62 void SetDefault(); 63 64 FX_COLORREF m_FillColorRef = 0; 65 FX_COLORREF m_StrokeColorRef = 0; 66 CPDF_Color m_FillColor; 67 CPDF_Color m_StrokeColor; 68 69 private: 70 ColorData(); 71 ColorData(const ColorData& src); 72 ~ColorData() override; 73 }; 74 75 void SetColor(RetainPtr<CPDF_ColorSpace> colorspace, 76 std::vector<float> values, 77 CPDF_Color* color, 78 FX_COLORREF* colorref); 79 void SetPattern(RetainPtr<CPDF_Pattern> pattern, 80 pdfium::span<float> values, 81 CPDF_Color* color, 82 FX_COLORREF* colorref); 83 84 SharedCopyOnWrite<ColorData> m_Ref; 85 }; 86 87 #endif // CORE_FPDFAPI_PAGE_CPDF_COLORSTATE_H_ 88