Home | History | Annotate | Download | only in page
      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_contentparser.h"
     12 #include "core/fpdfapi/page/cpdf_pageobject.h"
     13 #include "core/fpdfapi/page/pageint.h"
     14 #include "core/fpdfapi/parser/cpdf_dictionary.h"
     15 
     16 CPDF_PageObjectHolder::CPDF_PageObjectHolder()
     17     : m_pFormDict(nullptr),
     18       m_pFormStream(nullptr),
     19       m_pDocument(nullptr),
     20       m_pPageResources(nullptr),
     21       m_pResources(nullptr),
     22       m_Transparency(0),
     23       m_bBackgroundAlphaNeeded(false),
     24       m_bHasImageMask(false),
     25       m_ParseState(CONTENT_NOT_PARSED) {}
     26 
     27 CPDF_PageObjectHolder::~CPDF_PageObjectHolder() {}
     28 
     29 void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) {
     30   if (!m_pParser) {
     31     return;
     32   }
     33   m_pParser->Continue(pPause);
     34   if (m_pParser->GetStatus() == CPDF_ContentParser::Done) {
     35     m_ParseState = CONTENT_PARSED;
     36     m_pParser.reset();
     37   }
     38 }
     39 
     40 void CPDF_PageObjectHolder::Transform(const CFX_Matrix& matrix) {
     41   for (auto& pObj : m_PageObjectList)
     42     pObj->Transform(matrix);
     43 }
     44 
     45 CFX_FloatRect CPDF_PageObjectHolder::CalcBoundingBox() const {
     46   if (m_PageObjectList.empty())
     47     return CFX_FloatRect(0, 0, 0, 0);
     48 
     49   FX_FLOAT left = 1000000.0f;
     50   FX_FLOAT right = -1000000.0f;
     51   FX_FLOAT bottom = 1000000.0f;
     52   FX_FLOAT top = -1000000.0f;
     53   for (const auto& pObj : m_PageObjectList) {
     54     left = std::min(left, pObj->m_Left);
     55     right = std::max(right, pObj->m_Right);
     56     bottom = std::min(bottom, pObj->m_Bottom);
     57     top = std::max(top, pObj->m_Top);
     58   }
     59   return CFX_FloatRect(left, bottom, right, top);
     60 }
     61 
     62 void CPDF_PageObjectHolder::LoadTransInfo() {
     63   if (!m_pFormDict) {
     64     return;
     65   }
     66   CPDF_Dictionary* pGroup = m_pFormDict->GetDictFor("Group");
     67   if (!pGroup) {
     68     return;
     69   }
     70   if (pGroup->GetStringFor("S") != "Transparency") {
     71     return;
     72   }
     73   m_Transparency |= PDFTRANS_GROUP;
     74   if (pGroup->GetIntegerFor("I")) {
     75     m_Transparency |= PDFTRANS_ISOLATED;
     76   }
     77   if (pGroup->GetIntegerFor("K")) {
     78     m_Transparency |= PDFTRANS_KNOCKOUT;
     79   }
     80 }
     81