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 XFA_FGAS_GRAPHICS_CFGAS_GESHADING_H_ 8 #define XFA_FGAS_GRAPHICS_CFGAS_GESHADING_H_ 9 10 #include <stddef.h> 11 12 #include <array> 13 14 #include "core/fxcrt/fx_coordinates.h" 15 #include "core/fxge/dib/fx_dib.h" 16 17 class CFGAS_GEShading final { 18 public: 19 enum class Type { kAxial = 1, kRadial }; 20 21 // Axial shading. 22 CFGAS_GEShading(const CFX_PointF& beginPoint, 23 const CFX_PointF& endPoint, 24 bool isExtendedBegin, 25 bool isExtendedEnd, 26 FX_ARGB beginArgb, 27 FX_ARGB endArgb); 28 29 // Radial shading. 30 CFGAS_GEShading(const CFX_PointF& beginPoint, 31 const CFX_PointF& endPoint, 32 float beginRadius, 33 float endRadius, 34 bool isExtendedBegin, 35 bool isExtendedEnd, 36 FX_ARGB beginArgb, 37 FX_ARGB endArgb); 38 39 ~CFGAS_GEShading(); 40 GetType()41 Type GetType() const { return m_type; } GetBeginPoint()42 CFX_PointF GetBeginPoint() const { return m_beginPoint; } GetEndPoint()43 CFX_PointF GetEndPoint() const { return m_endPoint; } GetBeginRadius()44 float GetBeginRadius() const { return m_beginRadius; } GetEndRadius()45 float GetEndRadius() const { return m_endRadius; } IsExtendedBegin()46 bool IsExtendedBegin() const { return m_isExtendedBegin; } IsExtendedEnd()47 bool IsExtendedEnd() const { return m_isExtendedEnd; } GetArgb(float value)48 FX_ARGB GetArgb(float value) const { 49 return m_argbArray[static_cast<size_t>(value * (kSteps - 1))]; 50 } 51 52 private: 53 static constexpr size_t kSteps = 256; 54 55 void InitArgbArray(FX_ARGB begin_argb, FX_ARGB end_argb); 56 57 const Type m_type; 58 const CFX_PointF m_beginPoint; 59 const CFX_PointF m_endPoint; 60 const float m_beginRadius; 61 const float m_endRadius; 62 const bool m_isExtendedBegin; 63 const bool m_isExtendedEnd; 64 std::array<FX_ARGB, kSteps> m_argbArray; 65 }; 66 67 #endif // XFA_FGAS_GRAPHICS_CFGAS_GESHADING_H_ 68