Chromium Code Reviews| 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->NewIndirect<CPDF_Stream>(); |
| 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 uint32_t dwResourceObjNum, | 61 uint32_t dwResourceObjNum, |
| 63 const CFX_ByteString& bsType) { | 62 const CFX_ByteString& bsType) { |
| 64 ASSERT(dwResourceObjNum); | 63 ASSERT(dwResourceObjNum); |
| 65 if (!m_pPage->m_pResources) { | 64 if (!m_pPage->m_pResources) { |
| 66 m_pPage->m_pResources = | 65 m_pPage->m_pResources = m_pDocument->NewIndirect<CPDF_Dictionary>( |
| 67 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 66 m_pDocument->GetByteStringPool()); |
| 68 m_pPage->m_pFormDict->SetReferenceFor( | 67 m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, |
| 69 "Resources", m_pDocument, | 68 m_pPage->m_pResources); |
| 70 m_pDocument->AddIndirectObject(m_pPage->m_pResources)); | |
| 71 } | 69 } |
| 72 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); | 70 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); |
| 73 if (!pResList) { | 71 if (!pResList) { |
| 74 pResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 72 pResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); |
| 75 m_pPage->m_pResources->SetFor(bsType, pResList); | 73 m_pPage->m_pResources->SetFor(bsType, pResList); |
| 76 } | 74 } |
| 77 CFX_ByteString name; | 75 CFX_ByteString name; |
| 78 int idnum = 1; | 76 int idnum = 1; |
| 79 while (1) { | 77 while (1) { |
| 80 name.Format("FX%c%d", bsType[0], idnum); | 78 name.Format("FX%c%d", bsType[0], idnum); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 | 124 |
| 127 CFX_FloatRect bbox = m_pPage->GetPageBBox(); | 125 CFX_FloatRect bbox = m_pPage->GetPageBBox(); |
| 128 matrix.TransformRect(bbox); | 126 matrix.TransformRect(bbox); |
| 129 | 127 |
| 130 CPDF_Dictionary* pFormDict = | 128 CPDF_Dictionary* pFormDict = |
| 131 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 129 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); |
| 132 pFormDict->SetNameFor("Type", "XObject"); | 130 pFormDict->SetNameFor("Type", "XObject"); |
| 133 pFormDict->SetNameFor("Subtype", "Form"); | 131 pFormDict->SetNameFor("Subtype", "Form"); |
| 134 pFormDict->SetRectFor("BBox", bbox); | 132 pFormDict->SetRectFor("BBox", bbox); |
| 135 | 133 |
| 136 CPDF_Stream* pStream = new CPDF_Stream; | 134 CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); |
| 137 pStream->InitStream(data, size, pFormDict); | 135 pStream->InitStream(data, size, pFormDict); |
| 138 | 136 |
| 139 CFX_ByteString name = | 137 CFX_ByteString name = RealizeResource(pStream->GetObjNum(), "XObject"); |
|
dsinclair
2016/11/15 18:55:51
Why does this one need the extra ->GetObjNum when
Tom Sepez
2016/11/15 19:15:16
which other ones? RealizeResource() only takes ob
| |
| 140 RealizeResource(m_pDocument->AddIndirectObject(pStream), "XObject"); | |
| 141 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; | 138 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; |
| 142 } | 139 } |
| 143 | 140 |
| 144 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { | 141 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { |
| 145 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; | 142 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; |
| 146 CPDF_Object* pContent = | 143 CPDF_Object* pContent = |
| 147 pDict ? pDict->GetDirectObjectFor("Contents") : nullptr; | 144 pDict ? pDict->GetDirectObjectFor("Contents") : nullptr; |
| 148 if (!pContent) | 145 if (!pContent) |
| 149 return; | 146 return; |
| 150 | 147 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 174 delete pContentArray[i]; | 171 delete pContentArray[i]; |
| 175 } | 172 } |
| 176 ProcessForm(buf, pBuf, size, matrix); | 173 ProcessForm(buf, pBuf, size, matrix); |
| 177 FX_Free(pBuf); | 174 FX_Free(pBuf); |
| 178 FX_Free(pContentArray); | 175 FX_Free(pContentArray); |
| 179 } else if (CPDF_Stream* pStream = pContent->AsStream()) { | 176 } else if (CPDF_Stream* pStream = pContent->AsStream()) { |
| 180 CPDF_StreamAcc contentStream; | 177 CPDF_StreamAcc contentStream; |
| 181 contentStream.LoadAllData(pStream); | 178 contentStream.LoadAllData(pStream); |
| 182 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); | 179 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); |
| 183 } | 180 } |
| 184 CPDF_Stream* pStream = new CPDF_Stream; | 181 CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); |
| 185 pStream->SetData(buf.GetBuffer(), buf.GetLength()); | 182 pStream->SetData(buf.GetBuffer(), buf.GetLength()); |
| 186 m_pPage->m_pFormDict->SetReferenceFor( | 183 m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, pStream); |
| 187 "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream)); | |
| 188 } | 184 } |
| OLD | NEW |