Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame^] | 7 | #include "core/fpdfapi/page/cpdf_pageobjectholder.h" |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 8 | |
dsinclair | c6c425a | 2016-09-29 12:01:30 -0700 | [diff] [blame] | 9 | #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame^] | 10 | #include "core/fpdfapi/page/cpdf_pageobject.h" |
| 11 | #include "core/fpdfapi/page/pageint.h" |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 12 | |
| 13 | CPDF_PageObjectHolder::CPDF_PageObjectHolder() |
| 14 | : m_pFormDict(nullptr), |
| 15 | m_pFormStream(nullptr), |
| 16 | m_pDocument(nullptr), |
| 17 | m_pPageResources(nullptr), |
| 18 | m_pResources(nullptr), |
| 19 | m_Transparency(0), |
| 20 | m_bBackgroundAlphaNeeded(FALSE), |
| 21 | m_bHasImageMask(FALSE), |
| 22 | m_ParseState(CONTENT_NOT_PARSED) {} |
| 23 | |
weili | 868150b | 2016-06-13 14:57:29 -0700 | [diff] [blame] | 24 | CPDF_PageObjectHolder::~CPDF_PageObjectHolder() {} |
| 25 | |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 26 | void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) { |
| 27 | if (!m_pParser) { |
| 28 | return; |
| 29 | } |
| 30 | m_pParser->Continue(pPause); |
| 31 | if (m_pParser->GetStatus() == CPDF_ContentParser::Done) { |
| 32 | m_ParseState = CONTENT_PARSED; |
| 33 | m_pParser.reset(); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | void CPDF_PageObjectHolder::Transform(const CFX_Matrix& matrix) { |
| 38 | for (auto& pObj : m_PageObjectList) |
| 39 | pObj->Transform(matrix); |
| 40 | } |
| 41 | |
| 42 | CFX_FloatRect CPDF_PageObjectHolder::CalcBoundingBox() const { |
| 43 | if (m_PageObjectList.empty()) |
| 44 | return CFX_FloatRect(0, 0, 0, 0); |
| 45 | |
| 46 | FX_FLOAT left = 1000000.0f; |
| 47 | FX_FLOAT right = -1000000.0f; |
| 48 | FX_FLOAT bottom = 1000000.0f; |
| 49 | FX_FLOAT top = -1000000.0f; |
| 50 | for (const auto& pObj : m_PageObjectList) { |
| 51 | left = std::min(left, pObj->m_Left); |
| 52 | right = std::max(right, pObj->m_Right); |
| 53 | bottom = std::min(bottom, pObj->m_Bottom); |
| 54 | top = std::max(top, pObj->m_Top); |
| 55 | } |
| 56 | return CFX_FloatRect(left, bottom, right, top); |
| 57 | } |
| 58 | |
| 59 | void CPDF_PageObjectHolder::LoadTransInfo() { |
| 60 | if (!m_pFormDict) { |
| 61 | return; |
| 62 | } |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 63 | CPDF_Dictionary* pGroup = m_pFormDict->GetDictFor("Group"); |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 64 | if (!pGroup) { |
| 65 | return; |
| 66 | } |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 67 | if (pGroup->GetStringFor("S") != "Transparency") { |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 68 | return; |
| 69 | } |
| 70 | m_Transparency |= PDFTRANS_GROUP; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 71 | if (pGroup->GetIntegerFor("I")) { |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 72 | m_Transparency |= PDFTRANS_ISOLATED; |
| 73 | } |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 74 | if (pGroup->GetIntegerFor("K")) { |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 75 | m_Transparency |= PDFTRANS_KNOCKOUT; |
| 76 | } |
| 77 | } |