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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 continue; | 390 continue; |
391 pAPStream = pFirstObj->AsStream(); | 391 pAPStream = pFirstObj->AsStream(); |
392 } | 392 } |
393 } | 393 } |
394 } | 394 } |
395 } | 395 } |
396 if (!pAPStream) | 396 if (!pAPStream) |
397 continue; | 397 continue; |
398 | 398 |
399 CPDF_Dictionary* pAPDic = pAPStream->GetDict(); | 399 CPDF_Dictionary* pAPDic = pAPStream->GetDict(); |
400 CFX_Matrix matrix = pAPDic->GetMatrixFor("Matrix"); | |
401 | |
402 CFX_FloatRect rcStream; | 400 CFX_FloatRect rcStream; |
403 if (pAPDic->KeyExist("Rect")) | 401 if (pAPDic->KeyExist("Rect")) |
404 rcStream = pAPDic->GetRectFor("Rect"); | 402 rcStream = pAPDic->GetRectFor("Rect"); |
405 else if (pAPDic->KeyExist("BBox")) | 403 else if (pAPDic->KeyExist("BBox")) |
406 rcStream = pAPDic->GetRectFor("BBox"); | 404 rcStream = pAPDic->GetRectFor("BBox"); |
407 | 405 |
408 if (rcStream.IsEmpty()) | 406 if (rcStream.IsEmpty()) |
409 continue; | 407 continue; |
410 | 408 |
411 CPDF_Object* pObj = pAPStream; | 409 CPDF_Object* pObj = pAPStream; |
| 410 if (pObj->IsInline()) { |
| 411 pObj = pObj->Clone(); |
| 412 pDocument->AddIndirectObject(pObj); |
| 413 } |
412 | 414 |
413 if (pObj) { | 415 CPDF_Dictionary* pObjDic = pObj->GetDict(); |
414 CPDF_Dictionary* pObjDic = pObj->GetDict(); | 416 if (pObjDic) { |
415 if (pObjDic) { | 417 pObjDic->SetNameFor("Type", "XObject"); |
416 pObjDic->SetNameFor("Type", "XObject"); | 418 pObjDic->SetNameFor("Subtype", "Form"); |
417 pObjDic->SetNameFor("Subtype", "Form"); | |
418 } | |
419 } | 419 } |
420 | 420 |
421 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject"); | 421 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject"); |
422 if (!pXObject) { | 422 if (!pXObject) { |
423 pXObject = new CPDF_Dictionary(pDocument->GetByteStringPool()); | 423 pXObject = new CPDF_Dictionary(pDocument->GetByteStringPool()); |
424 pNewXORes->SetFor("XObject", pXObject); | 424 pNewXORes->SetFor("XObject", pXObject); |
425 } | 425 } |
426 | 426 |
427 CFX_ByteString sFormName; | 427 CFX_ByteString sFormName; |
428 sFormName.Format("F%d", i); | 428 sFormName.Format("F%d", i); |
429 pXObject->SetReferenceFor(sFormName, pDocument, | 429 pXObject->SetReferenceFor(sFormName, pDocument, pObj->GetObjNum()); |
430 pDocument->AddIndirectObject(pObj)); | |
431 | 430 |
432 CPDF_StreamAcc acc; | 431 CPDF_StreamAcc acc; |
433 acc.LoadAllData(pNewXObject); | 432 acc.LoadAllData(pNewXObject); |
434 | 433 |
435 const uint8_t* pData = acc.GetData(); | 434 const uint8_t* pData = acc.GetData(); |
436 CFX_ByteString sStream(pData, acc.GetSize()); | 435 CFX_ByteString sStream(pData, acc.GetSize()); |
437 | 436 CFX_Matrix matrix = pAPDic->GetMatrixFor("Matrix"); |
438 if (matrix.IsIdentity()) { | 437 if (matrix.IsIdentity()) { |
439 matrix.a = 1.0f; | 438 matrix.a = 1.0f; |
440 matrix.b = 0.0f; | 439 matrix.b = 0.0f; |
441 matrix.c = 0.0f; | 440 matrix.c = 0.0f; |
442 matrix.d = 1.0f; | 441 matrix.d = 1.0f; |
443 matrix.e = 0.0f; | 442 matrix.e = 0.0f; |
444 matrix.f = 0.0f; | 443 matrix.f = 0.0f; |
445 } | 444 } |
446 | 445 |
447 CFX_ByteString sTemp; | 446 CFX_ByteString sTemp; |
448 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); | 447 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); |
449 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, | 448 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, |
450 sFormName.c_str()); | 449 sFormName.c_str()); |
451 sStream += sTemp; | 450 sStream += sTemp; |
452 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength()); | 451 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength()); |
453 } | 452 } |
454 pPageDict->RemoveFor("Annots"); | 453 pPageDict->RemoveFor("Annots"); |
455 | 454 |
456 RectArray.RemoveAll(); | 455 RectArray.RemoveAll(); |
457 return FLATTEN_SUCCESS; | 456 return FLATTEN_SUCCESS; |
458 } | 457 } |
OLD | NEW |