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