| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/edit/cpdf_pagecontentgenerator.h" | 7 #include "core/fpdfapi/edit/cpdf_pagecontentgenerator.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/edit/cpdf_creator.h" | 9 #include "core/fpdfapi/edit/cpdf_creator.h" |
| 10 #include "core/fpdfapi/page/cpdf_docpagedata.h" | 10 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 } | 27 } |
| 28 | 28 |
| 29 CPDF_PageContentGenerator::CPDF_PageContentGenerator(CPDF_Page* pPage) | 29 CPDF_PageContentGenerator::CPDF_PageContentGenerator(CPDF_Page* pPage) |
| 30 : m_pPage(pPage), m_pDocument(m_pPage->m_pDocument) { | 30 : m_pPage(pPage), m_pDocument(m_pPage->m_pDocument) { |
| 31 for (const auto& pObj : *pPage->GetPageObjectList()) | 31 for (const auto& pObj : *pPage->GetPageObjectList()) |
| 32 InsertPageObject(pObj.get()); | 32 InsertPageObject(pObj.get()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 CPDF_PageContentGenerator::~CPDF_PageContentGenerator() {} | 35 CPDF_PageContentGenerator::~CPDF_PageContentGenerator() {} |
| 36 | 36 |
| 37 FX_BOOL CPDF_PageContentGenerator::InsertPageObject( | 37 void CPDF_PageContentGenerator::InsertPageObject(CPDF_PageObject* pPageObject) { |
| 38 CPDF_PageObject* pPageObject) { | 38 if (pPageObject) |
| 39 return pPageObject && m_pageObjects.Add(pPageObject); | 39 m_pageObjects.push_back(pPageObject); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void CPDF_PageContentGenerator::GenerateContent() { | 42 void CPDF_PageContentGenerator::GenerateContent() { |
| 43 CFX_ByteTextBuf buf; | 43 CFX_ByteTextBuf buf; |
| 44 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; | 44 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; |
| 45 for (int i = 0; i < m_pageObjects.GetSize(); ++i) { | 45 for (CPDF_PageObject* pPageObj : m_pageObjects) { |
| 46 CPDF_PageObject* pPageObj = m_pageObjects[i]; | 46 if (pPageObj && pPageObj->IsImage()) |
| 47 if (!pPageObj || !pPageObj->IsImage()) { | 47 ProcessImage(buf, pPageObj->AsImage()); |
| 48 continue; | |
| 49 } | |
| 50 ProcessImage(buf, pPageObj->AsImage()); | |
| 51 } | 48 } |
| 52 CPDF_Object* pContent = | 49 CPDF_Object* pContent = |
| 53 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; | 50 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; |
| 54 if (pContent) | 51 if (pContent) |
| 55 pPageDict->RemoveFor("Contents"); | 52 pPageDict->RemoveFor("Contents"); |
| 56 | 53 |
| 57 CPDF_Stream* pStream = new CPDF_Stream; | 54 CPDF_Stream* pStream = new CPDF_Stream; |
| 58 pStream->SetData(buf.GetBuffer(), buf.GetLength()); | 55 pStream->SetData(buf.GetBuffer(), buf.GetLength()); |
| 59 pPageDict->SetReferenceFor("Contents", m_pDocument, | 56 pPageDict->SetReferenceFor("Contents", m_pDocument, |
| 60 m_pDocument->AddIndirectObject(pStream)); | 57 m_pDocument->AddIndirectObject(pStream)); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } else if (CPDF_Stream* pStream = pContent->AsStream()) { | 167 } else if (CPDF_Stream* pStream = pContent->AsStream()) { |
| 171 CPDF_StreamAcc contentStream; | 168 CPDF_StreamAcc contentStream; |
| 172 contentStream.LoadAllData(pStream); | 169 contentStream.LoadAllData(pStream); |
| 173 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); | 170 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); |
| 174 } | 171 } |
| 175 CPDF_Stream* pStream = new CPDF_Stream; | 172 CPDF_Stream* pStream = new CPDF_Stream; |
| 176 pStream->SetData(buf.GetBuffer(), buf.GetLength()); | 173 pStream->SetData(buf.GetBuffer(), buf.GetLength()); |
| 177 m_pPage->m_pFormDict->SetReferenceFor( | 174 m_pPage->m_pFormDict->SetReferenceFor( |
| 178 "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream)); | 175 "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream)); |
| 179 } | 176 } |
| OLD | NEW |