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 <algorithm> | 9 #include <algorithm> |
10 #include <set> | 10 #include <set> |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 207 |
208 auto it = m_FontMap.find(pFontDict); | 208 auto it = m_FontMap.find(pFontDict); |
209 if (it == m_FontMap.end()) | 209 if (it == m_FontMap.end()) |
210 return; | 210 return; |
211 | 211 |
212 CPDF_CountedFont* pFontData = it->second; | 212 CPDF_CountedFont* pFontData = it->second; |
213 if (!pFontData->get()) | 213 if (!pFontData->get()) |
214 return; | 214 return; |
215 | 215 |
216 pFontData->RemoveRef(); | 216 pFontData->RemoveRef(); |
217 if (pFontData->use_count() != 0) | 217 if (pFontData->use_count() > 1) |
218 return; | 218 return; |
219 | 219 |
| 220 // We have font data only in m_FontMap cache. Clean it. |
220 pFontData->clear(); | 221 pFontData->clear(); |
221 } | 222 } |
222 | 223 |
223 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace( | 224 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace( |
224 CPDF_Object* pCSObj, | 225 CPDF_Object* pCSObj, |
225 const CPDF_Dictionary* pResources) { | 226 const CPDF_Dictionary* pResources) { |
226 std::set<CPDF_Object*> visited; | 227 std::set<CPDF_Object*> visited; |
227 return GetColorSpaceImpl(pCSObj, pResources, &visited); | 228 return GetColorSpaceImpl(pCSObj, pResources, &visited); |
228 } | 229 } |
229 | 230 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 324 |
324 auto it = m_ColorSpaceMap.find(pColorSpace); | 325 auto it = m_ColorSpaceMap.find(pColorSpace); |
325 if (it == m_ColorSpaceMap.end()) | 326 if (it == m_ColorSpaceMap.end()) |
326 return; | 327 return; |
327 | 328 |
328 CPDF_CountedColorSpace* pCountedColorSpace = it->second; | 329 CPDF_CountedColorSpace* pCountedColorSpace = it->second; |
329 if (!pCountedColorSpace->get()) | 330 if (!pCountedColorSpace->get()) |
330 return; | 331 return; |
331 | 332 |
332 pCountedColorSpace->RemoveRef(); | 333 pCountedColorSpace->RemoveRef(); |
333 if (pCountedColorSpace->use_count() != 0) | 334 if (pCountedColorSpace->use_count() > 1) |
334 return; | 335 return; |
335 | 336 |
| 337 // We have item only in m_ColorSpaceMap cache. Clean it. |
336 pCountedColorSpace->get()->ReleaseCS(); | 338 pCountedColorSpace->get()->ReleaseCS(); |
337 pCountedColorSpace->reset(nullptr); | 339 pCountedColorSpace->reset(nullptr); |
338 } | 340 } |
339 | 341 |
340 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, | 342 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, |
341 FX_BOOL bShading, | 343 FX_BOOL bShading, |
342 const CFX_Matrix& matrix) { | 344 const CFX_Matrix& matrix) { |
343 if (!pPatternObj) | 345 if (!pPatternObj) |
344 return nullptr; | 346 return nullptr; |
345 | 347 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 386 |
385 auto it = m_PatternMap.find(pPatternObj); | 387 auto it = m_PatternMap.find(pPatternObj); |
386 if (it == m_PatternMap.end()) | 388 if (it == m_PatternMap.end()) |
387 return; | 389 return; |
388 | 390 |
389 CPDF_CountedPattern* pPattern = it->second; | 391 CPDF_CountedPattern* pPattern = it->second; |
390 if (!pPattern->get()) | 392 if (!pPattern->get()) |
391 return; | 393 return; |
392 | 394 |
393 pPattern->RemoveRef(); | 395 pPattern->RemoveRef(); |
394 if (pPattern->use_count() != 0) | 396 if (pPattern->use_count() > 1) |
395 return; | 397 return; |
396 | 398 |
| 399 // We have item only in m_PatternMap cache. Clean it. |
397 pPattern->clear(); | 400 pPattern->clear(); |
398 } | 401 } |
399 | 402 |
400 CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream) { | 403 CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream) { |
401 if (!pImageStream) | 404 if (!pImageStream) |
402 return nullptr; | 405 return nullptr; |
403 | 406 |
404 const uint32_t dwImageObjNum = pImageStream->GetObjNum(); | 407 const uint32_t dwImageObjNum = pImageStream->GetObjNum(); |
405 auto it = m_ImageMap.find(dwImageObjNum); | 408 auto it = m_ImageMap.find(dwImageObjNum); |
406 if (it != m_ImageMap.end()) | 409 if (it != m_ImageMap.end()) |
(...skipping 15 matching lines...) Expand all Loading... |
422 | 425 |
423 auto it = m_ImageMap.find(dwObjNum); | 426 auto it = m_ImageMap.find(dwObjNum); |
424 if (it == m_ImageMap.end()) | 427 if (it == m_ImageMap.end()) |
425 return; | 428 return; |
426 | 429 |
427 CPDF_CountedImage* pCountedImage = it->second; | 430 CPDF_CountedImage* pCountedImage = it->second; |
428 if (!pCountedImage) | 431 if (!pCountedImage) |
429 return; | 432 return; |
430 | 433 |
431 pCountedImage->RemoveRef(); | 434 pCountedImage->RemoveRef(); |
432 if (pCountedImage->use_count() != 0) | 435 if (pCountedImage->use_count() > 1) |
433 return; | 436 return; |
434 | 437 |
| 438 // We have item only in m_ImageMap cache. Clean it. |
435 delete pCountedImage->get(); | 439 delete pCountedImage->get(); |
436 delete pCountedImage; | 440 delete pCountedImage; |
437 m_ImageMap.erase(it); | 441 m_ImageMap.erase(it); |
438 } | 442 } |
439 | 443 |
440 CPDF_IccProfile* CPDF_DocPageData::GetIccProfile( | 444 CPDF_IccProfile* CPDF_DocPageData::GetIccProfile( |
441 CPDF_Stream* pIccProfileStream) { | 445 CPDF_Stream* pIccProfileStream) { |
442 if (!pIccProfileStream) | 446 if (!pIccProfileStream) |
443 return nullptr; | 447 return nullptr; |
444 | 448 |
445 auto it = m_IccProfileMap.find(pIccProfileStream); | 449 auto it = m_IccProfileMap.find(pIccProfileStream); |
446 if (it != m_IccProfileMap.end()) | 450 if (it != m_IccProfileMap.end()) |
447 return it->second->AddRef(); | 451 return it->second->AddRef(); |
448 | 452 |
449 CPDF_StreamAcc stream; | 453 CPDF_StreamAcc stream; |
450 stream.LoadAllData(pIccProfileStream, FALSE); | 454 stream.LoadAllData(pIccProfileStream, FALSE); |
451 uint8_t digest[20]; | 455 uint8_t digest[20]; |
452 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); | 456 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); |
453 CFX_ByteString bsDigest(digest, 20); | 457 CFX_ByteString bsDigest(digest, 20); |
454 auto hash_it = m_HashProfileMap.find(bsDigest); | 458 auto hash_it = m_HashProfileMap.find(bsDigest); |
455 if (hash_it != m_HashProfileMap.end()) { | 459 if (hash_it != m_HashProfileMap.end()) { |
456 auto it_copied_stream = m_IccProfileMap.find(hash_it->second); | 460 auto it_copied_stream = m_IccProfileMap.find(hash_it->second); |
457 return it_copied_stream->second->AddRef(); | 461 if (it_copied_stream != m_IccProfileMap.end()) |
| 462 return it_copied_stream->second->AddRef(); |
458 } | 463 } |
459 CPDF_IccProfile* pProfile = | 464 CPDF_IccProfile* pProfile = |
460 new CPDF_IccProfile(stream.GetData(), stream.GetSize()); | 465 new CPDF_IccProfile(stream.GetData(), stream.GetSize()); |
461 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile); | 466 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile); |
462 m_IccProfileMap[pIccProfileStream] = ipData; | 467 m_IccProfileMap[pIccProfileStream] = ipData; |
463 m_HashProfileMap[bsDigest] = pIccProfileStream; | 468 m_HashProfileMap[bsDigest] = pIccProfileStream; |
464 return ipData->AddRef(); | 469 return ipData->AddRef(); |
465 } | 470 } |
466 | 471 |
467 void CPDF_DocPageData::ReleaseIccProfile(const CPDF_IccProfile* pIccProfile) { | 472 void CPDF_DocPageData::ReleaseIccProfile(const CPDF_IccProfile* pIccProfile) { |
468 ASSERT(pIccProfile); | 473 ASSERT(pIccProfile); |
469 | 474 |
470 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end(); ++it) { | 475 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end(); ++it) { |
471 CPDF_CountedIccProfile* profile = it->second; | 476 CPDF_CountedIccProfile* profile = it->second; |
472 if (profile->get() != pIccProfile) | 477 if (profile->get() != pIccProfile) |
473 continue; | 478 continue; |
474 | 479 |
475 profile->RemoveRef(); | 480 profile->RemoveRef(); |
476 if (profile->use_count() == 0) { | 481 if (profile->use_count() > 1) |
477 delete profile->get(); | 482 continue; |
478 delete profile; | 483 // We have item only in m_IccProfileMap cache. Clean it. |
479 m_IccProfileMap.erase(it); | 484 delete profile->get(); |
480 return; | 485 delete profile; |
481 } | 486 m_IccProfileMap.erase(it); |
| 487 return; |
482 } | 488 } |
483 } | 489 } |
484 | 490 |
485 CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc( | 491 CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc( |
486 CPDF_Stream* pFontStream) { | 492 CPDF_Stream* pFontStream) { |
487 ASSERT(pFontStream); | 493 ASSERT(pFontStream); |
488 | 494 |
489 auto it = m_FontFileMap.find(pFontStream); | 495 auto it = m_FontFileMap.find(pFontStream); |
490 if (it != m_FontFileMap.end()) | 496 if (it != m_FontFileMap.end()) |
491 return it->second->AddRef(); | 497 return it->second->AddRef(); |
(...skipping 19 matching lines...) Expand all Loading... |
511 | 517 |
512 auto it = m_FontFileMap.find(pFontStream); | 518 auto it = m_FontFileMap.find(pFontStream); |
513 if (it == m_FontFileMap.end()) | 519 if (it == m_FontFileMap.end()) |
514 return; | 520 return; |
515 | 521 |
516 CPDF_CountedStreamAcc* pCountedStream = it->second; | 522 CPDF_CountedStreamAcc* pCountedStream = it->second; |
517 if (!pCountedStream) | 523 if (!pCountedStream) |
518 return; | 524 return; |
519 | 525 |
520 pCountedStream->RemoveRef(); | 526 pCountedStream->RemoveRef(); |
521 if (pCountedStream->use_count() != 0) | 527 if (pCountedStream->use_count() > 1) |
522 return; | 528 return; |
523 | 529 |
| 530 // We have item only in m_FontFileMap cache. Clean it. |
524 delete pCountedStream->get(); | 531 delete pCountedStream->get(); |
525 delete pCountedStream; | 532 delete pCountedStream; |
526 m_FontFileMap.erase(it); | 533 m_FontFileMap.erase(it); |
527 } | 534 } |
528 | 535 |
529 CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr( | 536 CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr( |
530 CPDF_Object* pCSObj) const { | 537 CPDF_Object* pCSObj) const { |
531 if (!pCSObj) | 538 if (!pCSObj) |
532 return nullptr; | 539 return nullptr; |
533 | 540 |
534 auto it = m_ColorSpaceMap.find(pCSObj); | 541 auto it = m_ColorSpaceMap.find(pCSObj); |
535 return it != m_ColorSpaceMap.end() ? it->second : nullptr; | 542 return it != m_ColorSpaceMap.end() ? it->second : nullptr; |
536 } | 543 } |
537 | 544 |
538 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( | 545 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( |
539 CPDF_Object* pPatternObj) const { | 546 CPDF_Object* pPatternObj) const { |
540 if (!pPatternObj) | 547 if (!pPatternObj) |
541 return nullptr; | 548 return nullptr; |
542 | 549 |
543 auto it = m_PatternMap.find(pPatternObj); | 550 auto it = m_PatternMap.find(pPatternObj); |
544 return it != m_PatternMap.end() ? it->second : nullptr; | 551 return it != m_PatternMap.end() ? it->second : nullptr; |
545 } | 552 } |
OLD | NEW |