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 "core/fpdfapi/fpdf_page/pageint.h" | 7 #include "core/fpdfapi/fpdf_page/pageint.h" |
8 | 8 |
9 #include "core/fdrm/crypto/include/fx_crypt.h" | 9 #include "core/fdrm/crypto/include/fx_crypt.h" |
10 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h" | 10 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h" |
11 #include "core/fpdfapi/fpdf_font/font_int.h" | 11 #include "core/fpdfapi/fpdf_font/font_int.h" |
12 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" | 12 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" |
13 #include "core/fpdfapi/fpdf_page/cpdf_pattern.h" | 13 #include "core/fpdfapi/fpdf_page/cpdf_pattern.h" |
14 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" | 14 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" |
15 #include "core/fpdfapi/fpdf_page/cpdf_tilingpattern.h" | 15 #include "core/fpdfapi/fpdf_page/cpdf_tilingpattern.h" |
16 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" | 16 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" |
17 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 17 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
18 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 18 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
19 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 19 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
20 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" | 20 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" |
21 #include "core/fpdfapi/include/cpdf_modulemgr.h" | 21 #include "core/fpdfapi/include/cpdf_modulemgr.h" |
| 22 #include "third_party/base/stl_util.h" |
22 | 23 |
23 void CPDF_ModuleMgr::InitPageModule() { | 24 void CPDF_ModuleMgr::InitPageModule() { |
24 m_pPageModule.reset(new CPDF_PageModule); | 25 m_pPageModule.reset(new CPDF_PageModule); |
25 } | 26 } |
26 | 27 |
27 CPDF_DocPageData::CPDF_DocPageData(CPDF_Document* pPDFDoc) | 28 CPDF_DocPageData::CPDF_DocPageData(CPDF_Document* pPDFDoc) |
28 : m_pPDFDoc(pPDFDoc), m_bForceClear(FALSE) {} | 29 : m_pPDFDoc(pPDFDoc), m_bForceClear(FALSE) {} |
29 | 30 |
30 CPDF_DocPageData::~CPDF_DocPageData() { | 31 CPDF_DocPageData::~CPDF_DocPageData() { |
31 Clear(FALSE); | 32 Clear(FALSE); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 fontData->RemoveRef(); | 216 fontData->RemoveRef(); |
216 if (fontData->use_count() == 0) { | 217 if (fontData->use_count() == 0) { |
217 fontData->clear(); | 218 fontData->clear(); |
218 } | 219 } |
219 } | 220 } |
220 } | 221 } |
221 | 222 |
222 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace( | 223 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace( |
223 CPDF_Object* pCSObj, | 224 CPDF_Object* pCSObj, |
224 const CPDF_Dictionary* pResources) { | 225 const CPDF_Dictionary* pResources) { |
| 226 std::set<CPDF_Object*> visited; |
| 227 return GetColorSpaceImpl(pCSObj, pResources, &visited); |
| 228 } |
| 229 |
| 230 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpaceImpl( |
| 231 CPDF_Object* pCSObj, |
| 232 const CPDF_Dictionary* pResources, |
| 233 std::set<CPDF_Object*>* pVisited) { |
225 if (!pCSObj) | 234 if (!pCSObj) |
226 return nullptr; | 235 return nullptr; |
227 | 236 |
| 237 if (pdfium::ContainsKey(*pVisited, pCSObj)) |
| 238 return nullptr; |
| 239 |
228 if (pCSObj->IsName()) { | 240 if (pCSObj->IsName()) { |
229 CFX_ByteString name = pCSObj->GetString(); | 241 CFX_ByteString name = pCSObj->GetString(); |
230 CPDF_ColorSpace* pCS = CPDF_ColorSpace::ColorspaceFromName(name); | 242 CPDF_ColorSpace* pCS = CPDF_ColorSpace::ColorspaceFromName(name); |
231 if (!pCS && pResources) { | 243 if (!pCS && pResources) { |
232 CPDF_Dictionary* pList = pResources->GetDictBy("ColorSpace"); | 244 CPDF_Dictionary* pList = pResources->GetDictBy("ColorSpace"); |
233 if (pList) { | 245 if (pList) { |
234 pCSObj = pList->GetDirectObjectBy(name); | 246 pdfium::ScopedSetInsertion<CPDF_Object*> insertion(pVisited, pCSObj); |
235 return GetColorSpace(pCSObj, nullptr); | 247 return GetColorSpaceImpl(pList->GetDirectObjectBy(name), nullptr, |
| 248 pVisited); |
236 } | 249 } |
237 } | 250 } |
238 if (!pCS || !pResources) | 251 if (!pCS || !pResources) |
239 return pCS; | 252 return pCS; |
240 | 253 |
241 CPDF_Dictionary* pColorSpaces = pResources->GetDictBy("ColorSpace"); | 254 CPDF_Dictionary* pColorSpaces = pResources->GetDictBy("ColorSpace"); |
242 if (!pColorSpaces) | 255 if (!pColorSpaces) |
243 return pCS; | 256 return pCS; |
244 | 257 |
245 CPDF_Object* pDefaultCS = nullptr; | 258 CPDF_Object* pDefaultCS = nullptr; |
246 switch (pCS->GetFamily()) { | 259 switch (pCS->GetFamily()) { |
247 case PDFCS_DEVICERGB: | 260 case PDFCS_DEVICERGB: |
248 pDefaultCS = pColorSpaces->GetDirectObjectBy("DefaultRGB"); | 261 pDefaultCS = pColorSpaces->GetDirectObjectBy("DefaultRGB"); |
249 break; | 262 break; |
250 case PDFCS_DEVICEGRAY: | 263 case PDFCS_DEVICEGRAY: |
251 pDefaultCS = pColorSpaces->GetDirectObjectBy("DefaultGray"); | 264 pDefaultCS = pColorSpaces->GetDirectObjectBy("DefaultGray"); |
252 break; | 265 break; |
253 case PDFCS_DEVICECMYK: | 266 case PDFCS_DEVICECMYK: |
254 pDefaultCS = pColorSpaces->GetDirectObjectBy("DefaultCMYK"); | 267 pDefaultCS = pColorSpaces->GetDirectObjectBy("DefaultCMYK"); |
255 break; | 268 break; |
256 } | 269 } |
257 return pDefaultCS ? GetColorSpace(pDefaultCS, nullptr) : pCS; | 270 if (!pDefaultCS) |
| 271 return pCS; |
| 272 |
| 273 pdfium::ScopedSetInsertion<CPDF_Object*> insertion(pVisited, pCSObj); |
| 274 return GetColorSpaceImpl(pDefaultCS, nullptr, pVisited); |
258 } | 275 } |
259 | 276 |
260 CPDF_Array* pArray = pCSObj->AsArray(); | 277 CPDF_Array* pArray = pCSObj->AsArray(); |
261 if (!pArray || pArray->GetCount() == 0) | 278 if (!pArray || pArray->GetCount() == 0) |
262 return nullptr; | 279 return nullptr; |
263 if (pArray->GetCount() == 1) | 280 |
264 return GetColorSpace(pArray->GetDirectObjectAt(0), pResources); | 281 if (pArray->GetCount() == 1) { |
| 282 pdfium::ScopedSetInsertion<CPDF_Object*> insertion(pVisited, pCSObj); |
| 283 return GetColorSpaceImpl(pArray->GetDirectObjectAt(0), pResources, |
| 284 pVisited); |
| 285 } |
265 | 286 |
266 CPDF_CountedColorSpace* csData = nullptr; | 287 CPDF_CountedColorSpace* csData = nullptr; |
267 auto it = m_ColorSpaceMap.find(pCSObj); | 288 auto it = m_ColorSpaceMap.find(pCSObj); |
268 if (it != m_ColorSpaceMap.end()) { | 289 if (it != m_ColorSpaceMap.end()) { |
269 csData = it->second; | 290 csData = it->second; |
270 if (csData->get()) { | 291 if (csData->get()) { |
271 return csData->AddRef(); | 292 return csData->AddRef(); |
272 } | 293 } |
273 } | 294 } |
274 | 295 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 } | 532 } |
512 | 533 |
513 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( | 534 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( |
514 CPDF_Object* pPatternObj) const { | 535 CPDF_Object* pPatternObj) const { |
515 if (!pPatternObj) | 536 if (!pPatternObj) |
516 return nullptr; | 537 return nullptr; |
517 | 538 |
518 auto it = m_PatternMap.find(pPatternObj); | 539 auto it = m_PatternMap.find(pPatternObj); |
519 return it != m_PatternMap.end() ? it->second : nullptr; | 540 return it != m_PatternMap.end() ? it->second : nullptr; |
520 } | 541 } |
OLD | NEW |