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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 pPageDic ? pPageDic->GetObjectFor("Contents") : nullptr; | 121 pPageDic ? pPageDic->GetObjectFor("Contents") : nullptr; |
122 if (!pContentObj) | 122 if (!pContentObj) |
123 pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr; | 123 pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr; |
124 if (!pContentObj) | 124 if (!pContentObj) |
125 return false; | 125 return false; |
126 | 126 |
127 CPDF_Document* pDoc = pPage->m_pDocument; | 127 CPDF_Document* pDoc = pPage->m_pDocument; |
128 if (!pDoc) | 128 if (!pDoc) |
129 return false; | 129 return false; |
130 | 130 |
131 CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 131 CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>( |
132 CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic); | 132 nullptr, 0, |
| 133 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool())); |
133 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize()); | 134 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize()); |
134 | 135 |
135 pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 136 CPDF_Stream* pEndStream = pDoc->NewIndirect<CPDF_Stream>( |
136 | 137 nullptr, 0, |
137 CPDF_Stream* pEndStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic); | 138 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool())); |
138 pEndStream->SetData((const uint8_t*)" Q", 2); | 139 pEndStream->SetData((const uint8_t*)" Q", 2); |
139 | 140 |
140 CPDF_Array* pContentArray = nullptr; | 141 CPDF_Array* pContentArray = nullptr; |
141 CPDF_Array* pArray = ToArray(pContentObj); | 142 CPDF_Array* pArray = ToArray(pContentObj); |
142 if (pArray) { | 143 if (pArray) { |
143 pContentArray = pArray; | 144 pContentArray = pArray; |
144 pContentArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum()); | 145 pContentArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum()); |
145 pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum()); | 146 pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum()); |
146 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { | 147 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { |
147 CPDF_Object* pDirectObj = pReference->GetDirect(); | 148 CPDF_Object* pDirectObj = pReference->GetDirect(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 if (iClipType == FXFILL_WINDING) | 296 if (iClipType == FXFILL_WINDING) |
296 strClip << "W n\n"; | 297 strClip << "W n\n"; |
297 else | 298 else |
298 strClip << "W* n\n"; | 299 strClip << "W* n\n"; |
299 } | 300 } |
300 } | 301 } |
301 CPDF_Document* pDoc = pPage->m_pDocument; | 302 CPDF_Document* pDoc = pPage->m_pDocument; |
302 if (!pDoc) | 303 if (!pDoc) |
303 return; | 304 return; |
304 | 305 |
305 CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 306 CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>( |
306 CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic); | 307 nullptr, 0, |
| 308 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool())); |
307 pStream->SetData(strClip.GetBuffer(), strClip.GetSize()); | 309 pStream->SetData(strClip.GetBuffer(), strClip.GetSize()); |
308 | 310 |
309 CPDF_Array* pArray = ToArray(pContentObj); | 311 CPDF_Array* pArray = ToArray(pContentObj); |
310 if (pArray) { | 312 if (pArray) { |
311 pArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum()); | 313 pArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum()); |
312 return; | 314 return; |
313 } | 315 } |
314 CPDF_Reference* pReference = ToReference(pContentObj); | 316 CPDF_Reference* pReference = ToReference(pContentObj); |
315 if (!pReference) | 317 if (!pReference) |
316 return; | 318 return; |
317 | 319 |
318 CPDF_Object* pDirectObj = pReference->GetDirect(); | 320 CPDF_Object* pDirectObj = pReference->GetDirect(); |
319 if (!pDirectObj) | 321 if (!pDirectObj) |
320 return; | 322 return; |
321 | 323 |
322 CPDF_Array* pObjArray = pDirectObj->AsArray(); | 324 CPDF_Array* pObjArray = pDirectObj->AsArray(); |
323 if (pObjArray) { | 325 if (pObjArray) { |
324 pObjArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum()); | 326 pObjArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum()); |
325 return; | 327 return; |
326 } | 328 } |
327 if (pDirectObj->IsStream()) { | 329 if (pDirectObj->IsStream()) { |
328 CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>(); | 330 CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>(); |
329 pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum()); | 331 pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum()); |
330 pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum()); | 332 pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum()); |
331 pPageDic->SetNewFor<CPDF_Reference>("Contents", pDoc, | 333 pPageDic->SetNewFor<CPDF_Reference>("Contents", pDoc, |
332 pContentArray->GetObjNum()); | 334 pContentArray->GetObjNum()); |
333 } | 335 } |
334 } | 336 } |
OLD | NEW |