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

Side by Side Diff: core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp

Issue 656753002: Store the address of the page data map's value for proper referencing. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: typedef Created 6 years, 2 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
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "../../../include/fpdfapi/fpdf_page.h" 7 #include "../../../include/fpdfapi/fpdf_page.h"
8 #include "../../../include/fpdfapi/fpdf_module.h" 8 #include "../../../include/fpdfapi/fpdf_module.h"
9 #include "../../../include/fdrm/fx_crypt.h" 9 #include "../../../include/fdrm/fx_crypt.h"
10 #include "../fpdf_font/font_int.h" 10 #include "../fpdf_font/font_int.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 m_ColorSpaceMap.InitHashTable(32); 140 m_ColorSpaceMap.InitHashTable(32);
141 m_PatternMap.InitHashTable(16); 141 m_PatternMap.InitHashTable(16);
142 m_ImageMap.InitHashTable(64); 142 m_ImageMap.InitHashTable(64);
143 m_IccProfileMap.InitHashTable(16); 143 m_IccProfileMap.InitHashTable(16);
144 m_FontFileMap.InitHashTable(32); 144 m_FontFileMap.InitHashTable(32);
145 } 145 }
146 CPDF_DocPageData::~CPDF_DocPageData() 146 CPDF_DocPageData::~CPDF_DocPageData()
147 { 147 {
148 Clear(FALSE); 148 Clear(FALSE);
149 Clear(TRUE); 149 Clear(TRUE);
150 FX_POSITION pos = m_PatternMap.GetStartPosition();
151 while (pos)
152 {
153 CPDF_Object* ptObj;
154 CPDF_CountedObject<CPDF_Pattern*>* ptData;
155 m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
156 delete ptData;
157 }
158 m_PatternMap.RemoveAll();
159 pos = m_FontMap.GetStartPosition();
160 while (pos)
161 {
162 CPDF_Dictionary* fontDict;
163 CPDF_CountedObject<CPDF_Font*>* fontData;
164 m_FontMap.GetNextAssoc(pos, fontDict, fontData);
165 delete fontData;
166 }
167 m_FontMap.RemoveAll();
168 pos = m_ColorSpaceMap.GetStartPosition();
169 while (pos)
170 {
171 CPDF_Object* csKey;
172 CPDF_CountedObject<CPDF_ColorSpace*>* csData;
173 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData);
174 delete csData;
175 }
176 m_ColorSpaceMap.RemoveAll();
150 } 177 }
151 void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) 178 void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
152 { 179 {
153 FX_POSITION pos; 180 FX_POSITION pos;
154
155 m_bForceClear = bForceRelease; 181 m_bForceClear = bForceRelease;
156 182 pos = m_PatternMap.GetStartPosition();
157 // Release objects saved in the resource maps like font map and color space map. 183 while (pos) {
158 // The compound objects shall be released before simple ones. 184 CPDF_Object* ptObj;
185 CPDF_CountedObject<CPDF_Pattern*>* ptData;
186 m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
187 if (!ptData->m_Obj) {
188 continue;
189 }
190 if (bForceRelease || ptData->m_nCount < 2) {
191 ptData->m_Obj->SetForceClear(bForceRelease);
192 delete ptData->m_Obj;
193 ptData->m_Obj = NULL;
194 }
195 }
159 pos = m_FontMap.GetStartPosition(); 196 pos = m_FontMap.GetStartPosition();
160 while (pos) { 197 while (pos) {
161 CPDF_Dictionary* fontDict; 198 CPDF_Dictionary* fontDict;
162 CPDF_CountedObject<CPDF_Font*>* fontData; 199 CPDF_CountedObject<CPDF_Font*>* fontData;
163 m_FontMap.GetNextAssoc(pos, fontDict, fontData); 200 m_FontMap.GetNextAssoc(pos, fontDict, fontData);
164 if (!fontData->m_Obj) { 201 if (!fontData->m_Obj) {
165 continue; 202 continue;
166 } 203 }
167 if (bForceRelease || fontData->m_nCount < 2) { 204 if (bForceRelease || fontData->m_nCount < 2) {
168 delete fontData->m_Obj; 205 delete fontData->m_Obj;
169 fontData->m_Obj = NULL; 206 fontData->m_Obj = NULL;
170 } 207 }
171 } 208 }
172 pos = m_ColorSpaceMap.GetStartPosition(); 209 pos = m_ColorSpaceMap.GetStartPosition();
173 while (pos) { 210 while (pos) {
174 CPDF_Object* csKey; 211 CPDF_Object* csKey;
175 CPDF_CountedObject<CPDF_ColorSpace*>* csData; 212 CPDF_CountedObject<CPDF_ColorSpace*>* csData;
176 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData); 213 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData);
177 if (!csData->m_Obj) { 214 if (!csData->m_Obj) {
178 continue; 215 continue;
179 } 216 }
180 if (bForceRelease || csData->m_nCount < 2) { 217 if (bForceRelease || csData->m_nCount < 2) {
181 // csData->m_Obj is deleted in the function of ReleaseCS(). 218 // csData->m_Obj is deleted in the function of ReleaseCS().
182 csData->m_Obj->ReleaseCS(); 219 csData->m_Obj->ReleaseCS();
Bo Xu 2014/10/15 21:31:26 Hi Tom, I am trying to put them in a member functi
Tom Sepez 2014/10/15 22:05:37 As a first step, I think its fine to keep this spe
183 csData->m_Obj = NULL; 220 csData->m_Obj = NULL;
184 } 221 }
185 } 222 }
186 pos = m_IccProfileMap.GetStartPosition(); 223 pos = m_IccProfileMap.GetStartPosition();
187 while (pos) { 224 while (pos) {
188 CPDF_Stream* ipKey; 225 CPDF_Stream* ipKey;
189 CPDF_CountedObject<CPDF_IccProfile*>* ipData; 226 CPDF_CountedObject<CPDF_IccProfile*>* ipData;
190 m_IccProfileMap.GetNextAssoc(pos, ipKey, ipData); 227 m_IccProfileMap.GetNextAssoc(pos, ipKey, ipData);
191 if (!ipData->m_Obj) { 228 if (!ipData->m_Obj) {
192 continue; 229 continue;
193 } 230 }
194 if (bForceRelease || ipData->m_nCount < 2) { 231 if (bForceRelease || ipData->m_nCount < 2) {
195 FX_POSITION pos2 = m_HashProfileMap.GetStartPosition(); 232 FX_POSITION pos2 = m_HashProfileMap.GetStartPosition();
196 while (pos2) { 233 while (pos2) {
197 CFX_ByteString bsKey; 234 CFX_ByteString bsKey;
198 CPDF_Stream* pFindStream = NULL; 235 CPDF_Stream* pFindStream = NULL;
199 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStream); 236 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStream);
200 if (ipKey == pFindStream) { 237 if (ipKey == pFindStream) {
201 m_HashProfileMap.RemoveKey(bsKey); 238 m_HashProfileMap.RemoveKey(bsKey);
202 break; 239 break;
203 } 240 }
204 } 241 }
205 delete ipData->m_Obj; 242 delete ipData->m_Obj;
206 ipData->m_Obj = NULL;
207 delete ipData; 243 delete ipData;
208 m_IccProfileMap.RemoveKey(ipKey); 244 m_IccProfileMap.RemoveKey(ipKey);
209 } 245 }
210 } 246 }
211 pos = m_FontFileMap.GetStartPosition(); 247 pos = m_FontFileMap.GetStartPosition();
212 while (pos) { 248 while (pos) {
213 CPDF_Stream* ftKey; 249 CPDF_Stream* ftKey;
214 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; 250 CPDF_CountedObject<CPDF_StreamAcc*>* ftData;
215 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData); 251 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData);
216 if (!ftData->m_Obj) { 252 if (!ftData->m_Obj) {
217 continue; 253 continue;
218 } 254 }
219 if (bForceRelease || ftData->m_nCount < 2) { 255 if (bForceRelease || ftData->m_nCount < 2) {
220 delete ftData->m_Obj; 256 delete ftData->m_Obj;
221 ftData->m_Obj = NULL;
222 delete ftData; 257 delete ftData;
223 m_FontFileMap.RemoveKey(ftKey); 258 m_FontFileMap.RemoveKey(ftKey);
224 } 259 }
225 } 260 }
226 pos = m_PatternMap.GetStartPosition();
227 while (pos) {
228 CPDF_Object* ptObj;
229 CPDF_CountedObject<CPDF_Pattern*>* ptData;
230 m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
231 if (!ptData->m_Obj) {
232 continue;
233 }
234 if (bForceRelease || ptData->m_nCount < 2) {
235 ptData->m_Obj->SetForceClear(bForceRelease);
236 delete ptData->m_Obj;
237 ptData->m_Obj = NULL;
238 }
239 }
240 pos = m_ImageMap.GetStartPosition(); 261 pos = m_ImageMap.GetStartPosition();
241 while (pos) { 262 while (pos) {
242 FX_DWORD objNum; 263 FX_DWORD objNum;
243 CPDF_CountedObject<CPDF_Image*>* imageData; 264 CPDF_CountedObject<CPDF_Image*>* imageData;
244 m_ImageMap.GetNextAssoc(pos, objNum, imageData); 265 m_ImageMap.GetNextAssoc(pos, objNum, imageData);
245 if (!imageData->m_Obj) { 266 if (!imageData->m_Obj) {
246 continue; 267 continue;
247 } 268 }
248 if (bForceRelease || imageData->m_nCount < 2) { 269 if (bForceRelease || imageData->m_nCount < 2) {
249 delete imageData->m_Obj; 270 delete imageData->m_Obj;
250 imageData->m_Obj = NULL;
251 delete imageData; 271 delete imageData;
252 m_ImageMap.RemoveKey(objNum); 272 m_ImageMap.RemoveKey(objNum);
253 } 273 }
254 } 274 }
255 } 275 }
256 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl y) 276 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl y)
257 { 277 {
258 if (!pFontDict) { 278 if (!pFontDict) {
259 return NULL; 279 return NULL;
260 } 280 }
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 m_FontFileMap.SetAt(pFontStream, ftData); 667 m_FontFileMap.SetAt(pFontStream, ftData);
648 return pFontFile; 668 return pFontFile;
649 } 669 }
650 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO L bForce) 670 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO L bForce)
651 { 671 {
652 if (!pFontStream) { 672 if (!pFontStream) {
653 return; 673 return;
654 } 674 }
655 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS tream, NULL, bForce); 675 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS tream, NULL, bForce);
656 } 676 }
677 CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr(CPDF_Object* pCSObj) const
678 {
679 if (!pCSObj) return NULL;
680 CPDF_CountedObject<CPDF_ColorSpace*>* csData;
681 if (m_ColorSpaceMap.Lookup(pCSObj, csData))
682 {
683 return csData;
684 }
685 return NULL;
686 }
687 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr(CPDF_Object* pPatternObj) const
688 {
689 if (!pPatternObj) return NULL;
690 CPDF_CountedObject<CPDF_Pattern*>* ptData;
691 if (m_PatternMap.Lookup(pPatternObj, ptData))
692 {
693 return ptData;
694 }
695 return NULL;
696 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698