| 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> |
| 10 #include <set> |
| 11 |
| 9 #include "core/fdrm/crypto/include/fx_crypt.h" | 12 #include "core/fdrm/crypto/include/fx_crypt.h" |
| 10 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h" | 13 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h" |
| 11 #include "core/fpdfapi/fpdf_font/font_int.h" | 14 #include "core/fpdfapi/fpdf_font/font_int.h" |
| 12 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" | 15 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" |
| 13 #include "core/fpdfapi/fpdf_page/cpdf_pattern.h" | 16 #include "core/fpdfapi/fpdf_page/cpdf_pattern.h" |
| 14 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" | 17 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" |
| 15 #include "core/fpdfapi/fpdf_page/cpdf_tilingpattern.h" | 18 #include "core/fpdfapi/fpdf_page/cpdf_tilingpattern.h" |
| 16 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" | 19 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" |
| 17 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 20 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 18 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 21 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 96 } |
| 94 } | 97 } |
| 95 delete ipData->get(); | 98 delete ipData->get(); |
| 96 delete ipData; | 99 delete ipData; |
| 97 m_IccProfileMap.erase(curr_it); | 100 m_IccProfileMap.erase(curr_it); |
| 98 } | 101 } |
| 99 } | 102 } |
| 100 | 103 |
| 101 for (auto it = m_FontFileMap.begin(); it != m_FontFileMap.end();) { | 104 for (auto it = m_FontFileMap.begin(); it != m_FontFileMap.end();) { |
| 102 auto curr_it = it++; | 105 auto curr_it = it++; |
| 103 CPDF_CountedStreamAcc* ftData = curr_it->second; | 106 CPDF_CountedStreamAcc* pCountedFont = curr_it->second; |
| 104 if (!ftData->get()) | 107 if (!pCountedFont->get()) |
| 105 continue; | 108 continue; |
| 106 | 109 |
| 107 if (bForceRelease || ftData->use_count() < 2) { | 110 if (bForceRelease || pCountedFont->use_count() < 2) { |
| 108 delete ftData->get(); | 111 delete pCountedFont->get(); |
| 109 delete ftData; | 112 delete pCountedFont; |
| 110 m_FontFileMap.erase(curr_it); | 113 m_FontFileMap.erase(curr_it); |
| 111 } | 114 } |
| 112 } | 115 } |
| 113 | 116 |
| 114 for (auto it = m_ImageMap.begin(); it != m_ImageMap.end();) { | 117 for (auto it = m_ImageMap.begin(); it != m_ImageMap.end();) { |
| 115 auto curr_it = it++; | 118 auto curr_it = it++; |
| 116 CPDF_CountedImage* imageData = curr_it->second; | 119 CPDF_CountedImage* pCountedImage = curr_it->second; |
| 117 if (!imageData->get()) | 120 if (!pCountedImage->get()) |
| 118 continue; | 121 continue; |
| 119 | 122 |
| 120 if (bForceRelease || imageData->use_count() < 2) { | 123 if (bForceRelease || pCountedImage->use_count() < 2) { |
| 121 delete imageData->get(); | 124 delete pCountedImage->get(); |
| 122 delete imageData; | 125 delete pCountedImage; |
| 123 m_ImageMap.erase(curr_it); | 126 m_ImageMap.erase(curr_it); |
| 124 } | 127 } |
| 125 } | 128 } |
| 126 } | 129 } |
| 127 | 130 |
| 128 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, | 131 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, |
| 129 FX_BOOL findOnly) { | 132 FX_BOOL findOnly) { |
| 130 if (!pFontDict) { | 133 if (!pFontDict) |
| 131 return nullptr; | 134 return nullptr; |
| 132 } | |
| 133 if (findOnly) { | |
| 134 auto it = m_FontMap.find(pFontDict); | |
| 135 if (it != m_FontMap.end() && it->second->get()) { | |
| 136 return it->second->AddRef(); | |
| 137 } | |
| 138 return nullptr; | |
| 139 } | |
| 140 | 135 |
| 141 CPDF_CountedFont* fontData = nullptr; | 136 CPDF_CountedFont* pFontData = nullptr; |
| 142 auto it = m_FontMap.find(pFontDict); | 137 auto it = m_FontMap.find(pFontDict); |
| 143 if (it != m_FontMap.end()) { | 138 if (it != m_FontMap.end()) { |
| 144 fontData = it->second; | 139 pFontData = it->second; |
| 145 if (fontData->get()) { | 140 if (pFontData->get()) { |
| 146 return fontData->AddRef(); | 141 return pFontData->AddRef(); |
| 147 } | 142 } |
| 148 } | 143 } |
| 149 | 144 |
| 145 if (findOnly) |
| 146 return nullptr; |
| 147 |
| 150 CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pFontDict); | 148 CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pFontDict); |
| 151 if (!pFont) { | 149 if (!pFont) |
| 152 return nullptr; | 150 return nullptr; |
| 151 |
| 152 if (pFontData) { |
| 153 pFontData->reset(pFont); |
| 154 } else { |
| 155 pFontData = new CPDF_CountedFont(pFont); |
| 156 m_FontMap[pFontDict] = pFontData; |
| 153 } | 157 } |
| 154 if (!fontData) { | 158 return pFontData->AddRef(); |
| 155 fontData = new CPDF_CountedFont(pFont); | |
| 156 m_FontMap[pFontDict] = fontData; | |
| 157 } else { | |
| 158 fontData->reset(pFont); | |
| 159 } | |
| 160 return fontData->AddRef(); | |
| 161 } | 159 } |
| 162 | 160 |
| 163 CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteString& fontName, | 161 CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteString& fontName, |
| 164 CPDF_FontEncoding* pEncoding) { | 162 CPDF_FontEncoding* pEncoding) { |
| 165 if (fontName.IsEmpty()) | 163 if (fontName.IsEmpty()) |
| 166 return nullptr; | 164 return nullptr; |
| 167 | 165 |
| 168 for (auto& it : m_FontMap) { | 166 for (auto& it : m_FontMap) { |
| 169 CPDF_CountedFont* fontData = it.second; | 167 CPDF_CountedFont* fontData = it.second; |
| 170 CPDF_Font* pFont = fontData->get(); | 168 CPDF_Font* pFont = fontData->get(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 196 m_pPDFDoc->AddIndirectObject(pDict); | 194 m_pPDFDoc->AddIndirectObject(pDict); |
| 197 CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pDict); | 195 CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pDict); |
| 198 if (!pFont) { | 196 if (!pFont) { |
| 199 return nullptr; | 197 return nullptr; |
| 200 } | 198 } |
| 201 CPDF_CountedFont* fontData = new CPDF_CountedFont(pFont); | 199 CPDF_CountedFont* fontData = new CPDF_CountedFont(pFont); |
| 202 m_FontMap[pDict] = fontData; | 200 m_FontMap[pDict] = fontData; |
| 203 return fontData->AddRef(); | 201 return fontData->AddRef(); |
| 204 } | 202 } |
| 205 | 203 |
| 206 void CPDF_DocPageData::ReleaseFont(CPDF_Dictionary* pFontDict) { | 204 void CPDF_DocPageData::ReleaseFont(const CPDF_Dictionary* pFontDict) { |
| 207 if (!pFontDict) | 205 if (!pFontDict) |
| 208 return; | 206 return; |
| 209 | 207 |
| 210 auto it = m_FontMap.find(pFontDict); | 208 auto it = m_FontMap.find(pFontDict); |
| 211 if (it == m_FontMap.end()) | 209 if (it == m_FontMap.end()) |
| 212 return; | 210 return; |
| 213 | 211 |
| 214 CPDF_CountedFont* fontData = it->second; | 212 CPDF_CountedFont* pFontData = it->second; |
| 215 if (fontData->get()) { | 213 if (!pFontData->get()) |
| 216 fontData->RemoveRef(); | 214 return; |
| 217 if (fontData->use_count() == 0) { | 215 |
| 218 fontData->clear(); | 216 pFontData->RemoveRef(); |
| 219 } | 217 if (pFontData->use_count() != 0) |
| 220 } | 218 return; |
| 219 |
| 220 pFontData->clear(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace( | 223 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace( |
| 224 CPDF_Object* pCSObj, | 224 CPDF_Object* pCSObj, |
| 225 const CPDF_Dictionary* pResources) { | 225 const CPDF_Dictionary* pResources) { |
| 226 std::set<CPDF_Object*> visited; | 226 std::set<CPDF_Object*> visited; |
| 227 return GetColorSpaceImpl(pCSObj, pResources, &visited); | 227 return GetColorSpaceImpl(pCSObj, pResources, &visited); |
| 228 } | 228 } |
| 229 | 229 |
| 230 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpaceImpl( | 230 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpaceImpl( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 if (!pCSObj) | 310 if (!pCSObj) |
| 311 return nullptr; | 311 return nullptr; |
| 312 | 312 |
| 313 auto it = m_ColorSpaceMap.find(pCSObj); | 313 auto it = m_ColorSpaceMap.find(pCSObj); |
| 314 if (it != m_ColorSpaceMap.end()) | 314 if (it != m_ColorSpaceMap.end()) |
| 315 return it->second->AddRef(); | 315 return it->second->AddRef(); |
| 316 | 316 |
| 317 return nullptr; | 317 return nullptr; |
| 318 } | 318 } |
| 319 | 319 |
| 320 void CPDF_DocPageData::ReleaseColorSpace(CPDF_Object* pColorSpace) { | 320 void CPDF_DocPageData::ReleaseColorSpace(const CPDF_Object* pColorSpace) { |
| 321 if (!pColorSpace) | 321 if (!pColorSpace) |
| 322 return; | 322 return; |
| 323 | 323 |
| 324 auto it = m_ColorSpaceMap.find(pColorSpace); | 324 auto it = m_ColorSpaceMap.find(pColorSpace); |
| 325 if (it == m_ColorSpaceMap.end()) | 325 if (it == m_ColorSpaceMap.end()) |
| 326 return; | 326 return; |
| 327 | 327 |
| 328 CPDF_CountedColorSpace* csData = it->second; | 328 CPDF_CountedColorSpace* pCountedColorSpace = it->second; |
| 329 if (csData->get()) { | 329 if (!pCountedColorSpace->get()) |
| 330 csData->RemoveRef(); | 330 return; |
| 331 if (csData->use_count() == 0) { | 331 |
| 332 csData->get()->ReleaseCS(); | 332 pCountedColorSpace->RemoveRef(); |
| 333 csData->reset(nullptr); | 333 if (pCountedColorSpace->use_count() != 0) |
| 334 } | 334 return; |
| 335 } | 335 |
| 336 pCountedColorSpace->get()->ReleaseCS(); |
| 337 pCountedColorSpace->reset(nullptr); |
| 336 } | 338 } |
| 337 | 339 |
| 338 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, | 340 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, |
| 339 FX_BOOL bShading, | 341 FX_BOOL bShading, |
| 340 const CFX_Matrix& matrix) { | 342 const CFX_Matrix& matrix) { |
| 341 if (!pPatternObj) | 343 if (!pPatternObj) |
| 342 return nullptr; | 344 return nullptr; |
| 343 | 345 |
| 344 CPDF_CountedPattern* ptData = nullptr; | 346 CPDF_CountedPattern* ptData = nullptr; |
| 345 auto it = m_PatternMap.find(pPatternObj); | 347 auto it = m_PatternMap.find(pPatternObj); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 369 | 371 |
| 370 if (!ptData) { | 372 if (!ptData) { |
| 371 ptData = new CPDF_CountedPattern(pPattern); | 373 ptData = new CPDF_CountedPattern(pPattern); |
| 372 m_PatternMap[pPatternObj] = ptData; | 374 m_PatternMap[pPatternObj] = ptData; |
| 373 } else { | 375 } else { |
| 374 ptData->reset(pPattern); | 376 ptData->reset(pPattern); |
| 375 } | 377 } |
| 376 return ptData->AddRef(); | 378 return ptData->AddRef(); |
| 377 } | 379 } |
| 378 | 380 |
| 379 void CPDF_DocPageData::ReleasePattern(CPDF_Object* pPatternObj) { | 381 void CPDF_DocPageData::ReleasePattern(const CPDF_Object* pPatternObj) { |
| 380 if (!pPatternObj) | 382 if (!pPatternObj) |
| 381 return; | 383 return; |
| 382 | 384 |
| 383 auto it = m_PatternMap.find(pPatternObj); | 385 auto it = m_PatternMap.find(pPatternObj); |
| 384 if (it == m_PatternMap.end()) | 386 if (it == m_PatternMap.end()) |
| 385 return; | 387 return; |
| 386 | 388 |
| 387 CPDF_CountedPattern* ptData = it->second; | 389 CPDF_CountedPattern* pPattern = it->second; |
| 388 if (ptData->get()) { | 390 if (!pPattern->get()) |
| 389 ptData->RemoveRef(); | 391 return; |
| 390 if (ptData->use_count() == 0) { | 392 |
| 391 ptData->clear(); | 393 pPattern->RemoveRef(); |
| 392 } | 394 if (pPattern->use_count() != 0) |
| 393 } | 395 return; |
| 396 |
| 397 pPattern->clear(); |
| 394 } | 398 } |
| 395 | 399 |
| 396 CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream) { | 400 CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream) { |
| 397 if (!pImageStream) | 401 if (!pImageStream) |
| 398 return nullptr; | 402 return nullptr; |
| 399 | 403 |
| 400 const uint32_t dwImageObjNum = pImageStream->GetObjNum(); | 404 const uint32_t dwImageObjNum = pImageStream->GetObjNum(); |
| 401 auto it = m_ImageMap.find(dwImageObjNum); | 405 auto it = m_ImageMap.find(dwImageObjNum); |
| 402 if (it != m_ImageMap.end()) { | 406 if (it != m_ImageMap.end()) |
| 403 return it->second->AddRef(); | 407 return it->second->AddRef(); |
| 404 } | |
| 405 | 408 |
| 406 CPDF_Image* pImage = new CPDF_Image(m_pPDFDoc); | 409 CPDF_Image* pImage = new CPDF_Image(m_pPDFDoc); |
| 407 pImage->LoadImageF(pImageStream->AsStream(), FALSE); | 410 pImage->LoadImageF(pImageStream->AsStream(), false); |
| 408 | 411 |
| 409 CPDF_CountedImage* imageData = new CPDF_CountedImage(pImage); | 412 CPDF_CountedImage* pCountedImage = new CPDF_CountedImage(pImage); |
| 410 m_ImageMap[dwImageObjNum] = imageData; | 413 m_ImageMap[dwImageObjNum] = pCountedImage; |
| 411 return imageData->AddRef(); | 414 return pCountedImage->AddRef(); |
| 412 } | 415 } |
| 413 | 416 |
| 414 void CPDF_DocPageData::ReleaseImage(CPDF_Object* pImageStream) { | 417 void CPDF_DocPageData::ReleaseImage(const CPDF_Object* pImageStream) { |
| 415 if (!pImageStream || !pImageStream->GetObjNum()) | 418 if (!pImageStream) |
| 416 return; | 419 return; |
| 417 | 420 |
| 418 auto it = m_ImageMap.find(pImageStream->GetObjNum()); | 421 uint32_t dwObjNum = pImageStream->GetObjNum(); |
| 422 if (!dwObjNum) |
| 423 return; |
| 424 |
| 425 auto it = m_ImageMap.find(dwObjNum); |
| 419 if (it == m_ImageMap.end()) | 426 if (it == m_ImageMap.end()) |
| 420 return; | 427 return; |
| 421 | 428 |
| 422 CPDF_CountedImage* image = it->second; | 429 CPDF_CountedImage* pCountedImage = it->second; |
| 423 if (!image) | 430 if (!pCountedImage) |
| 424 return; | 431 return; |
| 425 | 432 |
| 426 image->RemoveRef(); | 433 pCountedImage->RemoveRef(); |
| 427 if (image->use_count() == 0) { | 434 if (pCountedImage->use_count() != 0) |
| 428 delete image->get(); | 435 return; |
| 429 delete image; | 436 |
| 430 m_ImageMap.erase(it); | 437 delete pCountedImage->get(); |
| 431 } | 438 delete pCountedImage; |
| 439 m_ImageMap.erase(it); |
| 432 } | 440 } |
| 433 | 441 |
| 434 CPDF_IccProfile* CPDF_DocPageData::GetIccProfile( | 442 CPDF_IccProfile* CPDF_DocPageData::GetIccProfile( |
| 435 CPDF_Stream* pIccProfileStream) { | 443 CPDF_Stream* pIccProfileStream) { |
| 436 if (!pIccProfileStream) | 444 if (!pIccProfileStream) |
| 437 return nullptr; | 445 return nullptr; |
| 438 | 446 |
| 439 auto it = m_IccProfileMap.find(pIccProfileStream); | 447 auto it = m_IccProfileMap.find(pIccProfileStream); |
| 440 if (it != m_IccProfileMap.end()) { | 448 if (it != m_IccProfileMap.end()) |
| 441 return it->second->AddRef(); | 449 return it->second->AddRef(); |
| 442 } | |
| 443 | 450 |
| 444 CPDF_StreamAcc stream; | 451 CPDF_StreamAcc stream; |
| 445 stream.LoadAllData(pIccProfileStream, FALSE); | 452 stream.LoadAllData(pIccProfileStream, FALSE); |
| 446 uint8_t digest[20]; | 453 uint8_t digest[20]; |
| 447 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); | 454 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); |
| 448 CFX_ByteString bsDigest(digest, 20); | 455 CFX_ByteString bsDigest(digest, 20); |
| 449 auto hash_it = m_HashProfileMap.find(bsDigest); | 456 auto hash_it = m_HashProfileMap.find(bsDigest); |
| 450 if (hash_it != m_HashProfileMap.end()) { | 457 if (hash_it != m_HashProfileMap.end()) { |
| 451 auto it_copied_stream = m_IccProfileMap.find(hash_it->second); | 458 auto it_copied_stream = m_IccProfileMap.find(hash_it->second); |
| 452 return it_copied_stream->second->AddRef(); | 459 return it_copied_stream->second->AddRef(); |
| 453 } | 460 } |
| 454 CPDF_IccProfile* pProfile = | 461 CPDF_IccProfile* pProfile = |
| 455 new CPDF_IccProfile(stream.GetData(), stream.GetSize()); | 462 new CPDF_IccProfile(stream.GetData(), stream.GetSize()); |
| 456 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile); | 463 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile); |
| 457 m_IccProfileMap[pIccProfileStream] = ipData; | 464 m_IccProfileMap[pIccProfileStream] = ipData; |
| 458 m_HashProfileMap[bsDigest] = pIccProfileStream; | 465 m_HashProfileMap[bsDigest] = pIccProfileStream; |
| 459 return ipData->AddRef(); | 466 return ipData->AddRef(); |
| 460 } | 467 } |
| 461 | 468 |
| 462 void CPDF_DocPageData::ReleaseIccProfile(CPDF_IccProfile* pIccProfile) { | 469 void CPDF_DocPageData::ReleaseIccProfile(const CPDF_IccProfile* pIccProfile) { |
| 463 ASSERT(pIccProfile); | 470 ASSERT(pIccProfile); |
| 464 | 471 |
| 465 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end(); ++it) { | 472 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end(); ++it) { |
| 466 CPDF_CountedIccProfile* profile = it->second; | 473 CPDF_CountedIccProfile* profile = it->second; |
| 467 if (profile->get() != pIccProfile) | 474 if (profile->get() != pIccProfile) |
| 468 continue; | 475 continue; |
| 469 | 476 |
| 470 profile->RemoveRef(); | 477 profile->RemoveRef(); |
| 471 if (profile->use_count() == 0) { | 478 if (profile->use_count() == 0) { |
| 472 delete profile->get(); | 479 delete profile->get(); |
| 473 delete profile; | 480 delete profile; |
| 474 m_IccProfileMap.erase(it); | 481 m_IccProfileMap.erase(it); |
| 475 return; | 482 return; |
| 476 } | 483 } |
| 477 } | 484 } |
| 478 } | 485 } |
| 479 | 486 |
| 480 CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc( | 487 CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc( |
| 481 CPDF_Stream* pFontStream) { | 488 CPDF_Stream* pFontStream) { |
| 482 ASSERT(pFontStream); | 489 ASSERT(pFontStream); |
| 483 | 490 |
| 484 auto it = m_FontFileMap.find(pFontStream); | 491 auto it = m_FontFileMap.find(pFontStream); |
| 485 if (it != m_FontFileMap.end()) | 492 if (it != m_FontFileMap.end()) |
| 486 return it->second->AddRef(); | 493 return it->second->AddRef(); |
| 487 | 494 |
| 488 CPDF_Dictionary* pFontDict = pFontStream->GetDict(); | 495 CPDF_Dictionary* pFontDict = pFontStream->GetDict(); |
| 489 int32_t org_size = pFontDict->GetIntegerBy("Length1") + | 496 int32_t org_size = pFontDict->GetIntegerBy("Length1") + |
| 490 pFontDict->GetIntegerBy("Length2") + | 497 pFontDict->GetIntegerBy("Length2") + |
| 491 pFontDict->GetIntegerBy("Length3"); | 498 pFontDict->GetIntegerBy("Length3"); |
| 492 if (org_size < 0) | 499 org_size = std::max(org_size, 0); |
| 493 org_size = 0; | |
| 494 | 500 |
| 495 CPDF_StreamAcc* pFontFile = new CPDF_StreamAcc; | 501 CPDF_StreamAcc* pFontFile = new CPDF_StreamAcc; |
| 496 pFontFile->LoadAllData(pFontStream, FALSE, org_size); | 502 pFontFile->LoadAllData(pFontStream, FALSE, org_size); |
| 497 | 503 |
| 498 CPDF_CountedStreamAcc* ftData = new CPDF_CountedStreamAcc(pFontFile); | 504 CPDF_CountedStreamAcc* pCountedFont = new CPDF_CountedStreamAcc(pFontFile); |
| 499 m_FontFileMap[pFontStream] = ftData; | 505 m_FontFileMap[pFontStream] = pCountedFont; |
| 500 return ftData->AddRef(); | 506 return pCountedFont->AddRef(); |
| 501 } | 507 } |
| 502 | 508 |
| 503 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, | 509 void CPDF_DocPageData::ReleaseFontFileStreamAcc( |
| 504 FX_BOOL bForce) { | 510 const CPDF_Stream* pFontStream) { |
| 505 if (!pFontStream) | 511 if (!pFontStream) |
| 506 return; | 512 return; |
| 507 | 513 |
| 508 auto it = m_FontFileMap.find(pFontStream); | 514 auto it = m_FontFileMap.find(pFontStream); |
| 509 if (it == m_FontFileMap.end()) | 515 if (it == m_FontFileMap.end()) |
| 510 return; | 516 return; |
| 511 | 517 |
| 512 CPDF_CountedStreamAcc* findData = it->second; | 518 CPDF_CountedStreamAcc* pCountedStream = it->second; |
| 513 if (!findData) | 519 if (!pCountedStream) |
| 514 return; | 520 return; |
| 515 | 521 |
| 516 findData->RemoveRef(); | 522 pCountedStream->RemoveRef(); |
| 517 if (findData->use_count() == 0 || bForce) { | 523 if (pCountedStream->use_count() != 0) |
| 518 delete findData->get(); | 524 return; |
| 519 delete findData; | 525 |
| 520 m_FontFileMap.erase(it); | 526 delete pCountedStream->get(); |
| 521 } | 527 delete pCountedStream; |
| 528 m_FontFileMap.erase(it); |
| 522 } | 529 } |
| 523 | 530 |
| 524 CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr( | 531 CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr( |
| 525 CPDF_Object* pCSObj) const { | 532 CPDF_Object* pCSObj) const { |
| 526 if (!pCSObj) | 533 if (!pCSObj) |
| 527 return nullptr; | 534 return nullptr; |
| 528 | 535 |
| 529 auto it = m_ColorSpaceMap.find(pCSObj); | 536 auto it = m_ColorSpaceMap.find(pCSObj); |
| 530 return it != m_ColorSpaceMap.end() ? it->second : nullptr; | 537 return it != m_ColorSpaceMap.end() ? it->second : nullptr; |
| 531 } | 538 } |
| 532 | 539 |
| 533 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( | 540 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( |
| 534 CPDF_Object* pPatternObj) const { | 541 CPDF_Object* pPatternObj) const { |
| 535 if (!pPatternObj) | 542 if (!pPatternObj) |
| 536 return nullptr; | 543 return nullptr; |
| 537 | 544 |
| 538 auto it = m_PatternMap.find(pPatternObj); | 545 auto it = m_PatternMap.find(pPatternObj); |
| 539 return it != m_PatternMap.end() ? it->second : nullptr; | 546 return it != m_PatternMap.end() ? it->second : nullptr; |
| 540 } | 547 } |
| OLD | NEW |