| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 CPDF_ImageObject* pImageObject = pPageObj->AsImage(); | 45 CPDF_ImageObject* pImageObject = pPageObj->AsImage(); |
| 46 if (pImageObject) | 46 if (pImageObject) |
| 47 ProcessImage(buf, pImageObject); | 47 ProcessImage(buf, pImageObject); |
| 48 } | 48 } |
| 49 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; | 49 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; |
| 50 CPDF_Object* pContent = | 50 CPDF_Object* pContent = |
| 51 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; | 51 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; |
| 52 if (pContent) | 52 if (pContent) |
| 53 pPageDict->RemoveFor("Contents"); | 53 pPageDict->RemoveFor("Contents"); |
| 54 | 54 |
| 55 CPDF_Stream* pStream = new CPDF_Stream; | 55 CPDF_Stream* pStream = m_pDocument->AddIndirectStream(); |
| 56 pStream->SetData(buf.GetBuffer(), buf.GetLength()); | 56 pStream->SetData(buf.GetBuffer(), buf.GetLength()); |
| 57 pPageDict->SetReferenceFor("Contents", m_pDocument, | 57 pPageDict->SetReferenceFor("Contents", m_pDocument, pStream); |
| 58 m_pDocument->AddIndirectObject(pStream)); | |
| 59 } | 58 } |
| 60 | 59 |
| 61 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( | 60 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( |
| 62 CPDF_Object* pResourceObj, | 61 CPDF_Object* pResourceObj, |
| 63 const CFX_ByteString& bsType) { | 62 const CFX_ByteString& bsType) { |
| 64 if (!m_pPage->m_pResources) { | 63 if (!m_pPage->m_pResources) { |
| 65 m_pPage->m_pResources = | 64 m_pPage->m_pResources = |
| 66 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 65 m_pDocument->AddIndirectDictionary(m_pDocument->GetByteStringPool()); |
| 67 m_pPage->m_pFormDict->SetReferenceFor( | 66 m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, |
| 68 "Resources", m_pDocument, | 67 m_pPage->m_pResources); |
| 69 m_pDocument->AddIndirectObject(m_pPage->m_pResources)); | |
| 70 } | 68 } |
| 71 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); | 69 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); |
| 72 if (!pResList) { | 70 if (!pResList) { |
| 73 pResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 71 pResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); |
| 74 m_pPage->m_pResources->SetFor(bsType, pResList); | 72 m_pPage->m_pResources->SetFor(bsType, pResList); |
| 75 } | 73 } |
| 76 CFX_ByteString name; | 74 CFX_ByteString name; |
| 77 int idnum = 1; | 75 int idnum = 1; |
| 78 while (1) { | 76 while (1) { |
| 79 name.Format("FX%c%d", bsType[0], idnum); | 77 name.Format("FX%c%d", bsType[0], idnum); |
| 80 if (!pResList->KeyExist(name)) { | 78 if (!pResList->KeyExist(name)) { |
| 81 break; | 79 break; |
| 82 } | 80 } |
| 83 idnum++; | 81 idnum++; |
| 84 } | 82 } |
| 85 pResList->SetReferenceFor(name, m_pDocument, | 83 pResList->SetReferenceFor( |
| 86 m_pDocument->AddIndirectObject(pResourceObj)); | 84 name, m_pDocument, |
| 85 m_pDocument->AddIndirectObject(UniqueObject(pResourceObj))); // Owner? |
| 87 return name; | 86 return name; |
| 88 } | 87 } |
| 89 | 88 |
| 90 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf, | 89 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf, |
| 91 CPDF_ImageObject* pImageObj) { | 90 CPDF_ImageObject* pImageObj) { |
| 92 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || | 91 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || |
| 93 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { | 92 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { |
| 94 return; | 93 return; |
| 95 } | 94 } |
| 96 buf << "q " << pImageObj->m_Matrix << " cm "; | 95 buf << "q " << pImageObj->m_Matrix << " cm "; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 delete pContentArray[i]; | 162 delete pContentArray[i]; |
| 164 } | 163 } |
| 165 ProcessForm(buf, pBuf, size, matrix); | 164 ProcessForm(buf, pBuf, size, matrix); |
| 166 FX_Free(pBuf); | 165 FX_Free(pBuf); |
| 167 FX_Free(pContentArray); | 166 FX_Free(pContentArray); |
| 168 } else if (CPDF_Stream* pStream = pContent->AsStream()) { | 167 } else if (CPDF_Stream* pStream = pContent->AsStream()) { |
| 169 CPDF_StreamAcc contentStream; | 168 CPDF_StreamAcc contentStream; |
| 170 contentStream.LoadAllData(pStream); | 169 contentStream.LoadAllData(pStream); |
| 171 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); | 170 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); |
| 172 } | 171 } |
| 173 CPDF_Stream* pStream = new CPDF_Stream; | 172 CPDF_Stream* pStream = m_pDocument->AddIndirectStream(); |
| 174 pStream->SetData(buf.GetBuffer(), buf.GetLength()); | 173 pStream->SetData(buf.GetBuffer(), buf.GetLength()); |
| 175 m_pPage->m_pFormDict->SetReferenceFor( | 174 m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, pStream); |
| 176 "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream)); | |
| 177 } | 175 } |
| OLD | NEW |