Home | History | Annotate | Download | only in page
      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/unowned_ptr.h"
     17 
     18 enum ShadingType {
     19   kInvalidShading = 0,
     20   kFunctionBasedShading = 1,
     21   kAxialShading = 2,
     22   kRadialShading = 3,
     23   kFreeFormGouraudTriangleMeshShading = 4,
     24   kLatticeFormGouraudTriangleMeshShading = 5,
     25   kCoonsPatchMeshShading = 6,
     26   kTensorProductPatchMeshShading = 7,
     27   kMaxShading = 8
     28 };
     29 
     30 class CFX_Matrix;
     31 class CPDF_ColorSpace;
     32 class CPDF_Document;
     33 class CPDF_Function;
     34 class CPDF_Object;
     35 
     36 class CPDF_ShadingPattern : public CPDF_Pattern {
     37  public:
     38   CPDF_ShadingPattern(CPDF_Document* pDoc,
     39                       CPDF_Object* pPatternObj,
     40                       bool bShading,
     41                       const CFX_Matrix& parentMatrix);
     42   ~CPDF_ShadingPattern() override;
     43 
     44   CPDF_TilingPattern* AsTilingPattern() override;
     45   CPDF_ShadingPattern* AsShadingPattern() override;
     46 
     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 
     55   ShadingType GetShadingType() const { return m_ShadingType; }
     56   bool IsShadingObject() const { return m_bShadingObj; }
     57   CPDF_Object* GetShadingObject() const { return m_pShadingObj.Get(); }
     58   CPDF_ColorSpace* GetCS() const { return m_pCS.Get(); }
     59   const std::vector<std::unique_ptr<CPDF_Function>>& GetFuncs() const {
     60     return m_pFunctions;
     61   }
     62 
     63  private:
     64   // Constraints in PDF 1.7 spec, 4.6.3 Shading Patterns, pages 308-331.
     65   bool Validate() const;
     66   bool ValidateFunctions(uint32_t nExpectedNumFunctions,
     67                          uint32_t nExpectedNumInputs,
     68                          uint32_t nExpectedNumOutputs) const;
     69 
     70   ShadingType m_ShadingType;
     71   bool m_bShadingObj;
     72   UnownedPtr<CPDF_Object> m_pShadingObj;
     73 
     74   // Still keep |m_pCS| as some CPDF_ColorSpace (name object) are not managed
     75   // as counted objects. Refer to CPDF_DocPageData::GetColorSpace.
     76   UnownedPtr<CPDF_ColorSpace> m_pCS;
     77 
     78   UnownedPtr<CPDF_CountedColorSpace> m_pCountedCS;
     79   std::vector<std::unique_ptr<CPDF_Function>> m_pFunctions;
     80 };
     81 
     82 #endif  // CORE_FPDFAPI_PAGE_CPDF_SHADINGPATTERN_H_
     83