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 #ifndef CORE_FPDFAPI_PAGE_CPDF_CONTENTPARSER_H_
      8 #define CORE_FPDFAPI_PAGE_CPDF_CONTENTPARSER_H_
      9 
     10 #include <memory>
     11 #include <set>
     12 #include <vector>
     13 
     14 #include "core/fpdfapi/page/cpdf_pageobjectholder.h"
     15 #include "core/fpdfapi/page/cpdf_streamcontentparser.h"
     16 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
     17 #include "core/fxcrt/maybe_owned.h"
     18 #include "core/fxcrt/unowned_ptr.h"
     19 
     20 class CPDF_AllStates;
     21 class CPDF_Form;
     22 class CPDF_Page;
     23 class CPDF_StreamAcc;
     24 class CPDF_Type3Char;
     25 
     26 class CPDF_ContentParser {
     27  public:
     28   explicit CPDF_ContentParser(CPDF_Page* pPage);
     29   CPDF_ContentParser(CPDF_Form* pForm,
     30                      CPDF_AllStates* pGraphicStates,
     31                      const CFX_Matrix* pParentMatrix,
     32                      CPDF_Type3Char* pType3Char,
     33                      std::set<const uint8_t*>* parsedSet);
     34   ~CPDF_ContentParser();
     35 
     36   const CPDF_AllStates* GetCurStates() const {
     37     return m_pParser ? m_pParser->GetCurStates() : nullptr;
     38   }
     39   // Returns whether to continue or not.
     40   bool Continue(IFX_PauseIndicator* pPause);
     41 
     42  private:
     43   enum InternalStage {
     44     STAGE_GETCONTENT = 1,
     45     STAGE_PARSE,
     46     STAGE_CHECKCLIP,
     47   };
     48 
     49   bool m_bIsDone = false;
     50   InternalStage m_InternalStage;
     51   UnownedPtr<CPDF_PageObjectHolder> const m_pObjectHolder;
     52   UnownedPtr<CPDF_Type3Char> m_pType3Char;  // Only used when parsing forms.
     53   uint32_t m_nStreams = 0;
     54   RetainPtr<CPDF_StreamAcc> m_pSingleStream;
     55   std::vector<RetainPtr<CPDF_StreamAcc>> m_StreamArray;
     56   MaybeOwned<uint8_t, FxFreeDeleter> m_pData;
     57   uint32_t m_Size = 0;
     58   uint32_t m_CurrentOffset = 0;
     59 
     60   // Only used when parsing pages.
     61   std::unique_ptr<std::set<const uint8_t*>> m_parsedSet;
     62 
     63   // |m_pParser| has a reference to |m_parsedSet|, so must be below and thus
     64   // destroyed first.
     65   std::unique_ptr<CPDF_StreamContentParser> m_pParser;
     66 };
     67 
     68 #endif  // CORE_FPDFAPI_PAGE_CPDF_CONTENTPARSER_H_
     69