| 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 17 matching lines...) Expand all Loading... |
| 28 if (rect.left - rcPage.left < -10.000001f || | 28 if (rect.left - rcPage.left < -10.000001f || |
| 29 rect.right - rcPage.right > 10.000001f || | 29 rect.right - rcPage.right > 10.000001f || |
| 30 rect.top - rcPage.top > 10.000001f || | 30 rect.top - rcPage.top > 10.000001f || |
| 31 rect.bottom - rcPage.bottom < -10.000001f) | 31 rect.bottom - rcPage.bottom < -10.000001f) |
| 32 return FALSE; | 32 return FALSE; |
| 33 } | 33 } |
| 34 | 34 |
| 35 return TRUE; | 35 return TRUE; |
| 36 } | 36 } |
| 37 | 37 |
| 38 FX_BOOL GetContentsRect(CPDF_Document* pDoc, | 38 void GetContentsRect(CPDF_Document* pDoc, |
| 39 CPDF_Dictionary* pDict, | 39 CPDF_Dictionary* pDict, |
| 40 CPDF_RectArray* pRectArray) { | 40 CPDF_RectArray* pRectArray) { |
| 41 CPDF_Page* pPDFPage = new CPDF_Page; | 41 std::unique_ptr<CPDF_Page> pPDFPage(new CPDF_Page); |
| 42 pPDFPage->Load(pDoc, pDict, FALSE); | 42 pPDFPage->Load(pDoc, pDict, FALSE); |
| 43 pPDFPage->ParseContent(nullptr); | 43 pPDFPage->ParseContent(nullptr); |
| 44 | 44 |
| 45 FX_POSITION pos = pPDFPage->GetPageObjectList()->GetHeadPosition(); | 45 for (auto& pPageObject : *pPDFPage->GetPageObjectList()) { |
| 46 while (pos) { | |
| 47 CPDF_PageObject* pPageObject = | |
| 48 pPDFPage->GetPageObjectList()->GetNextObject(pos); | |
| 49 if (!pPageObject) | 46 if (!pPageObject) |
| 50 continue; | 47 continue; |
| 51 | 48 |
| 52 CPDF_Rect rc; | 49 CPDF_Rect rc; |
| 53 rc.left = pPageObject->m_Left; | 50 rc.left = pPageObject->m_Left; |
| 54 rc.right = pPageObject->m_Right; | 51 rc.right = pPageObject->m_Right; |
| 55 rc.bottom = pPageObject->m_Bottom; | 52 rc.bottom = pPageObject->m_Bottom; |
| 56 rc.top = pPageObject->m_Top; | 53 rc.top = pPageObject->m_Top; |
| 57 | 54 if (IsValiableRect(rc, pDict->GetRectBy("MediaBox"))) |
| 58 if (IsValiableRect(rc, pDict->GetRectBy("MediaBox"))) { | |
| 59 pRectArray->Add(rc); | 55 pRectArray->Add(rc); |
| 60 } | |
| 61 } | 56 } |
| 62 | |
| 63 delete pPDFPage; | |
| 64 return TRUE; | |
| 65 } | 57 } |
| 66 | 58 |
| 67 void ParserStream(CPDF_Dictionary* pPageDic, | 59 void ParserStream(CPDF_Dictionary* pPageDic, |
| 68 CPDF_Dictionary* pStream, | 60 CPDF_Dictionary* pStream, |
| 69 CPDF_RectArray* pRectArray, | 61 CPDF_RectArray* pRectArray, |
| 70 CPDF_ObjectArray* pObjectArray) { | 62 CPDF_ObjectArray* pObjectArray) { |
| 71 if (!pStream) | 63 if (!pStream) |
| 72 return; | 64 return; |
| 73 CPDF_Rect rect; | 65 CPDF_Rect rect; |
| 74 if (pStream->KeyExist("Rect")) | 66 if (pStream->KeyExist("Rect")) |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | 506 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, |
| 515 FALSE); | 507 FALSE); |
| 516 } | 508 } |
| 517 pPageDict->RemoveAt("Annots"); | 509 pPageDict->RemoveAt("Annots"); |
| 518 | 510 |
| 519 ObjectArray.RemoveAll(); | 511 ObjectArray.RemoveAll(); |
| 520 RectArray.RemoveAll(); | 512 RectArray.RemoveAll(); |
| 521 | 513 |
| 522 return FLATTEN_SUCCESS; | 514 return FLATTEN_SUCCESS; |
| 523 } | 515 } |
| OLD | NEW |