| OLD | NEW |
| 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 Loading... |
| 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 = NULL; |
| 151 pos = m_PatternMap.GetStartPosition(); |
| 152 while (pos) |
| 153 { |
| 154 CPDF_Object* ptObj; |
| 155 CPDF_CountedObject<CPDF_Pattern*>* ptData; |
| 156 m_PatternMap.GetNextAssoc(pos, ptObj, ptData); |
| 157 delete ptData; |
| 158 } |
| 159 m_PatternMap.RemoveAll(); |
| 160 pos = m_FontMap.GetStartPosition(); |
| 161 while (pos) |
| 162 { |
| 163 CPDF_Dictionary* fontDict; |
| 164 CPDF_CountedObject<CPDF_Font*>* fontData; |
| 165 m_FontMap.GetNextAssoc(pos, fontDict, fontData); |
| 166 delete fontData; |
| 167 } |
| 168 m_FontMap.RemoveAll(); |
| 169 pos = m_ColorSpaceMap.GetStartPosition(); |
| 170 while (pos) |
| 171 { |
| 172 CPDF_Object* csKey; |
| 173 CPDF_CountedObject<CPDF_ColorSpace*>* csData; |
| 174 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData); |
| 175 delete csData; |
| 176 } |
| 177 m_ColorSpaceMap.RemoveAll(); |
| 150 } | 178 } |
| 151 void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) | 179 void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) |
| 152 { | 180 { |
| 153 FX_POSITION pos; | 181 FX_POSITION pos; |
| 154 | |
| 155 m_bForceClear = bForceRelease; | 182 m_bForceClear = bForceRelease; |
| 156 | 183 pos = m_PatternMap.GetStartPosition(); |
| 157 // Release objects saved in the resource maps like font map and color space
map. | 184 while (pos) { |
| 158 // The compound objects shall be released before simple ones. | 185 CPDF_Object* ptObj; |
| 186 CPDF_CountedObject<CPDF_Pattern*>* ptData; |
| 187 m_PatternMap.GetNextAssoc(pos, ptObj, ptData); |
| 188 if (!ptData->m_Obj) { |
| 189 continue; |
| 190 } |
| 191 if (bForceRelease || ptData->m_nCount < 2) { |
| 192 ptData->m_Obj->SetForceClear(bForceRelease); |
| 193 delete ptData->m_Obj; |
| 194 ptData->m_Obj = NULL; |
| 195 } |
| 196 } |
| 159 pos = m_FontMap.GetStartPosition(); | 197 pos = m_FontMap.GetStartPosition(); |
| 160 while (pos) { | 198 while (pos) { |
| 161 CPDF_Dictionary* fontDict; | 199 CPDF_Dictionary* fontDict; |
| 162 CPDF_CountedObject<CPDF_Font*>* fontData; | 200 CPDF_CountedObject<CPDF_Font*>* fontData; |
| 163 m_FontMap.GetNextAssoc(pos, fontDict, fontData); | 201 m_FontMap.GetNextAssoc(pos, fontDict, fontData); |
| 164 if (!fontData->m_Obj) { | 202 if (!fontData->m_Obj) { |
| 165 continue; | 203 continue; |
| 166 } | 204 } |
| 167 if (bForceRelease || fontData->m_nCount < 2) { | 205 if (bForceRelease || fontData->m_nCount < 2) { |
| 168 delete fontData->m_Obj; | 206 delete fontData->m_Obj; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 196 while (pos2) { | 234 while (pos2) { |
| 197 CFX_ByteString bsKey; | 235 CFX_ByteString bsKey; |
| 198 CPDF_Stream* pFindStream = NULL; | 236 CPDF_Stream* pFindStream = NULL; |
| 199 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStream); | 237 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStream); |
| 200 if (ipKey == pFindStream) { | 238 if (ipKey == pFindStream) { |
| 201 m_HashProfileMap.RemoveKey(bsKey); | 239 m_HashProfileMap.RemoveKey(bsKey); |
| 202 break; | 240 break; |
| 203 } | 241 } |
| 204 } | 242 } |
| 205 delete ipData->m_Obj; | 243 delete ipData->m_Obj; |
| 206 ipData->m_Obj = NULL; | |
| 207 delete ipData; | 244 delete ipData; |
| 208 m_IccProfileMap.RemoveKey(ipKey); | 245 m_IccProfileMap.RemoveKey(ipKey); |
| 209 } | 246 } |
| 210 } | 247 } |
| 211 pos = m_FontFileMap.GetStartPosition(); | 248 pos = m_FontFileMap.GetStartPosition(); |
| 212 while (pos) { | 249 while (pos) { |
| 213 CPDF_Stream* ftKey; | 250 CPDF_Stream* ftKey; |
| 214 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; | 251 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; |
| 215 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData); | 252 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData); |
| 216 if (!ftData->m_Obj) { | 253 if (!ftData->m_Obj) { |
| 217 continue; | 254 continue; |
| 218 } | 255 } |
| 219 if (bForceRelease || ftData->m_nCount < 2) { | 256 if (bForceRelease || ftData->m_nCount < 2) { |
| 220 delete ftData->m_Obj; | 257 delete ftData->m_Obj; |
| 221 ftData->m_Obj = NULL; | |
| 222 delete ftData; | 258 delete ftData; |
| 223 m_FontFileMap.RemoveKey(ftKey); | 259 m_FontFileMap.RemoveKey(ftKey); |
| 224 } | 260 } |
| 225 } | 261 } |
| 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(); | 262 pos = m_ImageMap.GetStartPosition(); |
| 241 while (pos) { | 263 while (pos) { |
| 242 FX_DWORD objNum; | 264 FX_DWORD objNum; |
| 243 CPDF_CountedObject<CPDF_Image*>* imageData; | 265 CPDF_CountedObject<CPDF_Image*>* imageData; |
| 244 m_ImageMap.GetNextAssoc(pos, objNum, imageData); | 266 m_ImageMap.GetNextAssoc(pos, objNum, imageData); |
| 245 if (!imageData->m_Obj) { | 267 if (!imageData->m_Obj) { |
| 246 continue; | 268 continue; |
| 247 } | 269 } |
| 248 if (bForceRelease || imageData->m_nCount < 2) { | 270 if (bForceRelease || imageData->m_nCount < 2) { |
| 249 delete imageData->m_Obj; | 271 delete imageData->m_Obj; |
| 250 imageData->m_Obj = NULL; | |
| 251 delete imageData; | 272 delete imageData; |
| 252 m_ImageMap.RemoveKey(objNum); | 273 m_ImageMap.RemoveKey(objNum); |
| 253 } | 274 } |
| 254 } | 275 } |
| 255 } | 276 } |
| 256 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl
y) | 277 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl
y) |
| 257 { | 278 { |
| 258 if (!pFontDict) { | 279 if (!pFontDict) { |
| 259 return NULL; | 280 return NULL; |
| 260 } | 281 } |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 m_FontFileMap.SetAt(pFontStream, ftData); | 668 m_FontFileMap.SetAt(pFontStream, ftData); |
| 648 return pFontFile; | 669 return pFontFile; |
| 649 } | 670 } |
| 650 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO
L bForce) | 671 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO
L bForce) |
| 651 { | 672 { |
| 652 if (!pFontStream) { | 673 if (!pFontStream) { |
| 653 return; | 674 return; |
| 654 } | 675 } |
| 655 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS
tream, NULL, bForce); | 676 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS
tream, NULL, bForce); |
| 656 } | 677 } |
| 678 CPDF_ColorSpace** CPDF_DocPageData::FindColorSpacePtr(CPDF_Object* pCSObj) |
| 679 { |
| 680 if (!pCSObj) return NULL; |
| 681 CPDF_CountedObject<CPDF_ColorSpace*>* csData; |
| 682 if (m_ColorSpaceMap.Lookup(pCSObj, csData)) |
| 683 { |
| 684 return &csData->m_Obj; |
| 685 } |
| 686 return NULL; |
| 687 } |
| 688 CPDF_Pattern** CPDF_DocPageData::FindPatternPtr(CPDF_Object* pPatternObj) |
| 689 { |
| 690 if (!pPatternObj) return NULL; |
| 691 CPDF_CountedObject<CPDF_Pattern*>* ptData; |
| 692 if (m_PatternMap.Lookup(pPatternObj, ptData)) |
| 693 { |
| 694 return &ptData->m_Obj; |
| 695 } |
| 696 return NULL; |
| 697 } |
| OLD | NEW |