• 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_DOCPAGEDATA_H_
8 #define CORE_FPDFAPI_PAGE_CPDF_DOCPAGEDATA_H_
9 
10 #include <map>
11 #include <set>
12 
13 #include "core/fpdfapi/page/cpdf_colorspace.h"
14 #include "core/fxcrt/fx_coordinates.h"
15 #include "core/fxcrt/fx_string.h"
16 #include "core/fxcrt/unowned_ptr.h"
17 
18 class CPDF_Dictionary;
19 class CPDF_Document;
20 class CPDF_Font;
21 class CPDF_FontEncoding;
22 class CPDF_IccProfile;
23 class CPDF_Image;
24 class CPDF_Object;
25 class CPDF_Pattern;
26 class CPDF_Stream;
27 class CPDF_StreamAcc;
28 
29 class CPDF_DocPageData {
30  public:
31   explicit CPDF_DocPageData(CPDF_Document* pPDFDoc);
32   ~CPDF_DocPageData();
33 
34   void Clear(bool bRelease = false);
IsForceClear()35   bool IsForceClear() const { return m_bForceClear; }
36 
37   CPDF_Font* GetFont(CPDF_Dictionary* pFontDict);
38   CPDF_Font* GetStandardFont(const ByteString& fontName,
39                              CPDF_FontEncoding* pEncoding);
40   void ReleaseFont(const CPDF_Dictionary* pFontDict);
41 
42   CPDF_ColorSpace* GetColorSpace(CPDF_Object* pCSObj,
43                                  const CPDF_Dictionary* pResources);
44   CPDF_ColorSpace* GetColorSpaceGuarded(CPDF_Object* pCSObj,
45                                         const CPDF_Dictionary* pResources,
46                                         std::set<CPDF_Object*>* pVisited);
47 
48   CPDF_ColorSpace* GetCopiedColorSpace(CPDF_Object* pCSObj);
49   void ReleaseColorSpace(const CPDF_Object* pColorSpace);
50 
51   CPDF_Pattern* GetPattern(CPDF_Object* pPatternObj,
52                            bool bShading,
53                            const CFX_Matrix& matrix);
54   void ReleasePattern(const CPDF_Object* pPatternObj);
55 
56   RetainPtr<CPDF_Image> GetImage(uint32_t dwStreamObjNum);
57   void MaybePurgeImage(uint32_t dwStreamObjNum);
58 
59   RetainPtr<CPDF_IccProfile> GetIccProfile(CPDF_Stream* pProfileStream);
60   void MaybePurgeIccProfile(CPDF_Stream* pProfileStream);
61 
62   RetainPtr<CPDF_StreamAcc> GetFontFileStreamAcc(CPDF_Stream* pFontStream);
63   void MaybePurgeFontFileStreamAcc(const CPDF_Stream* pFontStream);
64 
65   CPDF_CountedColorSpace* FindColorSpacePtr(CPDF_Object* pCSObj) const;
66   CPDF_CountedPattern* FindPatternPtr(CPDF_Object* pPatternObj) const;
67 
68  private:
69   using CPDF_CountedFont = CPDF_CountedObject<CPDF_Font>;
70 
71   bool m_bForceClear;
72   UnownedPtr<CPDF_Document> const m_pPDFDoc;
73   std::map<ByteString, CPDF_Stream*> m_HashProfileMap;
74   std::map<const CPDF_Object*, CPDF_CountedColorSpace*> m_ColorSpaceMap;
75   std::map<const CPDF_Stream*, RetainPtr<CPDF_StreamAcc>> m_FontFileMap;
76   std::map<const CPDF_Dictionary*, CPDF_CountedFont*> m_FontMap;
77   std::map<const CPDF_Stream*, RetainPtr<CPDF_IccProfile>> m_IccProfileMap;
78   std::map<uint32_t, RetainPtr<CPDF_Image>> m_ImageMap;
79   std::map<const CPDF_Object*, CPDF_CountedPattern*> m_PatternMap;
80 };
81 
82 #endif  // CORE_FPDFAPI_PAGE_CPDF_DOCPAGEDATA_H_
83