• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_streamcontentparser.h"
15 #include "core/fxcrt/fx_memory_wrappers.h"
16 #include "core/fxcrt/maybe_owned.h"
17 #include "core/fxcrt/unowned_ptr.h"
18 
19 class CPDF_AllStates;
20 class CPDF_Array;
21 class CPDF_Form;
22 class CPDF_Page;
23 class CPDF_PageObjectHolder;
24 class CPDF_Stream;
25 class CPDF_StreamAcc;
26 class CPDF_Type3Char;
27 class PauseIndicatorIface;
28 
29 class CPDF_ContentParser {
30  public:
31   explicit CPDF_ContentParser(CPDF_Page* pPage);
32   CPDF_ContentParser(CPDF_Form* pForm,
33                      const CPDF_AllStates* pGraphicStates,
34                      const CFX_Matrix* pParentMatrix,
35                      CPDF_Type3Char* pType3Char,
36                      std::set<const uint8_t*>* pParsedSet);
37   ~CPDF_ContentParser();
38 
GetCurStates()39   const CPDF_AllStates* GetCurStates() const {
40     return m_pParser ? m_pParser->GetCurStates() : nullptr;
41   }
42   // Returns whether to continue or not.
43   bool Continue(PauseIndicatorIface* pPause);
44 
45  private:
46   enum class Stage : uint8_t {
47     kGetContent = 1,
48     kPrepareContent,
49     kParse,
50     kCheckClip,
51     kComplete,
52   };
53 
54   Stage GetContent();
55   Stage PrepareContent();
56   Stage Parse();
57   Stage CheckClip();
58 
59   void HandlePageContentStream(CPDF_Stream* pStream);
60   bool HandlePageContentArray(CPDF_Array* pArray);
61   void HandlePageContentFailure();
62 
63   Stage m_CurrentStage;
64   UnownedPtr<CPDF_PageObjectHolder> const m_pObjectHolder;
65   UnownedPtr<CPDF_Type3Char> m_pType3Char;  // Only used when parsing forms.
66   RetainPtr<CPDF_StreamAcc> m_pSingleStream;
67   std::vector<RetainPtr<CPDF_StreamAcc>> m_StreamArray;
68   std::vector<uint32_t> m_StreamSegmentOffsets;
69   MaybeOwned<uint8_t, FxFreeDeleter> m_pData;
70   uint32_t m_nStreams = 0;
71   uint32_t m_Size = 0;
72   uint32_t m_CurrentOffset = 0;
73 
74   // Only used when parsing pages.
75   std::unique_ptr<std::set<const uint8_t*>> m_pParsedSet;
76 
77   // |m_pParser| has a reference to |m_pParsedSet|, so must be below and thus
78   // destroyed first.
79   std::unique_ptr<CPDF_StreamContentParser> m_pParser;
80 };
81 
82 #endif  // CORE_FPDFAPI_PAGE_CPDF_CONTENTPARSER_H_
83