Chromium Code Reviews| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 } | 150 } |
| 151 void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) | 151 void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) |
| 152 { | 152 { |
| 153 FX_POSITION pos; | 153 FX_POSITION pos; |
| 154 FX_DWORD nCount; | |
| 155 | 154 |
| 156 m_bForceClear = bForceRelease; | 155 m_bForceClear = bForceRelease; |
| 157 pos = m_FontMap.GetStartPosition(); | 156 pos = m_FontMap.GetStartPosition(); |
| 158 while (pos) { | 157 while (pos) { |
| 159 CPDF_Dictionary* fontDict; | 158 CPDF_Dictionary* fontDict; |
| 160 CPDF_CountedObject<CPDF_Font*>* fontData; | 159 CPDF_CountedObject<CPDF_Font*>* fontData; |
| 161 m_FontMap.GetNextAssoc(pos, fontDict, fontData); | 160 m_FontMap.GetNextAssoc(pos, fontDict, fontData); |
| 162 nCount = fontData->m_nCount; | 161 if (!fontData || !fontData->m_Obj) { |
|
Tom Sepez
2014/09/19 18:33:13
Can any of these return NULL fontData, etc. The o
| |
| 163 if (bForceRelease || nCount < 2) { | 162 continue; |
| 163 } | |
| 164 if (bForceRelease || fontData->m_nCount < 2) { | |
| 164 delete fontData->m_Obj; | 165 delete fontData->m_Obj; |
| 165 fontData->m_Obj = NULL; | 166 fontData->m_Obj = NULL; |
| 166 } | 167 } |
| 167 } | 168 } |
| 168 pos = m_ImageMap.GetStartPosition(); | |
| 169 while (pos) { | |
| 170 FX_DWORD objNum; | |
| 171 CPDF_CountedObject<CPDF_Image*>* imageData; | |
| 172 m_ImageMap.GetNextAssoc(pos, objNum, imageData); | |
| 173 nCount = imageData->m_nCount; | |
| 174 if (bForceRelease || nCount < 2) { | |
| 175 delete imageData->m_Obj; | |
| 176 delete imageData; | |
| 177 m_ImageMap.RemoveKey(objNum); | |
| 178 } | |
| 179 } | |
| 180 pos = m_ColorSpaceMap.GetStartPosition(); | 169 pos = m_ColorSpaceMap.GetStartPosition(); |
| 181 while (pos) { | 170 while (pos) { |
| 182 CPDF_Object* csKey; | 171 CPDF_Object* csKey; |
| 183 CPDF_CountedObject<CPDF_ColorSpace*>* csData; | 172 CPDF_CountedObject<CPDF_ColorSpace*>* csData; |
| 184 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData); | 173 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData); |
| 185 nCount = csData->m_nCount; | 174 if (!csData || !csData->m_Obj) { |
| 186 if (bForceRelease || nCount < 2) { | 175 continue; |
| 176 } | |
| 177 if (bForceRelease || csData->m_nCount < 2) { | |
| 187 csData->m_Obj->ReleaseCS(); | 178 csData->m_Obj->ReleaseCS(); |
| 188 csData->m_Obj = NULL; | 179 csData->m_Obj = NULL; |
| 189 } | 180 } |
| 190 } | 181 } |
| 191 pos = m_IccProfileMap.GetStartPosition(); | 182 pos = m_IccProfileMap.GetStartPosition(); |
| 192 while (pos) { | 183 while (pos) { |
| 193 CPDF_Stream* ipKey; | 184 CPDF_Stream* ipKey; |
| 194 CPDF_CountedObject<CPDF_IccProfile*>* ipData; | 185 CPDF_CountedObject<CPDF_IccProfile*>* ipData; |
| 195 m_IccProfileMap.GetNextAssoc(pos, ipKey, ipData); | 186 m_IccProfileMap.GetNextAssoc(pos, ipKey, ipData); |
| 196 nCount = ipData->m_nCount; | 187 if (!ipKey || !ipData) { |
|
Tom Sepez
2014/09/19 18:33:13
Don't think these can be NULL, can they?
| |
| 197 if (bForceRelease || nCount < 2) { | 188 continue; |
| 189 } | |
| 190 if (bForceRelease || ipData->m_nCount < 2) { | |
| 198 FX_POSITION pos2 = m_HashProfileMap.GetStartPosition(); | 191 FX_POSITION pos2 = m_HashProfileMap.GetStartPosition(); |
| 199 while (pos2) { | 192 while (pos2) { |
| 200 CFX_ByteString bsKey; | 193 CFX_ByteString bsKey; |
| 201 CPDF_Stream* pFindStream = NULL; | 194 CPDF_Stream* pFindStream = NULL; |
| 202 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStream); | 195 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStream); |
| 203 if (ipKey == pFindStream) { | 196 if (ipKey == pFindStream) { |
| 204 m_HashProfileMap.RemoveKey(bsKey); | 197 m_HashProfileMap.RemoveKey(bsKey); |
| 205 break; | 198 break; |
| 206 } | 199 } |
| 207 } | 200 } |
| 208 delete ipData->m_Obj; | 201 if (ipData->m_Obj) { |
| 202 delete ipData->m_Obj; | |
| 203 ipData->m_Obj = NULL; | |
| 204 } | |
| 209 delete ipData; | 205 delete ipData; |
| 210 m_IccProfileMap.RemoveKey(ipKey); | 206 m_IccProfileMap.RemoveKey(ipKey); |
|
Tom Sepez
2014/09/19 18:33:13
nit: I always feel a little squeamish about deleti
| |
| 211 } | 207 } |
| 212 } | 208 } |
| 213 pos = m_FontFileMap.GetStartPosition(); | 209 pos = m_FontFileMap.GetStartPosition(); |
| 214 while (pos) { | 210 while (pos) { |
| 215 CPDF_Stream* ftKey; | 211 CPDF_Stream* ftKey; |
| 216 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; | 212 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; |
| 217 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData); | 213 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData); |
| 218 nCount = ftData->m_nCount; | 214 if (!ftData) { |
|
Tom Sepez
2014/09/19 18:33:13
same here.
| |
| 219 if (bForceRelease || nCount < 2) { | 215 continue; |
| 220 delete ftData->m_Obj; | 216 } |
| 217 if (bForceRelease || ftData->m_nCount < 2) { | |
| 218 if (ftData->m_Obj) { | |
| 219 delete ftData->m_Obj; | |
| 220 ftData->m_Obj = NULL; | |
| 221 } | |
| 221 delete ftData; | 222 delete ftData; |
| 222 m_FontFileMap.RemoveKey(ftKey); | 223 if (ftKey) { |
| 224 m_FontFileMap.RemoveKey(ftKey); | |
| 225 } | |
| 223 } | 226 } |
| 224 } | 227 } |
| 225 pos = m_PatternMap.GetStartPosition(); | 228 pos = m_PatternMap.GetStartPosition(); |
| 226 while (pos) { | 229 while (pos) { |
| 227 CPDF_Object* ptObj; | 230 CPDF_Object* ptObj; |
| 228 CPDF_CountedObject<CPDF_Pattern*>* ptData; | 231 CPDF_CountedObject<CPDF_Pattern*>* ptData; |
| 229 m_PatternMap.GetNextAssoc(pos, ptObj, ptData); | 232 m_PatternMap.GetNextAssoc(pos, ptObj, ptData); |
| 230 nCount = ptData->m_nCount; | 233 if (!ptData || !ptData->m_Obj) { |
| 231 if (bForceRelease || nCount < 2) { | 234 continue; |
| 235 } | |
| 236 if (bForceRelease || ptData->m_nCount < 2) { | |
| 232 ptData->m_Obj->SetForceClear(bForceRelease); | 237 ptData->m_Obj->SetForceClear(bForceRelease); |
| 233 delete ptData->m_Obj; | 238 delete ptData->m_Obj; |
| 234 ptData->m_Obj = NULL; | 239 ptData->m_Obj = NULL; |
| 235 } | 240 } |
| 236 } | 241 } |
| 242 pos = m_ImageMap.GetStartPosition(); | |
| 243 while (pos) { | |
| 244 FX_DWORD objNum; | |
| 245 CPDF_CountedObject<CPDF_Image*>* imageData; | |
| 246 m_ImageMap.GetNextAssoc(pos, objNum, imageData); | |
| 247 if (!imageData) { | |
|
Tom Sepez
2014/09/19 18:33:13
same here.
| |
| 248 continue; | |
| 249 } | |
| 250 if (bForceRelease || imageData->m_nCount < 2) { | |
| 251 if (imageData->m_Obj) { | |
| 252 delete imageData->m_Obj; | |
| 253 imageData->m_Obj = NULL; | |
| 254 } | |
| 255 delete imageData; | |
| 256 m_ImageMap.RemoveKey(objNum); | |
| 257 } | |
| 258 } | |
| 237 } | 259 } |
| 238 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl y) | 260 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl y) |
| 239 { | 261 { |
| 240 if (!pFontDict) { | 262 if (!pFontDict) { |
| 241 return NULL; | 263 return NULL; |
| 242 } | 264 } |
| 243 if (findOnly) { | 265 if (findOnly) { |
| 244 CPDF_CountedObject<CPDF_Font*>* fontData; | 266 CPDF_CountedObject<CPDF_Font*>* fontData; |
| 245 if (m_FontMap.Lookup(pFontDict, fontData)) { | 267 if (m_FontMap.Lookup(pFontDict, fontData)) { |
| 246 if (!fontData->m_Obj) { | 268 if (!fontData->m_Obj) { |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 m_FontFileMap.SetAt(pFontStream, ftData); | 651 m_FontFileMap.SetAt(pFontStream, ftData); |
| 630 return pFontFile; | 652 return pFontFile; |
| 631 } | 653 } |
| 632 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO L bForce) | 654 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO L bForce) |
| 633 { | 655 { |
| 634 if (!pFontStream) { | 656 if (!pFontStream) { |
| 635 return; | 657 return; |
| 636 } | 658 } |
| 637 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS tream, NULL, bForce); | 659 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS tream, NULL, bForce); |
| 638 } | 660 } |
| OLD | NEW |