| 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 "public/fpdf_transformpage.h" | 7 #include "public/fpdf_transformpage.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/page/cpdf_clippath.h" | 9 #include "core/fpdfapi/page/cpdf_clippath.h" |
| 10 #include "core/fpdfapi/page/cpdf_page.h" | 10 #include "core/fpdfapi/page/cpdf_page.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 if (!pContentObj) | 123 if (!pContentObj) |
| 124 pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr; | 124 pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr; |
| 125 if (!pContentObj) | 125 if (!pContentObj) |
| 126 return false; | 126 return false; |
| 127 | 127 |
| 128 CPDF_Document* pDoc = pPage->m_pDocument; | 128 CPDF_Document* pDoc = pPage->m_pDocument; |
| 129 if (!pDoc) | 129 if (!pDoc) |
| 130 return false; | 130 return false; |
| 131 | 131 |
| 132 CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 132 CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 133 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); | 133 CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic); |
| 134 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize()); | 134 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize()); |
| 135 pDoc->AddIndirectObject(pStream); | 135 |
| 136 pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 136 pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 137 | 137 |
| 138 CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic); | 138 CPDF_Stream* pEndStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic); |
| 139 pEndStream->SetData((const uint8_t*)" Q", 2); | 139 pEndStream->SetData((const uint8_t*)" Q", 2); |
| 140 pDoc->AddIndirectObject(pEndStream); | |
| 141 | 140 |
| 142 CPDF_Array* pContentArray = nullptr; | 141 CPDF_Array* pContentArray = nullptr; |
| 143 CPDF_Array* pArray = ToArray(pContentObj); | 142 CPDF_Array* pArray = ToArray(pContentObj); |
| 144 if (pArray) { | 143 if (pArray) { |
| 145 pContentArray = pArray; | 144 pContentArray = pArray; |
| 146 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); | 145 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
| 147 pContentArray->InsertAt(0, pRef); | 146 pContentArray->InsertAt(0, pRef); |
| 148 pContentArray->AddReference(pDoc, pEndStream->GetObjNum()); | 147 pContentArray->AddReference(pDoc, pEndStream->GetObjNum()); |
| 149 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { | 148 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { |
| 150 CPDF_Object* pDirectObj = pReference->GetDirect(); | 149 CPDF_Object* pDirectObj = pReference->GetDirect(); |
| 151 if (pDirectObj) { | 150 if (pDirectObj) { |
| 152 CPDF_Array* pObjArray = pDirectObj->AsArray(); | 151 CPDF_Array* pObjArray = pDirectObj->AsArray(); |
| 153 if (pObjArray) { | 152 if (pObjArray) { |
| 154 pContentArray = pObjArray; | 153 pContentArray = pObjArray; |
| 155 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); | 154 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
| 156 pContentArray->InsertAt(0, pRef); | 155 pContentArray->InsertAt(0, pRef); |
| 157 pContentArray->AddReference(pDoc, pEndStream->GetObjNum()); | 156 pContentArray->AddReference(pDoc, pEndStream->GetObjNum()); |
| 158 } else if (pDirectObj->IsStream()) { | 157 } else if (pDirectObj->IsStream()) { |
| 159 pContentArray = new CPDF_Array(); | 158 pContentArray = pDoc->NewIndirect<CPDF_Array>(); |
| 160 pContentArray->AddReference(pDoc, pStream->GetObjNum()); | 159 pContentArray->AddReference(pDoc, pStream->GetObjNum()); |
| 161 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); | 160 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); |
| 162 pContentArray->AddReference(pDoc, pEndStream->GetObjNum()); | 161 pContentArray->AddReference(pDoc, pEndStream->GetObjNum()); |
| 163 pPageDic->SetReferenceFor("Contents", pDoc, | 162 pPageDic->SetReferenceFor("Contents", pDoc, pContentArray); |
| 164 pDoc->AddIndirectObject(pContentArray)); | |
| 165 } | 163 } |
| 166 } | 164 } |
| 167 } | 165 } |
| 168 | 166 |
| 169 // Need to transform the patterns as well. | 167 // Need to transform the patterns as well. |
| 170 CPDF_Dictionary* pRes = pPageDic->GetDictFor("Resources"); | 168 CPDF_Dictionary* pRes = pPageDic->GetDictFor("Resources"); |
| 171 if (pRes) { | 169 if (pRes) { |
| 172 CPDF_Dictionary* pPattenDict = pRes->GetDictFor("Pattern"); | 170 CPDF_Dictionary* pPattenDict = pRes->GetDictFor("Pattern"); |
| 173 if (pPattenDict) { | 171 if (pPattenDict) { |
| 174 for (const auto& it : *pPattenDict) { | 172 for (const auto& it : *pPattenDict) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 strClip << "W n\n"; | 297 strClip << "W n\n"; |
| 300 else | 298 else |
| 301 strClip << "W* n\n"; | 299 strClip << "W* n\n"; |
| 302 } | 300 } |
| 303 } | 301 } |
| 304 CPDF_Document* pDoc = pPage->m_pDocument; | 302 CPDF_Document* pDoc = pPage->m_pDocument; |
| 305 if (!pDoc) | 303 if (!pDoc) |
| 306 return; | 304 return; |
| 307 | 305 |
| 308 CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 306 CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 309 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); | 307 CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic); |
| 310 pStream->SetData(strClip.GetBuffer(), strClip.GetSize()); | 308 pStream->SetData(strClip.GetBuffer(), strClip.GetSize()); |
| 311 pDoc->AddIndirectObject(pStream); | |
| 312 | 309 |
| 313 CPDF_Array* pContentArray = nullptr; | 310 CPDF_Array* pContentArray = nullptr; |
| 314 CPDF_Array* pArray = ToArray(pContentObj); | 311 CPDF_Array* pArray = ToArray(pContentObj); |
| 315 if (pArray) { | 312 if (pArray) { |
| 316 pContentArray = pArray; | 313 pContentArray = pArray; |
| 317 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); | 314 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
| 318 pContentArray->InsertAt(0, pRef); | 315 pContentArray->InsertAt(0, pRef); |
| 319 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { | 316 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { |
| 320 CPDF_Object* pDirectObj = pReference->GetDirect(); | 317 CPDF_Object* pDirectObj = pReference->GetDirect(); |
| 321 if (pDirectObj) { | 318 if (pDirectObj) { |
| 322 CPDF_Array* pObjArray = pDirectObj->AsArray(); | 319 CPDF_Array* pObjArray = pDirectObj->AsArray(); |
| 323 if (pObjArray) { | 320 if (pObjArray) { |
| 324 pContentArray = pObjArray; | 321 pContentArray = pObjArray; |
| 325 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); | 322 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
| 326 pContentArray->InsertAt(0, pRef); | 323 pContentArray->InsertAt(0, pRef); |
| 327 } else if (pDirectObj->IsStream()) { | 324 } else if (pDirectObj->IsStream()) { |
| 328 pContentArray = new CPDF_Array(); | 325 pContentArray = pDoc->NewIndirect<CPDF_Array>(); |
| 329 pContentArray->AddReference(pDoc, pStream->GetObjNum()); | 326 pContentArray->AddReference(pDoc, pStream->GetObjNum()); |
| 330 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); | 327 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); |
| 331 pPageDic->SetReferenceFor("Contents", pDoc, | 328 pPageDic->SetReferenceFor("Contents", pDoc, pContentArray); |
| 332 pDoc->AddIndirectObject(pContentArray)); | |
| 333 } | 329 } |
| 334 } | 330 } |
| 335 } | 331 } |
| 336 } | 332 } |
| OLD | NEW |