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

Side by Side Diff: core/fpdfapi/page/cpdf_contentparser.cpp

Issue 2571913002: Avoid the ptr.reset(new XXX()) anti-pattern (Closed)
Patch Set: rebase Created 4 years 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/font/fpdf_font.cpp ('k') | core/fpdfapi/page/cpdf_form.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/page/cpdf_contentparser.h" 7 #include "core/fpdfapi/page/cpdf_contentparser.h"
8 8
9 #include "core/fpdfapi/font/cpdf_type3char.h" 9 #include "core/fpdfapi/font/cpdf_type3char.h"
10 #include "core/fpdfapi/page/cpdf_allstates.h" 10 #include "core/fpdfapi/page/cpdf_allstates.h"
11 #include "core/fpdfapi/page/cpdf_form.h" 11 #include "core/fpdfapi/page/cpdf_form.h"
12 #include "core/fpdfapi/page/cpdf_page.h" 12 #include "core/fpdfapi/page/cpdf_page.h"
13 #include "core/fpdfapi/page/cpdf_pageobject.h" 13 #include "core/fpdfapi/page/cpdf_pageobject.h"
14 #include "core/fpdfapi/page/cpdf_path.h" 14 #include "core/fpdfapi/page/cpdf_path.h"
15 #include "core/fpdfapi/parser/cpdf_array.h" 15 #include "core/fpdfapi/parser/cpdf_array.h"
16 #include "core/fpdfapi/parser/cpdf_dictionary.h" 16 #include "core/fpdfapi/parser/cpdf_dictionary.h"
17 #include "core/fpdfapi/parser/cpdf_stream.h" 17 #include "core/fpdfapi/parser/cpdf_stream.h"
18 #include "core/fpdfapi/parser/cpdf_stream_acc.h" 18 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
19 #include "core/fxcrt/fx_safe_types.h" 19 #include "core/fxcrt/fx_safe_types.h"
20 #include "third_party/base/ptr_util.h"
20 21
21 #define PARSE_STEP_LIMIT 100 22 #define PARSE_STEP_LIMIT 100
22 23
23 CPDF_ContentParser::CPDF_ContentParser() 24 CPDF_ContentParser::CPDF_ContentParser()
24 : m_Status(Ready), 25 : m_Status(Ready),
25 m_InternalStage(STAGE_GETCONTENT), 26 m_InternalStage(STAGE_GETCONTENT),
26 m_pObjectHolder(nullptr), 27 m_pObjectHolder(nullptr),
27 m_bForm(false), 28 m_bForm(false),
28 m_pType3Char(nullptr), 29 m_pType3Char(nullptr),
29 m_pData(nullptr), 30 m_pData(nullptr),
(...skipping 17 matching lines...) Expand all
47 m_InternalStage = STAGE_GETCONTENT; 48 m_InternalStage = STAGE_GETCONTENT;
48 m_CurrentOffset = 0; 49 m_CurrentOffset = 0;
49 50
50 CPDF_Object* pContent = pPage->m_pFormDict->GetDirectObjectFor("Contents"); 51 CPDF_Object* pContent = pPage->m_pFormDict->GetDirectObjectFor("Contents");
51 if (!pContent) { 52 if (!pContent) {
52 m_Status = Done; 53 m_Status = Done;
53 return; 54 return;
54 } 55 }
55 if (CPDF_Stream* pStream = pContent->AsStream()) { 56 if (CPDF_Stream* pStream = pContent->AsStream()) {
56 m_nStreams = 0; 57 m_nStreams = 0;
57 m_pSingleStream.reset(new CPDF_StreamAcc); 58 m_pSingleStream = pdfium::MakeUnique<CPDF_StreamAcc>();
58 m_pSingleStream->LoadAllData(pStream, false); 59 m_pSingleStream->LoadAllData(pStream, false);
59 } else if (CPDF_Array* pArray = pContent->AsArray()) { 60 } else if (CPDF_Array* pArray = pContent->AsArray()) {
60 m_nStreams = pArray->GetCount(); 61 m_nStreams = pArray->GetCount();
61 if (m_nStreams) 62 if (m_nStreams)
62 m_StreamArray.resize(m_nStreams); 63 m_StreamArray.resize(m_nStreams);
63 else 64 else
64 m_Status = Done; 65 m_Status = Done;
65 } else { 66 } else {
66 m_Status = Done; 67 m_Status = Done;
67 } 68 }
(...skipping 19 matching lines...) Expand all
87 ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right, 88 ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right,
88 form_bbox.top); 89 form_bbox.top);
89 ClipPath.Transform(&form_matrix); 90 ClipPath.Transform(&form_matrix);
90 if (pParentMatrix) 91 if (pParentMatrix)
91 ClipPath.Transform(pParentMatrix); 92 ClipPath.Transform(pParentMatrix);
92 form_bbox.Transform(&form_matrix); 93 form_bbox.Transform(&form_matrix);
93 if (pParentMatrix) 94 if (pParentMatrix)
94 form_bbox.Transform(pParentMatrix); 95 form_bbox.Transform(pParentMatrix);
95 } 96 }
96 CPDF_Dictionary* pResources = pForm->m_pFormDict->GetDictFor("Resources"); 97 CPDF_Dictionary* pResources = pForm->m_pFormDict->GetDictFor("Resources");
97 m_pParser.reset(new CPDF_StreamContentParser( 98 m_pParser = pdfium::MakeUnique<CPDF_StreamContentParser>(
98 pForm->m_pDocument, pForm->m_pPageResources, pForm->m_pResources, 99 pForm->m_pDocument, pForm->m_pPageResources, pForm->m_pResources,
99 pParentMatrix, pForm, pResources, &form_bbox, pGraphicStates, level)); 100 pParentMatrix, pForm, pResources, &form_bbox, pGraphicStates, level);
100 m_pParser->GetCurStates()->m_CTM = form_matrix; 101 m_pParser->GetCurStates()->m_CTM = form_matrix;
101 m_pParser->GetCurStates()->m_ParentMatrix = form_matrix; 102 m_pParser->GetCurStates()->m_ParentMatrix = form_matrix;
102 if (ClipPath) { 103 if (ClipPath) {
103 m_pParser->GetCurStates()->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, 104 m_pParser->GetCurStates()->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING,
104 true); 105 true);
105 } 106 }
106 if (pForm->m_Transparency & PDFTRANS_GROUP) { 107 if (pForm->m_Transparency & PDFTRANS_GROUP) {
107 CPDF_GeneralState* pState = &m_pParser->GetCurStates()->m_GeneralState; 108 CPDF_GeneralState* pState = &m_pParser->GetCurStates()->m_GeneralState;
108 pState->SetBlendType(FXDIB_BLEND_NORMAL); 109 pState->SetBlendType(FXDIB_BLEND_NORMAL);
109 pState->SetStrokeAlpha(1.0f); 110 pState->SetStrokeAlpha(1.0f);
110 pState->SetFillAlpha(1.0f); 111 pState->SetFillAlpha(1.0f);
111 pState->SetSoftMask(nullptr); 112 pState->SetSoftMask(nullptr);
112 } 113 }
113 m_nStreams = 0; 114 m_nStreams = 0;
114 m_pSingleStream.reset(new CPDF_StreamAcc); 115 m_pSingleStream = pdfium::MakeUnique<CPDF_StreamAcc>();
115 m_pSingleStream->LoadAllData(pForm->m_pFormStream, false); 116 m_pSingleStream->LoadAllData(pForm->m_pFormStream, false);
116 m_pData = (uint8_t*)m_pSingleStream->GetData(); 117 m_pData = (uint8_t*)m_pSingleStream->GetData();
117 m_Size = m_pSingleStream->GetSize(); 118 m_Size = m_pSingleStream->GetSize();
118 m_Status = ToBeContinued; 119 m_Status = ToBeContinued;
119 m_InternalStage = STAGE_PARSE; 120 m_InternalStage = STAGE_PARSE;
120 m_CurrentOffset = 0; 121 m_CurrentOffset = 0;
121 } 122 }
122 123
123 void CPDF_ContentParser::Continue(IFX_Pause* pPause) { 124 void CPDF_ContentParser::Continue(IFX_Pause* pPause) {
124 int steps = 0; 125 int steps = 0;
(...skipping 21 matching lines...) Expand all
146 m_StreamArray.clear(); 147 m_StreamArray.clear();
147 } else { 148 } else {
148 m_pData = (uint8_t*)m_pSingleStream->GetData(); 149 m_pData = (uint8_t*)m_pSingleStream->GetData();
149 m_Size = m_pSingleStream->GetSize(); 150 m_Size = m_pSingleStream->GetSize();
150 } 151 }
151 m_InternalStage = STAGE_PARSE; 152 m_InternalStage = STAGE_PARSE;
152 m_CurrentOffset = 0; 153 m_CurrentOffset = 0;
153 } else { 154 } else {
154 CPDF_Array* pContent = 155 CPDF_Array* pContent =
155 m_pObjectHolder->m_pFormDict->GetArrayFor("Contents"); 156 m_pObjectHolder->m_pFormDict->GetArrayFor("Contents");
156 m_StreamArray[m_CurrentOffset].reset(new CPDF_StreamAcc); 157 m_StreamArray[m_CurrentOffset] = pdfium::MakeUnique<CPDF_StreamAcc>();
157 CPDF_Stream* pStreamObj = ToStream( 158 CPDF_Stream* pStreamObj = ToStream(
158 pContent ? pContent->GetDirectObjectAt(m_CurrentOffset) : nullptr); 159 pContent ? pContent->GetDirectObjectAt(m_CurrentOffset) : nullptr);
159 m_StreamArray[m_CurrentOffset]->LoadAllData(pStreamObj, false); 160 m_StreamArray[m_CurrentOffset]->LoadAllData(pStreamObj, false);
160 m_CurrentOffset++; 161 m_CurrentOffset++;
161 } 162 }
162 } 163 }
163 if (m_InternalStage == STAGE_PARSE) { 164 if (m_InternalStage == STAGE_PARSE) {
164 if (!m_pParser) { 165 if (!m_pParser) {
165 m_pParser.reset(new CPDF_StreamContentParser( 166 m_pParser = pdfium::MakeUnique<CPDF_StreamContentParser>(
166 m_pObjectHolder->m_pDocument, m_pObjectHolder->m_pPageResources, 167 m_pObjectHolder->m_pDocument, m_pObjectHolder->m_pPageResources,
167 nullptr, nullptr, m_pObjectHolder, m_pObjectHolder->m_pResources, 168 nullptr, nullptr, m_pObjectHolder, m_pObjectHolder->m_pResources,
168 &m_pObjectHolder->m_BBox, nullptr, 0)); 169 &m_pObjectHolder->m_BBox, nullptr, 0);
169 m_pParser->GetCurStates()->m_ColorState.SetDefault(); 170 m_pParser->GetCurStates()->m_ColorState.SetDefault();
170 } 171 }
171 if (m_CurrentOffset >= m_Size) { 172 if (m_CurrentOffset >= m_Size) {
172 m_InternalStage = STAGE_CHECKCLIP; 173 m_InternalStage = STAGE_CHECKCLIP;
173 } else { 174 } else {
174 m_CurrentOffset += 175 m_CurrentOffset +=
175 m_pParser->Parse(m_pData + m_CurrentOffset, 176 m_pParser->Parse(m_pData + m_CurrentOffset,
176 m_Size - m_CurrentOffset, PARSE_STEP_LIMIT); 177 m_Size - m_CurrentOffset, PARSE_STEP_LIMIT);
177 } 178 }
178 } 179 }
(...skipping 29 matching lines...) Expand all
208 pObj->m_ClipPath.SetNull(); 209 pObj->m_ClipPath.SetNull();
209 } 210 }
210 m_Status = Done; 211 m_Status = Done;
211 return; 212 return;
212 } 213 }
213 steps++; 214 steps++;
214 if (pPause && pPause->NeedToPauseNow()) 215 if (pPause && pPause->NeedToPauseNow())
215 break; 216 break;
216 } 217 }
217 } 218 }
OLDNEW
« no previous file with comments | « core/fpdfapi/font/fpdf_font.cpp ('k') | core/fpdfapi/page/cpdf_form.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698