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