• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SHADINGPATTERN_H_
8 #define CORE_FPDFAPI_PAGE_CPDF_SHADINGPATTERN_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fpdfapi/page/cpdf_colorspace.h"
14 #include "core/fpdfapi/page/cpdf_pattern.h"
15 #include "core/fxcrt/fx_system.h"
16 #include "core/fxcrt/retain_ptr.h"
17 #include "core/fxcrt/unowned_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   template <typename T, typename... Args>
42   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
43 
44   ~CPDF_ShadingPattern() override;
45 
46   // CPDF_Pattern:
47   CPDF_ShadingPattern* AsShadingPattern() override;
48 
IsMeshShading()49   bool IsMeshShading() const {
50     return m_ShadingType == kFreeFormGouraudTriangleMeshShading ||
51            m_ShadingType == kLatticeFormGouraudTriangleMeshShading ||
52            m_ShadingType == kCoonsPatchMeshShading ||
53            m_ShadingType == kTensorProductPatchMeshShading;
54   }
55   bool Load();
56 
GetShadingType()57   ShadingType GetShadingType() const { return m_ShadingType; }
IsShadingObject()58   bool IsShadingObject() const { return m_bShading; }
59   const CPDF_Object* GetShadingObject() const;
GetCS()60   RetainPtr<CPDF_ColorSpace> GetCS() const { return m_pCS; }
GetFuncs()61   const std::vector<std::unique_ptr<CPDF_Function>>& GetFuncs() const {
62     return m_pFunctions;
63   }
64 
65  private:
66   CPDF_ShadingPattern(CPDF_Document* pDoc,
67                       CPDF_Object* pPatternObj,
68                       bool bShading,
69                       const CFX_Matrix& parentMatrix);
70   CPDF_ShadingPattern(const CPDF_ShadingPattern&) = delete;
71   CPDF_ShadingPattern& operator=(const CPDF_ShadingPattern&) = delete;
72 
73   // Constraints in PDF 1.7 spec, 4.6.3 Shading Patterns, pages 308-331.
74   bool Validate() const;
75   bool ValidateFunctions(uint32_t nExpectedNumFunctions,
76                          uint32_t nExpectedNumInputs,
77                          uint32_t nExpectedNumOutputs) const;
78 
79   ShadingType m_ShadingType = kInvalidShading;
80   const bool m_bShading;
81   RetainPtr<CPDF_ColorSpace> m_pCS;
82   std::vector<std::unique_ptr<CPDF_Function>> m_pFunctions;
83 };
84 
85 #endif  // CORE_FPDFAPI_PAGE_CPDF_SHADINGPATTERN_H_
86