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