| 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/page/cpdf_docpagedata.h" | 7 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <utility> |
| 12 | 13 |
| 13 #include "core/fdrm/crypto/fx_crypt.h" | 14 #include "core/fdrm/crypto/fx_crypt.h" |
| 14 #include "core/fpdfapi/cpdf_modulemgr.h" | 15 #include "core/fpdfapi/cpdf_modulemgr.h" |
| 15 #include "core/fpdfapi/font/cpdf_type1font.h" | 16 #include "core/fpdfapi/font/cpdf_type1font.h" |
| 16 #include "core/fpdfapi/font/font_int.h" | 17 #include "core/fpdfapi/font/font_int.h" |
| 17 #include "core/fpdfapi/page/cpdf_image.h" | 18 #include "core/fpdfapi/page/cpdf_image.h" |
| 18 #include "core/fpdfapi/page/cpdf_pagemodule.h" | 19 #include "core/fpdfapi/page/cpdf_pagemodule.h" |
| 19 #include "core/fpdfapi/page/cpdf_pattern.h" | 20 #include "core/fpdfapi/page/cpdf_pattern.h" |
| 20 #include "core/fpdfapi/page/cpdf_shadingpattern.h" | 21 #include "core/fpdfapi/page/cpdf_shadingpattern.h" |
| 21 #include "core/fpdfapi/page/cpdf_tilingpattern.h" | 22 #include "core/fpdfapi/page/cpdf_tilingpattern.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 pFontData = it->second; | 137 pFontData = it->second; |
| 137 if (pFontData->get()) { | 138 if (pFontData->get()) { |
| 138 return pFontData->AddRef(); | 139 return pFontData->AddRef(); |
| 139 } | 140 } |
| 140 } | 141 } |
| 141 std::unique_ptr<CPDF_Font> pFont = CPDF_Font::Create(m_pPDFDoc, pFontDict); | 142 std::unique_ptr<CPDF_Font> pFont = CPDF_Font::Create(m_pPDFDoc, pFontDict); |
| 142 if (!pFont) | 143 if (!pFont) |
| 143 return nullptr; | 144 return nullptr; |
| 144 | 145 |
| 145 if (pFontData) { | 146 if (pFontData) { |
| 146 pFontData->reset(pFont.release()); | 147 pFontData->reset(std::move(pFont)); |
| 147 } else { | 148 } else { |
| 148 pFontData = new CPDF_CountedFont(pFont.release()); | 149 pFontData = new CPDF_CountedFont(std::move(pFont)); |
| 149 m_FontMap[pFontDict] = pFontData; | 150 m_FontMap[pFontDict] = pFontData; |
| 150 } | 151 } |
| 151 return pFontData->AddRef(); | 152 return pFontData->AddRef(); |
| 152 } | 153 } |
| 153 | 154 |
| 154 CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteString& fontName, | 155 CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteString& fontName, |
| 155 CPDF_FontEncoding* pEncoding) { | 156 CPDF_FontEncoding* pEncoding) { |
| 156 if (fontName.IsEmpty()) | 157 if (fontName.IsEmpty()) |
| 157 return nullptr; | 158 return nullptr; |
| 158 | 159 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 183 pDict->SetNewFor<CPDF_Name>("BaseFont", fontName); | 184 pDict->SetNewFor<CPDF_Name>("BaseFont", fontName); |
| 184 if (pEncoding) { | 185 if (pEncoding) { |
| 185 pDict->SetFor("Encoding", | 186 pDict->SetFor("Encoding", |
| 186 pEncoding->Realize(m_pPDFDoc->GetByteStringPool())); | 187 pEncoding->Realize(m_pPDFDoc->GetByteStringPool())); |
| 187 } | 188 } |
| 188 | 189 |
| 189 std::unique_ptr<CPDF_Font> pFont = CPDF_Font::Create(m_pPDFDoc, pDict); | 190 std::unique_ptr<CPDF_Font> pFont = CPDF_Font::Create(m_pPDFDoc, pDict); |
| 190 if (!pFont) | 191 if (!pFont) |
| 191 return nullptr; | 192 return nullptr; |
| 192 | 193 |
| 193 CPDF_CountedFont* fontData = new CPDF_CountedFont(pFont.release()); | 194 CPDF_CountedFont* fontData = new CPDF_CountedFont(std::move(pFont)); |
| 194 m_FontMap[pDict] = fontData; | 195 m_FontMap[pDict] = fontData; |
| 195 return fontData->AddRef(); | 196 return fontData->AddRef(); |
| 196 } | 197 } |
| 197 | 198 |
| 198 void CPDF_DocPageData::ReleaseFont(const CPDF_Dictionary* pFontDict) { | 199 void CPDF_DocPageData::ReleaseFont(const CPDF_Dictionary* pFontDict) { |
| 199 if (!pFontDict) | 200 if (!pFontDict) |
| 200 return; | 201 return; |
| 201 | 202 |
| 202 auto it = m_FontMap.find(pFontDict); | 203 auto it = m_FontMap.find(pFontDict); |
| 203 if (it == m_FontMap.end()) | 204 if (it == m_FontMap.end()) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 if (csData->get()) { | 287 if (csData->get()) { |
| 287 return csData->AddRef(); | 288 return csData->AddRef(); |
| 288 } | 289 } |
| 289 } | 290 } |
| 290 | 291 |
| 291 std::unique_ptr<CPDF_ColorSpace> pCS = | 292 std::unique_ptr<CPDF_ColorSpace> pCS = |
| 292 CPDF_ColorSpace::Load(m_pPDFDoc, pArray); | 293 CPDF_ColorSpace::Load(m_pPDFDoc, pArray); |
| 293 if (!pCS) | 294 if (!pCS) |
| 294 return nullptr; | 295 return nullptr; |
| 295 | 296 |
| 296 if (!csData) { | 297 if (csData) { |
| 297 csData = new CPDF_CountedColorSpace(pCS.release()); | 298 csData->reset(std::move(pCS)); |
| 299 } else { |
| 300 csData = new CPDF_CountedColorSpace(std::move(pCS)); |
| 298 m_ColorSpaceMap[pCSObj] = csData; | 301 m_ColorSpaceMap[pCSObj] = csData; |
| 299 } else { | |
| 300 csData->reset(pCS.release()); | |
| 301 } | 302 } |
| 302 return csData->AddRef(); | 303 return csData->AddRef(); |
| 303 } | 304 } |
| 304 | 305 |
| 305 CPDF_ColorSpace* CPDF_DocPageData::GetCopiedColorSpace(CPDF_Object* pCSObj) { | 306 CPDF_ColorSpace* CPDF_DocPageData::GetCopiedColorSpace(CPDF_Object* pCSObj) { |
| 306 if (!pCSObj) | 307 if (!pCSObj) |
| 307 return nullptr; | 308 return nullptr; |
| 308 | 309 |
| 309 auto it = m_ColorSpaceMap.find(pCSObj); | 310 auto it = m_ColorSpaceMap.find(pCSObj); |
| 310 if (it != m_ColorSpaceMap.end()) | 311 if (it != m_ColorSpaceMap.end()) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 341 return nullptr; | 342 return nullptr; |
| 342 | 343 |
| 343 CPDF_CountedPattern* ptData = nullptr; | 344 CPDF_CountedPattern* ptData = nullptr; |
| 344 auto it = m_PatternMap.find(pPatternObj); | 345 auto it = m_PatternMap.find(pPatternObj); |
| 345 if (it != m_PatternMap.end()) { | 346 if (it != m_PatternMap.end()) { |
| 346 ptData = it->second; | 347 ptData = it->second; |
| 347 if (ptData->get()) { | 348 if (ptData->get()) { |
| 348 return ptData->AddRef(); | 349 return ptData->AddRef(); |
| 349 } | 350 } |
| 350 } | 351 } |
| 351 CPDF_Pattern* pPattern = nullptr; | 352 std::unique_ptr<CPDF_Pattern> pPattern; |
| 352 if (bShading) { | 353 if (bShading) { |
| 353 pPattern = new CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, true, matrix); | 354 pPattern = pdfium::MakeUnique<CPDF_ShadingPattern>(m_pPDFDoc, pPatternObj, |
| 355 true, matrix); |
| 354 } else { | 356 } else { |
| 355 CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : nullptr; | 357 CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : nullptr; |
| 356 if (pDict) { | 358 if (pDict) { |
| 357 int type = pDict->GetIntegerFor("PatternType"); | 359 int type = pDict->GetIntegerFor("PatternType"); |
| 358 if (type == CPDF_Pattern::TILING) { | 360 if (type == CPDF_Pattern::TILING) { |
| 359 pPattern = new CPDF_TilingPattern(m_pPDFDoc, pPatternObj, matrix); | 361 pPattern = pdfium::MakeUnique<CPDF_TilingPattern>(m_pPDFDoc, |
| 362 pPatternObj, matrix); |
| 360 } else if (type == CPDF_Pattern::SHADING) { | 363 } else if (type == CPDF_Pattern::SHADING) { |
| 361 pPattern = | 364 pPattern = pdfium::MakeUnique<CPDF_ShadingPattern>( |
| 362 new CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, false, matrix); | 365 m_pPDFDoc, pPatternObj, false, matrix); |
| 363 } | 366 } |
| 364 } | 367 } |
| 365 } | 368 } |
| 366 if (!pPattern) | 369 if (!pPattern) |
| 367 return nullptr; | 370 return nullptr; |
| 368 | 371 |
| 369 if (!ptData) { | 372 if (ptData) { |
| 370 ptData = new CPDF_CountedPattern(pPattern); | 373 ptData->reset(std::move(pPattern)); |
| 374 } else { |
| 375 ptData = new CPDF_CountedPattern(std::move(pPattern)); |
| 371 m_PatternMap[pPatternObj] = ptData; | 376 m_PatternMap[pPatternObj] = ptData; |
| 372 } else { | |
| 373 ptData->reset(pPattern); | |
| 374 } | 377 } |
| 375 return ptData->AddRef(); | 378 return ptData->AddRef(); |
| 376 } | 379 } |
| 377 | 380 |
| 378 void CPDF_DocPageData::ReleasePattern(const CPDF_Object* pPatternObj) { | 381 void CPDF_DocPageData::ReleasePattern(const CPDF_Object* pPatternObj) { |
| 379 if (!pPatternObj) | 382 if (!pPatternObj) |
| 380 return; | 383 return; |
| 381 | 384 |
| 382 auto it = m_PatternMap.find(pPatternObj); | 385 auto it = m_PatternMap.find(pPatternObj); |
| 383 if (it == m_PatternMap.end()) | 386 if (it == m_PatternMap.end()) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 394 // We have item only in m_PatternMap cache. Clean it. | 397 // We have item only in m_PatternMap cache. Clean it. |
| 395 pPattern->clear(); | 398 pPattern->clear(); |
| 396 } | 399 } |
| 397 | 400 |
| 398 CPDF_Image* CPDF_DocPageData::GetImage(uint32_t dwStreamObjNum) { | 401 CPDF_Image* CPDF_DocPageData::GetImage(uint32_t dwStreamObjNum) { |
| 399 ASSERT(dwStreamObjNum); | 402 ASSERT(dwStreamObjNum); |
| 400 auto it = m_ImageMap.find(dwStreamObjNum); | 403 auto it = m_ImageMap.find(dwStreamObjNum); |
| 401 if (it != m_ImageMap.end()) | 404 if (it != m_ImageMap.end()) |
| 402 return it->second->AddRef(); | 405 return it->second->AddRef(); |
| 403 | 406 |
| 404 CPDF_CountedImage* pCountedImage = | 407 CPDF_CountedImage* pCountedImage = new CPDF_CountedImage( |
| 405 new CPDF_CountedImage(new CPDF_Image(m_pPDFDoc, dwStreamObjNum)); | 408 pdfium::MakeUnique<CPDF_Image>(m_pPDFDoc, dwStreamObjNum)); |
| 406 m_ImageMap[dwStreamObjNum] = pCountedImage; | 409 m_ImageMap[dwStreamObjNum] = pCountedImage; |
| 407 return pCountedImage->AddRef(); | 410 return pCountedImage->AddRef(); |
| 408 } | 411 } |
| 409 | 412 |
| 410 void CPDF_DocPageData::ReleaseImage(uint32_t dwStreamObjNum) { | 413 void CPDF_DocPageData::ReleaseImage(uint32_t dwStreamObjNum) { |
| 411 ASSERT(dwStreamObjNum); | 414 ASSERT(dwStreamObjNum); |
| 412 auto it = m_ImageMap.find(dwStreamObjNum); | 415 auto it = m_ImageMap.find(dwStreamObjNum); |
| 413 if (it == m_ImageMap.end()) | 416 if (it == m_ImageMap.end()) |
| 414 return; | 417 return; |
| 415 | 418 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 440 stream.LoadAllData(pIccProfileStream, false); | 443 stream.LoadAllData(pIccProfileStream, false); |
| 441 uint8_t digest[20]; | 444 uint8_t digest[20]; |
| 442 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); | 445 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); |
| 443 CFX_ByteString bsDigest(digest, 20); | 446 CFX_ByteString bsDigest(digest, 20); |
| 444 auto hash_it = m_HashProfileMap.find(bsDigest); | 447 auto hash_it = m_HashProfileMap.find(bsDigest); |
| 445 if (hash_it != m_HashProfileMap.end()) { | 448 if (hash_it != m_HashProfileMap.end()) { |
| 446 auto it_copied_stream = m_IccProfileMap.find(hash_it->second); | 449 auto it_copied_stream = m_IccProfileMap.find(hash_it->second); |
| 447 if (it_copied_stream != m_IccProfileMap.end()) | 450 if (it_copied_stream != m_IccProfileMap.end()) |
| 448 return it_copied_stream->second->AddRef(); | 451 return it_copied_stream->second->AddRef(); |
| 449 } | 452 } |
| 450 CPDF_IccProfile* pProfile = | 453 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile( |
| 451 new CPDF_IccProfile(stream.GetData(), stream.GetSize()); | 454 pdfium::MakeUnique<CPDF_IccProfile>(stream.GetData(), stream.GetSize())); |
| 452 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile); | |
| 453 m_IccProfileMap[pIccProfileStream] = ipData; | 455 m_IccProfileMap[pIccProfileStream] = ipData; |
| 454 m_HashProfileMap[bsDigest] = pIccProfileStream; | 456 m_HashProfileMap[bsDigest] = pIccProfileStream; |
| 455 return ipData->AddRef(); | 457 return ipData->AddRef(); |
| 456 } | 458 } |
| 457 | 459 |
| 458 void CPDF_DocPageData::ReleaseIccProfile(const CPDF_IccProfile* pIccProfile) { | 460 void CPDF_DocPageData::ReleaseIccProfile(const CPDF_IccProfile* pIccProfile) { |
| 459 ASSERT(pIccProfile); | 461 ASSERT(pIccProfile); |
| 460 | 462 |
| 461 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end(); ++it) { | 463 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end(); ++it) { |
| 462 CPDF_CountedIccProfile* profile = it->second; | 464 CPDF_CountedIccProfile* profile = it->second; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 481 auto it = m_FontFileMap.find(pFontStream); | 483 auto it = m_FontFileMap.find(pFontStream); |
| 482 if (it != m_FontFileMap.end()) | 484 if (it != m_FontFileMap.end()) |
| 483 return it->second->AddRef(); | 485 return it->second->AddRef(); |
| 484 | 486 |
| 485 CPDF_Dictionary* pFontDict = pFontStream->GetDict(); | 487 CPDF_Dictionary* pFontDict = pFontStream->GetDict(); |
| 486 int32_t org_size = pFontDict->GetIntegerFor("Length1") + | 488 int32_t org_size = pFontDict->GetIntegerFor("Length1") + |
| 487 pFontDict->GetIntegerFor("Length2") + | 489 pFontDict->GetIntegerFor("Length2") + |
| 488 pFontDict->GetIntegerFor("Length3"); | 490 pFontDict->GetIntegerFor("Length3"); |
| 489 org_size = std::max(org_size, 0); | 491 org_size = std::max(org_size, 0); |
| 490 | 492 |
| 491 CPDF_StreamAcc* pFontFile = new CPDF_StreamAcc; | 493 auto pFontAcc = pdfium::MakeUnique<CPDF_StreamAcc>(); |
| 492 pFontFile->LoadAllData(pFontStream, false, org_size); | 494 pFontAcc->LoadAllData(pFontStream, false, org_size); |
| 493 | 495 |
| 494 CPDF_CountedStreamAcc* pCountedFont = new CPDF_CountedStreamAcc(pFontFile); | 496 CPDF_CountedStreamAcc* pCountedFont = |
| 497 new CPDF_CountedStreamAcc(std::move(pFontAcc)); |
| 495 m_FontFileMap[pFontStream] = pCountedFont; | 498 m_FontFileMap[pFontStream] = pCountedFont; |
| 496 return pCountedFont->AddRef(); | 499 return pCountedFont->AddRef(); |
| 497 } | 500 } |
| 498 | 501 |
| 499 void CPDF_DocPageData::ReleaseFontFileStreamAcc( | 502 void CPDF_DocPageData::ReleaseFontFileStreamAcc( |
| 500 const CPDF_Stream* pFontStream) { | 503 const CPDF_Stream* pFontStream) { |
| 501 if (!pFontStream) | 504 if (!pFontStream) |
| 502 return; | 505 return; |
| 503 | 506 |
| 504 auto it = m_FontFileMap.find(pFontStream); | 507 auto it = m_FontFileMap.find(pFontStream); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 529 } | 532 } |
| 530 | 533 |
| 531 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( | 534 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( |
| 532 CPDF_Object* pPatternObj) const { | 535 CPDF_Object* pPatternObj) const { |
| 533 if (!pPatternObj) | 536 if (!pPatternObj) |
| 534 return nullptr; | 537 return nullptr; |
| 535 | 538 |
| 536 auto it = m_PatternMap.find(pPatternObj); | 539 auto it = m_PatternMap.find(pPatternObj); |
| 537 return it != m_PatternMap.end() ? it->second : nullptr; | 540 return it != m_PatternMap.end() ? it->second : nullptr; |
| 538 } | 541 } |
| OLD | NEW |