OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" | 7 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 ShadingType ToShadingType(int type) { | 16 ShadingType ToShadingType(int type) { |
17 return (type > static_cast<int>(kInvalidShading) && | 17 return (type > static_cast<int>(kInvalidShading) && |
18 type < static_cast<int>(kMaxShading)) | 18 type < static_cast<int>(kMaxShading)) |
19 ? static_cast<ShadingType>(type) | 19 ? static_cast<ShadingType>(type) |
20 : kInvalidShading; | 20 : kInvalidShading; |
21 } | 21 } |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, | 25 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, |
26 CPDF_Object* pPatternObj, | 26 CPDF_Object* pPatternObj, |
27 FX_BOOL bShading, | 27 FX_BOOL bShading, |
28 const CFX_Matrix* parentMatrix) | 28 const CFX_Matrix& parentMatrix) |
29 : CPDF_Pattern(SHADING, | 29 : CPDF_Pattern(SHADING, |
30 pDoc, | 30 pDoc, |
31 bShading ? nullptr : pPatternObj, | 31 bShading ? nullptr : pPatternObj, |
32 parentMatrix), | 32 parentMatrix), |
33 m_ShadingType(kInvalidShading), | 33 m_ShadingType(kInvalidShading), |
34 m_bShadingObj(bShading), | 34 m_bShadingObj(bShading), |
35 m_pShadingObj(pPatternObj), | 35 m_pShadingObj(pPatternObj), |
36 m_pCS(nullptr), | 36 m_pCS(nullptr), |
37 m_pCountedCS(nullptr), | 37 m_pCountedCS(nullptr), |
38 m_nFuncs(0) { | 38 m_nFuncs(0) { |
39 if (!bShading) { | 39 if (!bShading) { |
40 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 40 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
41 m_Pattern2Form = pDict->GetMatrixBy("Matrix"); | 41 m_Pattern2Form = pDict->GetMatrixBy("Matrix"); |
42 m_pShadingObj = pDict->GetDirectObjectBy("Shading"); | 42 m_pShadingObj = pDict->GetDirectObjectBy("Shading"); |
43 if (parentMatrix) | 43 m_Pattern2Form.Concat(parentMatrix); |
44 m_Pattern2Form.Concat(*parentMatrix); | |
45 } | 44 } |
46 for (size_t i = 0; i < FX_ArraySize(m_pFunctions); ++i) | 45 for (size_t i = 0; i < FX_ArraySize(m_pFunctions); ++i) |
47 m_pFunctions[i] = nullptr; | 46 m_pFunctions[i] = nullptr; |
48 } | 47 } |
49 | 48 |
50 CPDF_ShadingPattern::~CPDF_ShadingPattern() { | 49 CPDF_ShadingPattern::~CPDF_ShadingPattern() { |
51 for (size_t i = 0; i < m_nFuncs; ++i) | 50 for (size_t i = 0; i < m_nFuncs; ++i) |
52 delete m_pFunctions[i]; | 51 delete m_pFunctions[i]; |
53 | 52 |
54 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : nullptr; | 53 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : nullptr; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); | 91 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); |
93 | 92 |
94 m_ShadingType = ToShadingType(pShadingDict->GetIntegerBy("ShadingType")); | 93 m_ShadingType = ToShadingType(pShadingDict->GetIntegerBy("ShadingType")); |
95 | 94 |
96 // We expect to have a stream if our shading type is a mesh. | 95 // We expect to have a stream if our shading type is a mesh. |
97 if (IsMeshShading() && !ToStream(m_pShadingObj)) | 96 if (IsMeshShading() && !ToStream(m_pShadingObj)) |
98 return FALSE; | 97 return FALSE; |
99 | 98 |
100 return TRUE; | 99 return TRUE; |
101 } | 100 } |
OLD | NEW |