• 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_PAGEOBJECTHOLDER_H_
8 #define CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECTHOLDER_H_
9 
10 #include <map>
11 #include <memory>
12 #include <vector>
13 
14 #include "core/fpdfapi/page/cpdf_pageobjectlist.h"
15 #include "core/fxcrt/fx_coordinates.h"
16 #include "core/fxcrt/fx_string.h"
17 #include "core/fxcrt/fx_system.h"
18 #include "core/fxcrt/unowned_ptr.h"
19 
20 class IFX_PauseIndicator;
21 class CPDF_Dictionary;
22 class CPDF_Stream;
23 class CPDF_Document;
24 class CPDF_ContentParser;
25 
26 #define PDFTRANS_GROUP 0x0100
27 #define PDFTRANS_ISOLATED 0x0200
28 #define PDFTRANS_KNOCKOUT 0x0400
29 
30 // These structs are used to keep track of resources that have already been
31 // generated in the page object holder.
32 struct GraphicsData {
33   float fillAlpha;
34   float strokeAlpha;
35   int blendType;
36   bool operator<(const GraphicsData& other) const;
37 };
38 
39 struct FontData {
40   ByteString baseFont;
41   ByteString type;
42   bool operator<(const FontData& other) const;
43 };
44 
45 class CPDF_PageObjectHolder {
46  public:
47   CPDF_PageObjectHolder(CPDF_Document* pDoc, CPDF_Dictionary* pFormDict);
48   virtual ~CPDF_PageObjectHolder();
49 
50   virtual bool IsPage() const;
51 
52   void ContinueParse(IFX_PauseIndicator* pPause);
IsParsed()53   bool IsParsed() const { return m_ParseState == CONTENT_PARSED; }
54 
GetPageObjectList()55   CPDF_PageObjectList* GetPageObjectList() { return &m_PageObjectList; }
GetPageObjectList()56   const CPDF_PageObjectList* GetPageObjectList() const {
57     return &m_PageObjectList;
58   }
GetLastCTM()59   const CFX_Matrix& GetLastCTM() const { return m_LastCTM; }
60 
BackgroundAlphaNeeded()61   bool BackgroundAlphaNeeded() const { return m_bBackgroundAlphaNeeded; }
SetBackgroundAlphaNeeded(bool needed)62   void SetBackgroundAlphaNeeded(bool needed) {
63     m_bBackgroundAlphaNeeded = needed;
64   }
65 
HasImageMask()66   bool HasImageMask() const { return !m_MaskBoundingBoxes.empty(); }
GetMaskBoundingBoxes()67   const std::vector<CFX_FloatRect>& GetMaskBoundingBoxes() const {
68     return m_MaskBoundingBoxes;
69   }
70   void AddImageMaskBoundingBox(const CFX_FloatRect& box);
71   void Transform(const CFX_Matrix& matrix);
72   CFX_FloatRect CalcBoundingBox() const;
73 
74   const UnownedPtr<CPDF_Dictionary> m_pFormDict;
75   UnownedPtr<CPDF_Stream> m_pFormStream;
76   UnownedPtr<CPDF_Document> m_pDocument;
77   UnownedPtr<CPDF_Dictionary> m_pPageResources;
78   UnownedPtr<CPDF_Dictionary> m_pResources;
79   std::map<GraphicsData, ByteString> m_GraphicsMap;
80   std::map<FontData, ByteString> m_FontsMap;
81   CFX_FloatRect m_BBox;
82   int m_iTransparency;
83 
84  protected:
85   enum ParseState { CONTENT_NOT_PARSED, CONTENT_PARSING, CONTENT_PARSED };
86 
87   void LoadTransInfo();
88 
89   bool m_bBackgroundAlphaNeeded;
90   std::vector<CFX_FloatRect> m_MaskBoundingBoxes;
91   ParseState m_ParseState;
92   std::unique_ptr<CPDF_ContentParser> m_pParser;
93   CPDF_PageObjectList m_PageObjectList;
94   CFX_Matrix m_LastCTM;
95 };
96 
97 #endif  // CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECTHOLDER_H_
98