| 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 for (CPDF_PageObject* pPageObj : m_pageObjects) { |
| 45 CPDF_ImageObject* pImageObject = pPageObj->AsImage(); |
| 46 if (pImageObject) |
| 47 ProcessImage(buf, pImageObject); |
| 48 } |
| 44 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; | 49 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; |
| 45 for (int i = 0; i < m_pageObjects.GetSize(); ++i) { | |
| 46 CPDF_PageObject* pPageObj = m_pageObjects[i]; | |
| 47 if (!pPageObj || !pPageObj->IsImage()) { | |
| 48 continue; | |
| 49 } | |
| 50 ProcessImage(buf, pPageObj->AsImage()); | |
| 51 } | |
| 52 CPDF_Object* pContent = | 50 CPDF_Object* pContent = |
| 53 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; | 51 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; |
| 54 if (pContent) | 52 if (pContent) |
| 55 pPageDict->RemoveFor("Contents"); | 53 pPageDict->RemoveFor("Contents"); |
| 56 | 54 |
| 57 CPDF_Stream* pStream = new CPDF_Stream; | 55 CPDF_Stream* pStream = new CPDF_Stream; |
| 58 pStream->SetData(buf.GetBuffer(), buf.GetLength()); | 56 pStream->SetData(buf.GetBuffer(), buf.GetLength()); |
| 59 pPageDict->SetReferenceFor("Contents", m_pDocument, | 57 pPageDict->SetReferenceFor("Contents", m_pDocument, |
| 60 m_pDocument->AddIndirectObject(pStream)); | 58 m_pDocument->AddIndirectObject(pStream)); |
| 61 } | 59 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } else if (CPDF_Stream* pStream = pContent->AsStream()) { | 168 } else if (CPDF_Stream* pStream = pContent->AsStream()) { |
| 171 CPDF_StreamAcc contentStream; | 169 CPDF_StreamAcc contentStream; |
| 172 contentStream.LoadAllData(pStream); | 170 contentStream.LoadAllData(pStream); |
| 173 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); | 171 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); |
| 174 } | 172 } |
| 175 CPDF_Stream* pStream = new CPDF_Stream; | 173 CPDF_Stream* pStream = new CPDF_Stream; |
| 176 pStream->SetData(buf.GetBuffer(), buf.GetLength()); | 174 pStream->SetData(buf.GetBuffer(), buf.GetLength()); |
| 177 m_pPage->m_pFormDict->SetReferenceFor( | 175 m_pPage->m_pFormDict->SetReferenceFor( |
| 178 "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream)); | 176 "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream)); |
| 179 } | 177 } |
| OLD | NEW |