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_flatten.h" | 7 #include "../../public/fpdf_flatten.h" |
8 #include "../include/fsdk_define.h" | 8 #include "../include/fsdk_define.h" |
9 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 9 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
10 #include "../include/fpdfxfa/fpdfxfa_page.h" | 10 #include "../include/fpdfxfa/fpdfxfa_page.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 CPDF_Dictionary* pPage, | 189 CPDF_Dictionary* pPage, |
190 CPDF_Document* pDocument) { | 190 CPDF_Document* pDocument) { |
191 CPDF_Object* pContentsObj = pPage->GetStream("Contents"); | 191 CPDF_Object* pContentsObj = pPage->GetStream("Contents"); |
192 if (!pContentsObj) { | 192 if (!pContentsObj) { |
193 pContentsObj = pPage->GetArray("Contents"); | 193 pContentsObj = pPage->GetArray("Contents"); |
194 } | 194 } |
195 | 195 |
196 if (!pContentsObj) { | 196 if (!pContentsObj) { |
197 // Create a new contents dictionary | 197 // Create a new contents dictionary |
198 if (!key.IsEmpty()) { | 198 if (!key.IsEmpty()) { |
199 CPDF_Stream* pNewContents = | 199 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); |
200 new CPDF_Stream(NULL, 0, new CPDF_Dictionary); | |
201 if (!pNewContents) | 200 if (!pNewContents) |
202 return; | 201 return; |
203 pPage->SetAtReference("Contents", pDocument, | 202 pPage->SetAtReference("Contents", pDocument, |
204 pDocument->AddIndirectObject(pNewContents)); | 203 pDocument->AddIndirectObject(pNewContents)); |
205 | 204 |
206 CFX_ByteString sStream; | 205 CFX_ByteString sStream; |
207 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 206 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
208 pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | 207 pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, |
209 FALSE); | 208 FALSE); |
210 } | 209 } |
(...skipping 28 matching lines...) Expand all Loading... |
239 break; | 238 break; |
240 } | 239 } |
241 | 240 |
242 if (!pContentsArray) | 241 if (!pContentsArray) |
243 return; | 242 return; |
244 | 243 |
245 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContentsArray); | 244 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContentsArray); |
246 pPage->SetAtReference("Contents", pDocument, dwObjNum); | 245 pPage->SetAtReference("Contents", pDocument, dwObjNum); |
247 | 246 |
248 if (!key.IsEmpty()) { | 247 if (!key.IsEmpty()) { |
249 CPDF_Stream* pNewContents = | 248 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); |
250 new CPDF_Stream(NULL, 0, new CPDF_Dictionary); | |
251 dwObjNum = pDocument->AddIndirectObject(pNewContents); | 249 dwObjNum = pDocument->AddIndirectObject(pNewContents); |
252 pContentsArray->AddReference(pDocument, dwObjNum); | 250 pContentsArray->AddReference(pDocument, dwObjNum); |
253 | 251 |
254 CFX_ByteString sStream; | 252 CFX_ByteString sStream; |
255 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 253 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
256 pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | 254 pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, |
257 FALSE); | 255 FALSE); |
258 } | 256 } |
259 } | 257 } |
260 | 258 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 pPageDict->SetAt("ArtBox", pCropBox); | 382 pPageDict->SetAt("ArtBox", pCropBox); |
385 } | 383 } |
386 | 384 |
387 CPDF_Dictionary* pRes = NULL; | 385 CPDF_Dictionary* pRes = NULL; |
388 pRes = pPageDict->GetDict("Resources"); | 386 pRes = pPageDict->GetDict("Resources"); |
389 if (!pRes) { | 387 if (!pRes) { |
390 pRes = new CPDF_Dictionary; | 388 pRes = new CPDF_Dictionary; |
391 pPageDict->SetAt("Resources", pRes); | 389 pPageDict->SetAt("Resources", pRes); |
392 } | 390 } |
393 | 391 |
394 CPDF_Stream* pNewXObject = | 392 CPDF_Stream* pNewXObject = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); |
395 new CPDF_Stream(NULL, 0, new CPDF_Dictionary); | |
396 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject); | 393 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject); |
397 CPDF_Dictionary* pPageXObject = pRes->GetDict("XObject"); | 394 CPDF_Dictionary* pPageXObject = pRes->GetDict("XObject"); |
398 if (!pPageXObject) { | 395 if (!pPageXObject) { |
399 pPageXObject = new CPDF_Dictionary; | 396 pPageXObject = new CPDF_Dictionary; |
400 pRes->SetAt("XObject", pPageXObject); | 397 pRes->SetAt("XObject", pPageXObject); |
401 } | 398 } |
402 | 399 |
403 CFX_ByteString key = ""; | 400 CFX_ByteString key = ""; |
404 int nStreams = ObjectArray.GetSize(); | 401 int nStreams = ObjectArray.GetSize(); |
405 | 402 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | 527 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, |
531 FALSE); | 528 FALSE); |
532 } | 529 } |
533 pPageDict->RemoveAt("Annots"); | 530 pPageDict->RemoveAt("Annots"); |
534 | 531 |
535 ObjectArray.RemoveAll(); | 532 ObjectArray.RemoveAll(); |
536 RectArray.RemoveAll(); | 533 RectArray.RemoveAll(); |
537 | 534 |
538 return FLATTEN_SUCCESS; | 535 return FLATTEN_SUCCESS; |
539 } | 536 } |
OLD | NEW |