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
7 #include "core/fpdfapi/page/cpdf_pageobjectholder.h"
8
9 #include <algorithm>
10
11 #include "core/fpdfapi/page/cpdf_allstates.h"
12 #include "core/fpdfapi/page/cpdf_contentparser.h"
13 #include "core/fpdfapi/page/cpdf_pageobject.h"
14 #include "core/fpdfapi/parser/cpdf_dictionary.h"
15
CPDF_PageObjectHolder(CPDF_Document * pDoc,CPDF_Dictionary * pFormDict)16 CPDF_PageObjectHolder::CPDF_PageObjectHolder(CPDF_Document* pDoc,
17 CPDF_Dictionary* pFormDict)
18 : m_pFormDict(pFormDict),
19 m_pFormStream(nullptr),
20 m_pDocument(pDoc),
21 m_pPageResources(nullptr),
22 m_pResources(nullptr),
23 m_iTransparency(0),
24 m_bBackgroundAlphaNeeded(false),
25 m_ParseState(CONTENT_NOT_PARSED) {
26 // TODO(thestig): Check if |m_pFormDict| is never a nullptr and simplify
27 // callers that checks for that.
28 }
29
~CPDF_PageObjectHolder()30 CPDF_PageObjectHolder::~CPDF_PageObjectHolder() {}
31
IsPage() const32 bool CPDF_PageObjectHolder::IsPage() const {
33 return false;
34 }
35
ContinueParse(IFX_PauseIndicator * pPause)36 void CPDF_PageObjectHolder::ContinueParse(IFX_PauseIndicator* pPause) {
37 if (!m_pParser)
38 return;
39
40 if (m_pParser->Continue(pPause))
41 return;
42
43 m_ParseState = CONTENT_PARSED;
44 if (m_pParser->GetCurStates())
45 m_LastCTM = m_pParser->GetCurStates()->m_CTM;
46 m_pParser.reset();
47 }
48
AddImageMaskBoundingBox(const CFX_FloatRect & box)49 void CPDF_PageObjectHolder::AddImageMaskBoundingBox(const CFX_FloatRect& box) {
50 m_MaskBoundingBoxes.push_back(box);
51 }
52
Transform(const CFX_Matrix & matrix)53 void CPDF_PageObjectHolder::Transform(const CFX_Matrix& matrix) {
54 for (auto& pObj : m_PageObjectList)
55 pObj->Transform(matrix);
56 }
57
CalcBoundingBox() const58 CFX_FloatRect CPDF_PageObjectHolder::CalcBoundingBox() const {
59 if (m_PageObjectList.empty())
60 return CFX_FloatRect();
61
62 float left = 1000000.0f;
63 float right = -1000000.0f;
64 float bottom = 1000000.0f;
65 float top = -1000000.0f;
66 for (const auto& pObj : m_PageObjectList) {
67 left = std::min(left, pObj->m_Left);
68 right = std::max(right, pObj->m_Right);
69 bottom = std::min(bottom, pObj->m_Bottom);
70 top = std::max(top, pObj->m_Top);
71 }
72 return CFX_FloatRect(left, bottom, right, top);
73 }
74
LoadTransInfo()75 void CPDF_PageObjectHolder::LoadTransInfo() {
76 if (!m_pFormDict) {
77 return;
78 }
79 CPDF_Dictionary* pGroup = m_pFormDict->GetDictFor("Group");
80 if (!pGroup) {
81 return;
82 }
83 if (pGroup->GetStringFor("S") != "Transparency") {
84 return;
85 }
86 m_iTransparency |= PDFTRANS_GROUP;
87 if (pGroup->GetIntegerFor("I")) {
88 m_iTransparency |= PDFTRANS_ISOLATED;
89 }
90 if (pGroup->GetIntegerFor("K")) {
91 m_iTransparency |= PDFTRANS_KNOCKOUT;
92 }
93 }
94