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_SHADINGPATTERN_H_ 8 #define CORE_FPDFAPI_PAGE_CPDF_SHADINGPATTERN_H_ 9 10 #include <stdint.h> 11 12 #include <memory> 13 #include <vector> 14 15 #include "core/fpdfapi/page/cpdf_colorspace.h" 16 #include "core/fpdfapi/page/cpdf_pattern.h" 17 #include "core/fxcrt/retain_ptr.h" 18 19 // Values used in PDFs except for |kInvalidShading| and |kMaxShading|. 20 // Do not change. 21 enum ShadingType { 22 kInvalidShading = 0, 23 kFunctionBasedShading = 1, 24 kAxialShading = 2, 25 kRadialShading = 3, 26 kFreeFormGouraudTriangleMeshShading = 4, 27 kLatticeFormGouraudTriangleMeshShading = 5, 28 kCoonsPatchMeshShading = 6, 29 kTensorProductPatchMeshShading = 7, 30 kMaxShading = 8 31 }; 32 33 class CFX_Matrix; 34 class CPDF_ColorSpace; 35 class CPDF_Document; 36 class CPDF_Function; 37 class CPDF_Object; 38 39 class CPDF_ShadingPattern final : public CPDF_Pattern { 40 public: 41 CONSTRUCT_VIA_MAKE_RETAIN; 42 ~CPDF_ShadingPattern() override; 43 44 // CPDF_Pattern: 45 CPDF_ShadingPattern* AsShadingPattern() override; 46 IsMeshShading()47 bool IsMeshShading() const { 48 return m_ShadingType == kFreeFormGouraudTriangleMeshShading || 49 m_ShadingType == kLatticeFormGouraudTriangleMeshShading || 50 m_ShadingType == kCoonsPatchMeshShading || 51 m_ShadingType == kTensorProductPatchMeshShading; 52 } 53 bool Load(); 54 GetShadingType()55 ShadingType GetShadingType() const { return m_ShadingType; } IsShadingObject()56 bool IsShadingObject() const { return m_bShading; } 57 RetainPtr<const CPDF_Object> GetShadingObject() const; GetCS()58 RetainPtr<CPDF_ColorSpace> GetCS() const { return m_pCS; } GetFuncs()59 const std::vector<std::unique_ptr<CPDF_Function>>& GetFuncs() const { 60 return m_pFunctions; 61 } 62 63 private: 64 CPDF_ShadingPattern(CPDF_Document* pDoc, 65 RetainPtr<CPDF_Object> pPatternObj, 66 bool bShading, 67 const CFX_Matrix& parentMatrix); 68 CPDF_ShadingPattern(const CPDF_ShadingPattern&) = delete; 69 CPDF_ShadingPattern& operator=(const CPDF_ShadingPattern&) = delete; 70 71 // Constraints in PDF 1.7 spec, 4.6.3 Shading Patterns, pages 308-331. 72 bool Validate() const; 73 bool ValidateFunctions(uint32_t nExpectedNumFunctions, 74 uint32_t nExpectedNumInputs, 75 uint32_t nExpectedNumOutputs) const; 76 77 ShadingType m_ShadingType = kInvalidShading; 78 const bool m_bShading; 79 RetainPtr<CPDF_ColorSpace> m_pCS; 80 std::vector<std::unique_ptr<CPDF_Function>> m_pFunctions; 81 }; 82 83 #endif // CORE_FPDFAPI_PAGE_CPDF_SHADINGPATTERN_H_ 84