| 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/pageint.h" | 7 #include "core/fpdfapi/page/pageint.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 m_pCurStates->m_ColorState.Emplace(); | 227 m_pCurStates->m_ColorState.Emplace(); |
| 228 } | 228 } |
| 229 for (size_t i = 0; i < FX_ArraySize(m_Type3Data); ++i) { | 229 for (size_t i = 0; i < FX_ArraySize(m_Type3Data); ++i) { |
| 230 m_Type3Data[i] = 0.0; | 230 m_Type3Data[i] = 0.0; |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 CPDF_StreamContentParser::~CPDF_StreamContentParser() { | 234 CPDF_StreamContentParser::~CPDF_StreamContentParser() { |
| 235 ClearAllParams(); | 235 ClearAllParams(); |
| 236 FX_Free(m_pPathPoints); | 236 FX_Free(m_pPathPoints); |
| 237 if (m_pLastImageDict) { | 237 delete m_pLastImageDict; |
| 238 m_pLastImageDict->Release(); | 238 delete m_pLastCloneImageDict; |
| 239 } | |
| 240 if (m_pLastCloneImageDict) { | |
| 241 m_pLastCloneImageDict->Release(); | |
| 242 } | |
| 243 } | 239 } |
| 244 | 240 |
| 245 int CPDF_StreamContentParser::GetNextParamPos() { | 241 int CPDF_StreamContentParser::GetNextParamPos() { |
| 246 if (m_ParamCount == PARAM_BUF_SIZE) { | 242 if (m_ParamCount == PARAM_BUF_SIZE) { |
| 247 m_ParamStartPos++; | 243 m_ParamStartPos++; |
| 248 if (m_ParamStartPos == PARAM_BUF_SIZE) { | 244 if (m_ParamStartPos == PARAM_BUF_SIZE) |
| 249 m_ParamStartPos = 0; | 245 m_ParamStartPos = 0; |
| 250 } | 246 |
| 251 if (m_ParamBuf[m_ParamStartPos].m_Type == 0) { | 247 if (m_ParamBuf[m_ParamStartPos].m_Type == 0) |
| 252 if (CPDF_Object* pObject = m_ParamBuf[m_ParamStartPos].m_pObject) | 248 delete m_ParamBuf[m_ParamStartPos].m_pObject; |
| 253 pObject->Release(); | 249 |
| 254 } | |
| 255 return m_ParamStartPos; | 250 return m_ParamStartPos; |
| 256 } | 251 } |
| 257 int index = m_ParamStartPos + m_ParamCount; | 252 int index = m_ParamStartPos + m_ParamCount; |
| 258 if (index >= PARAM_BUF_SIZE) { | 253 if (index >= PARAM_BUF_SIZE) { |
| 259 index -= PARAM_BUF_SIZE; | 254 index -= PARAM_BUF_SIZE; |
| 260 } | 255 } |
| 261 m_ParamCount++; | 256 m_ParamCount++; |
| 262 return index; | 257 return index; |
| 263 } | 258 } |
| 264 | 259 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 291 | 286 |
| 292 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) { | 287 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) { |
| 293 ContentParam& param = m_ParamBuf[GetNextParamPos()]; | 288 ContentParam& param = m_ParamBuf[GetNextParamPos()]; |
| 294 param.m_Type = ContentParam::OBJECT; | 289 param.m_Type = ContentParam::OBJECT; |
| 295 param.m_pObject = pObj; | 290 param.m_pObject = pObj; |
| 296 } | 291 } |
| 297 | 292 |
| 298 void CPDF_StreamContentParser::ClearAllParams() { | 293 void CPDF_StreamContentParser::ClearAllParams() { |
| 299 uint32_t index = m_ParamStartPos; | 294 uint32_t index = m_ParamStartPos; |
| 300 for (uint32_t i = 0; i < m_ParamCount; i++) { | 295 for (uint32_t i = 0; i < m_ParamCount; i++) { |
| 301 if (m_ParamBuf[index].m_Type == 0) { | 296 if (m_ParamBuf[index].m_Type == 0) |
| 302 if (CPDF_Object* pObject = m_ParamBuf[index].m_pObject) | 297 delete m_ParamBuf[index].m_pObject; |
| 303 pObject->Release(); | 298 |
| 304 } | |
| 305 index++; | 299 index++; |
| 306 if (index == PARAM_BUF_SIZE) { | 300 if (index == PARAM_BUF_SIZE) |
| 307 index = 0; | 301 index = 0; |
| 308 } | |
| 309 } | 302 } |
| 310 m_ParamStartPos = 0; | 303 m_ParamStartPos = 0; |
| 311 m_ParamCount = 0; | 304 m_ParamCount = 0; |
| 312 } | 305 } |
| 313 | 306 |
| 314 CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) { | 307 CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) { |
| 315 if (index >= m_ParamCount) { | 308 if (index >= m_ParamCount) { |
| 316 return nullptr; | 309 return nullptr; |
| 317 } | 310 } |
| 318 int real_index = m_ParamStartPos + m_ParamCount - index - 1; | 311 int real_index = m_ParamStartPos + m_ParamCount - index - 1; |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 FX_FILESIZE savePos = m_pSyntax->GetPos(); | 571 FX_FILESIZE savePos = m_pSyntax->GetPos(); |
| 579 CPDF_Dictionary* pDict = | 572 CPDF_Dictionary* pDict = |
| 580 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 573 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); |
| 581 while (1) { | 574 while (1) { |
| 582 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); | 575 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); |
| 583 if (type == CPDF_StreamParser::Keyword) { | 576 if (type == CPDF_StreamParser::Keyword) { |
| 584 CFX_ByteString bsKeyword(m_pSyntax->GetWordBuf(), | 577 CFX_ByteString bsKeyword(m_pSyntax->GetWordBuf(), |
| 585 m_pSyntax->GetWordSize()); | 578 m_pSyntax->GetWordSize()); |
| 586 if (bsKeyword != "ID") { | 579 if (bsKeyword != "ID") { |
| 587 m_pSyntax->SetPos(savePos); | 580 m_pSyntax->SetPos(savePos); |
| 588 pDict->Release(); | 581 delete pDict; |
| 589 return; | 582 return; |
| 590 } | 583 } |
| 591 } | 584 } |
| 592 if (type != CPDF_StreamParser::Name) { | 585 if (type != CPDF_StreamParser::Name) { |
| 593 break; | 586 break; |
| 594 } | 587 } |
| 595 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, | 588 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, |
| 596 m_pSyntax->GetWordSize() - 1); | 589 m_pSyntax->GetWordSize() - 1); |
| 597 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( | 590 std::unique_ptr<CPDF_Object> pObj(m_pSyntax->ReadNextObject(false, 0)); |
| 598 m_pSyntax->ReadNextObject(false, 0)); | |
| 599 if (!key.IsEmpty()) { | 591 if (!key.IsEmpty()) { |
| 600 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; | 592 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; |
| 601 if (dwObjNum) | 593 if (dwObjNum) |
| 602 pDict->SetReferenceFor(key, m_pDocument, dwObjNum); | 594 pDict->SetReferenceFor(key, m_pDocument, dwObjNum); |
| 603 else | 595 else |
| 604 pDict->SetFor(key, pObj.release()); | 596 pDict->SetFor(key, pObj.release()); |
| 605 } | 597 } |
| 606 } | 598 } |
| 607 PDF_ReplaceAbbr(pDict); | 599 PDF_ReplaceAbbr(pDict); |
| 608 CPDF_Object* pCSObj = nullptr; | 600 CPDF_Object* pCSObj = nullptr; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 631 } | 623 } |
| 632 if (m_pSyntax->GetWordSize() == 2 && m_pSyntax->GetWordBuf()[0] == 'E' && | 624 if (m_pSyntax->GetWordSize() == 2 && m_pSyntax->GetWordBuf()[0] == 'E' && |
| 633 m_pSyntax->GetWordBuf()[1] == 'I') { | 625 m_pSyntax->GetWordBuf()[1] == 'I') { |
| 634 break; | 626 break; |
| 635 } | 627 } |
| 636 } | 628 } |
| 637 pDict->SetNameFor("Subtype", "Image"); | 629 pDict->SetNameFor("Subtype", "Image"); |
| 638 CPDF_ImageObject* pImgObj = AddImage(pStream, nullptr, true); | 630 CPDF_ImageObject* pImgObj = AddImage(pStream, nullptr, true); |
| 639 if (!pImgObj) { | 631 if (!pImgObj) { |
| 640 if (pStream) { | 632 if (pStream) { |
| 641 pStream->Release(); | 633 delete pStream; |
| 642 } else { | 634 } else { |
| 643 pDict->Release(); | 635 delete pDict; |
| 644 } | 636 } |
| 645 } | 637 } |
| 646 } | 638 } |
| 647 | 639 |
| 648 void CPDF_StreamContentParser::Handle_BeginMarkedContent() { | 640 void CPDF_StreamContentParser::Handle_BeginMarkedContent() { |
| 649 m_CurContentMark.AddMark(GetString(0), nullptr, FALSE); | 641 m_CurContentMark.AddMark(GetString(0), nullptr, FALSE); |
| 650 } | 642 } |
| 651 | 643 |
| 652 void CPDF_StreamContentParser::Handle_BeginText() { | 644 void CPDF_StreamContentParser::Handle_BeginText() { |
| 653 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); | 645 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); |
| (...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1659 } else { | 1651 } else { |
| 1660 PDF_ReplaceAbbr(pElement); | 1652 PDF_ReplaceAbbr(pElement); |
| 1661 } | 1653 } |
| 1662 } | 1654 } |
| 1663 break; | 1655 break; |
| 1664 } | 1656 } |
| 1665 default: | 1657 default: |
| 1666 break; | 1658 break; |
| 1667 } | 1659 } |
| 1668 } | 1660 } |
| OLD | NEW |