Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp

Issue 2000973002: Make CPDF_Function::Load() return an unique_ptr. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: fix build, nits Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_shadingpattern.h ('k') | core/fpdfapi/fpdf_page/fpdf_page_doc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_page/pageint.h"
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
13 14
14 namespace { 15 namespace {
15 16
16 ShadingType ToShadingType(int type) { 17 ShadingType ToShadingType(int type) {
17 return (type > static_cast<int>(kInvalidShading) && 18 return (type > static_cast<int>(kInvalidShading) &&
18 type < static_cast<int>(kMaxShading)) 19 type < static_cast<int>(kMaxShading))
19 ? static_cast<ShadingType>(type) 20 ? static_cast<ShadingType>(type)
20 : kInvalidShading; 21 : kInvalidShading;
21 } 22 }
22 23
23 } // namespace 24 } // namespace
24 25
25 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, 26 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc,
26 CPDF_Object* pPatternObj, 27 CPDF_Object* pPatternObj,
27 FX_BOOL bShading, 28 FX_BOOL bShading,
28 const CFX_Matrix& parentMatrix) 29 const CFX_Matrix& parentMatrix)
29 : CPDF_Pattern(SHADING, 30 : CPDF_Pattern(SHADING,
30 pDoc, 31 pDoc,
31 bShading ? nullptr : pPatternObj, 32 bShading ? nullptr : pPatternObj,
32 parentMatrix), 33 parentMatrix),
33 m_ShadingType(kInvalidShading), 34 m_ShadingType(kInvalidShading),
34 m_bShadingObj(bShading), 35 m_bShadingObj(bShading),
35 m_pShadingObj(pPatternObj), 36 m_pShadingObj(pPatternObj),
36 m_pCS(nullptr), 37 m_pCS(nullptr),
37 m_pCountedCS(nullptr), 38 m_pCountedCS(nullptr) {
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 m_Pattern2Form.Concat(parentMatrix); 43 m_Pattern2Form.Concat(parentMatrix);
44 } 44 }
45 for (size_t i = 0; i < FX_ArraySize(m_pFunctions); ++i)
46 m_pFunctions[i] = nullptr;
47 } 45 }
48 46
49 CPDF_ShadingPattern::~CPDF_ShadingPattern() { 47 CPDF_ShadingPattern::~CPDF_ShadingPattern() {
50 for (size_t i = 0; i < m_nFuncs; ++i)
51 delete m_pFunctions[i];
52
53 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : nullptr; 48 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : nullptr;
54 if (pCS && m_pDocument) 49 if (pCS && m_pDocument)
55 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); 50 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
56 } 51 }
57 52
58 FX_BOOL CPDF_ShadingPattern::Load() { 53 bool CPDF_ShadingPattern::Load() {
59 if (m_ShadingType != kInvalidShading) 54 if (m_ShadingType != kInvalidShading)
60 return TRUE; 55 return TRUE;
61 56
62 CPDF_Dictionary* pShadingDict = 57 CPDF_Dictionary* pShadingDict =
63 m_pShadingObj ? m_pShadingObj->GetDict() : nullptr; 58 m_pShadingObj ? m_pShadingObj->GetDict() : nullptr;
64 if (!pShadingDict) 59 if (!pShadingDict)
65 return FALSE; 60 return FALSE;
66 61
67 if (m_nFuncs) { 62 m_pFunctions.clear();
68 for (size_t i = 0; i < m_nFuncs; i++)
69 delete m_pFunctions[i];
70 m_nFuncs = 0;
71 }
72 CPDF_Object* pFunc = pShadingDict->GetDirectObjectBy("Function"); 63 CPDF_Object* pFunc = pShadingDict->GetDirectObjectBy("Function");
73 if (pFunc) { 64 if (pFunc) {
74 if (CPDF_Array* pArray = pFunc->AsArray()) { 65 if (CPDF_Array* pArray = pFunc->AsArray()) {
75 m_nFuncs = std::min<size_t>(pArray->GetCount(), 4); 66 m_pFunctions.resize(std::min<size_t>(pArray->GetCount(), 4));
76 67 for (size_t i = 0; i < m_pFunctions.size(); ++i)
77 for (size_t i = 0; i < m_nFuncs; i++)
78 m_pFunctions[i] = CPDF_Function::Load(pArray->GetDirectObjectAt(i)); 68 m_pFunctions[i] = CPDF_Function::Load(pArray->GetDirectObjectAt(i));
79 } else { 69 } else {
80 m_pFunctions[0] = CPDF_Function::Load(pFunc); 70 m_pFunctions.push_back(CPDF_Function::Load(pFunc));
81 m_nFuncs = 1;
82 } 71 }
83 } 72 }
84 CPDF_Object* pCSObj = pShadingDict->GetDirectObjectBy("ColorSpace"); 73 CPDF_Object* pCSObj = pShadingDict->GetDirectObjectBy("ColorSpace");
85 if (!pCSObj) 74 if (!pCSObj)
86 return FALSE; 75 return FALSE;
87 76
88 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); 77 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData();
89 m_pCS = pDocPageData->GetColorSpace(pCSObj, nullptr); 78 m_pCS = pDocPageData->GetColorSpace(pCSObj, nullptr);
90 if (m_pCS) 79 if (m_pCS)
91 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); 80 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray());
92 81
93 m_ShadingType = ToShadingType(pShadingDict->GetIntegerBy("ShadingType")); 82 m_ShadingType = ToShadingType(pShadingDict->GetIntegerBy("ShadingType"));
94 83
95 // We expect to have a stream if our shading type is a mesh. 84 // We expect to have a stream if our shading type is a mesh.
96 if (IsMeshShading() && !ToStream(m_pShadingObj)) 85 if (IsMeshShading() && !ToStream(m_pShadingObj))
97 return FALSE; 86 return FALSE;
98 87
99 return TRUE; 88 return TRUE;
100 } 89 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_shadingpattern.h ('k') | core/fpdfapi/fpdf_page/fpdf_page_doc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698