1 // Copyright 2016 PDFium Authors. All rights reserved. 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/fx_system.h" 14 #include "core/fxcrt/retain_ptr.h" 15 #include "core/fxcrt/shared_copy_on_write.h" 16 #include "core/fxge/fx_dib.h" 17 18 class CPDF_Color; 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(const RetainPtr<CPDF_ColorSpace>& pCS, 46 const std::vector<float>& values); 47 void SetStrokeColor(const RetainPtr<CPDF_ColorSpace>& pCS, 48 const std::vector<float>& values); 49 void SetFillPattern(const RetainPtr<CPDF_Pattern>& pattern, 50 const std::vector<float>& values); 51 void SetStrokePattern(const RetainPtr<CPDF_Pattern>& pattern, 52 const std::vector<float>& values); 53 HasRef()54 bool HasRef() const { return !!m_Ref; } 55 56 private: 57 class ColorData final : public Retainable { 58 public: 59 template <typename T, typename... Args> 60 friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); 61 62 RetainPtr<ColorData> Clone() const; 63 64 void SetDefault(); 65 66 FX_COLORREF m_FillColorRef = 0; 67 FX_COLORREF m_StrokeColorRef = 0; 68 CPDF_Color m_FillColor; 69 CPDF_Color m_StrokeColor; 70 71 private: 72 ColorData(); 73 ColorData(const ColorData& src); 74 ~ColorData() override; 75 }; 76 77 void SetColor(const RetainPtr<CPDF_ColorSpace>& pCS, 78 const std::vector<float>& values, 79 CPDF_Color* color, 80 FX_COLORREF* colorref); 81 void SetPattern(const RetainPtr<CPDF_Pattern>& pPattern, 82 const std::vector<float>& values, 83 CPDF_Color* color, 84 FX_COLORREF* colorref); 85 86 SharedCopyOnWrite<ColorData> m_Ref; 87 }; 88 89 #endif // CORE_FPDFAPI_PAGE_CPDF_COLORSTATE_H_ 90