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 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 CPDF_Dictionary* pPage, | 187 CPDF_Dictionary* pPage, |
188 CPDF_Document* pDocument) { | 188 CPDF_Document* pDocument) { |
189 CPDF_Object* pContentsObj = pPage->GetStreamBy("Contents"); | 189 CPDF_Object* pContentsObj = pPage->GetStreamBy("Contents"); |
190 if (!pContentsObj) { | 190 if (!pContentsObj) { |
191 pContentsObj = pPage->GetArrayBy("Contents"); | 191 pContentsObj = pPage->GetArrayBy("Contents"); |
192 } | 192 } |
193 | 193 |
194 if (!pContentsObj) { | 194 if (!pContentsObj) { |
195 // Create a new contents dictionary | 195 // Create a new contents dictionary |
196 if (!key.IsEmpty()) { | 196 if (!key.IsEmpty()) { |
197 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); | 197 CPDF_Stream* pNewContents = |
| 198 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); |
198 pPage->SetAtReference("Contents", pDocument, | 199 pPage->SetAtReference("Contents", pDocument, |
199 pDocument->AddIndirectObject(pNewContents)); | 200 pDocument->AddIndirectObject(pNewContents)); |
200 | 201 |
201 CFX_ByteString sStream; | 202 CFX_ByteString sStream; |
202 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 203 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
203 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, | 204 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, |
204 FALSE); | 205 FALSE); |
205 } | 206 } |
206 return; | 207 return; |
207 } | 208 } |
208 | 209 |
209 CPDF_Array* pContentsArray = NULL; | 210 CPDF_Array* pContentsArray = nullptr; |
210 | 211 |
211 switch (pContentsObj->GetType()) { | 212 switch (pContentsObj->GetType()) { |
212 case CPDF_Object::STREAM: { | 213 case CPDF_Object::STREAM: { |
213 pContentsArray = new CPDF_Array; | 214 pContentsArray = new CPDF_Array; |
214 CPDF_Stream* pContents = pContentsObj->AsStream(); | 215 CPDF_Stream* pContents = pContentsObj->AsStream(); |
215 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents); | 216 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents); |
216 CPDF_StreamAcc acc; | 217 CPDF_StreamAcc acc; |
217 acc.LoadAllData(pContents); | 218 acc.LoadAllData(pContents); |
218 CFX_ByteString sStream = "q\n"; | 219 CFX_ByteString sStream = "q\n"; |
219 CFX_ByteString sBody = | 220 CFX_ByteString sBody = |
(...skipping 12 matching lines...) Expand all Loading... |
232 break; | 233 break; |
233 } | 234 } |
234 | 235 |
235 if (!pContentsArray) | 236 if (!pContentsArray) |
236 return; | 237 return; |
237 | 238 |
238 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray); | 239 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray); |
239 pPage->SetAtReference("Contents", pDocument, dwObjNum); | 240 pPage->SetAtReference("Contents", pDocument, dwObjNum); |
240 | 241 |
241 if (!key.IsEmpty()) { | 242 if (!key.IsEmpty()) { |
242 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); | 243 CPDF_Stream* pNewContents = |
| 244 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); |
243 dwObjNum = pDocument->AddIndirectObject(pNewContents); | 245 dwObjNum = pDocument->AddIndirectObject(pNewContents); |
244 pContentsArray->AddReference(pDocument, dwObjNum); | 246 pContentsArray->AddReference(pDocument, dwObjNum); |
245 | 247 |
246 CFX_ByteString sStream; | 248 CFX_ByteString sStream; |
247 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 249 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
248 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); | 250 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); |
249 } | 251 } |
250 } | 252 } |
251 | 253 |
252 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, | 254 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 pCropBox->Add(new CPDF_Number(rcOriginalCB.top)); | 371 pCropBox->Add(new CPDF_Number(rcOriginalCB.top)); |
370 pPageDict->SetAt("ArtBox", pCropBox); | 372 pPageDict->SetAt("ArtBox", pCropBox); |
371 } | 373 } |
372 | 374 |
373 CPDF_Dictionary* pRes = pPageDict->GetDictBy("Resources"); | 375 CPDF_Dictionary* pRes = pPageDict->GetDictBy("Resources"); |
374 if (!pRes) { | 376 if (!pRes) { |
375 pRes = new CPDF_Dictionary; | 377 pRes = new CPDF_Dictionary; |
376 pPageDict->SetAt("Resources", pRes); | 378 pPageDict->SetAt("Resources", pRes); |
377 } | 379 } |
378 | 380 |
379 CPDF_Stream* pNewXObject = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); | 381 CPDF_Stream* pNewXObject = new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); |
380 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject); | 382 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject); |
381 CPDF_Dictionary* pPageXObject = pRes->GetDictBy("XObject"); | 383 CPDF_Dictionary* pPageXObject = pRes->GetDictBy("XObject"); |
382 if (!pPageXObject) { | 384 if (!pPageXObject) { |
383 pPageXObject = new CPDF_Dictionary; | 385 pPageXObject = new CPDF_Dictionary; |
384 pRes->SetAt("XObject", pPageXObject); | 386 pRes->SetAt("XObject", pPageXObject); |
385 } | 387 } |
386 | 388 |
387 CFX_ByteString key = ""; | 389 CFX_ByteString key = ""; |
388 int nStreams = ObjectArray.GetSize(); | 390 int nStreams = ObjectArray.GetSize(); |
389 | 391 |
390 if (nStreams > 0) { | 392 if (nStreams > 0) { |
391 for (int iKey = 0; /*iKey < 100*/; iKey++) { | 393 for (int iKey = 0; /*iKey < 100*/; iKey++) { |
392 char sExtend[5] = {}; | 394 char sExtend[5] = {}; |
393 FXSYS_itoa(iKey, sExtend, 10); | 395 FXSYS_itoa(iKey, sExtend, 10); |
394 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend); | 396 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend); |
395 if (!pPageXObject->KeyExist(key)) | 397 if (!pPageXObject->KeyExist(key)) |
396 break; | 398 break; |
397 } | 399 } |
398 } | 400 } |
399 | 401 |
400 SetPageContents(key, pPageDict, pDocument); | 402 SetPageContents(key, pPageDict, pDocument); |
401 | 403 |
402 CPDF_Dictionary* pNewXORes = NULL; | 404 CPDF_Dictionary* pNewXORes = nullptr; |
403 | 405 |
404 if (!key.IsEmpty()) { | 406 if (!key.IsEmpty()) { |
405 pPageXObject->SetAtReference(key, pDocument, dwObjNum); | 407 pPageXObject->SetAtReference(key, pDocument, dwObjNum); |
406 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); | 408 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); |
407 pNewXORes = new CPDF_Dictionary; | 409 pNewXORes = new CPDF_Dictionary; |
408 pNewOXbjectDic->SetAt("Resources", pNewXORes); | 410 pNewOXbjectDic->SetAt("Resources", pNewXORes); |
409 pNewOXbjectDic->SetAtName("Type", "XObject"); | 411 pNewOXbjectDic->SetAtName("Type", "XObject"); |
410 pNewOXbjectDic->SetAtName("Subtype", "Form"); | 412 pNewOXbjectDic->SetAtName("Subtype", "Form"); |
411 pNewOXbjectDic->SetAtInteger("FormType", 1); | 413 pNewOXbjectDic->SetAtInteger("FormType", 1); |
412 pNewOXbjectDic->SetAtName("Name", "FRM"); | 414 pNewOXbjectDic->SetAtName("Name", "FRM"); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 sStream += sTemp; | 509 sStream += sTemp; |
508 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); | 510 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); |
509 } | 511 } |
510 pPageDict->RemoveAt("Annots"); | 512 pPageDict->RemoveAt("Annots"); |
511 | 513 |
512 ObjectArray.RemoveAll(); | 514 ObjectArray.RemoveAll(); |
513 RectArray.RemoveAll(); | 515 RectArray.RemoveAll(); |
514 | 516 |
515 return FLATTEN_SUCCESS; | 517 return FLATTEN_SUCCESS; |
516 } | 518 } |
OLD | NEW |