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