• 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_FPDFDOC_CPDF_ANNOT_H_
8 #define CORE_FPDFDOC_CPDF_ANNOT_H_
9 
10 #include <map>
11 #include <memory>
12 
13 #include "core/fxcrt/cfx_maybe_owned.h"
14 #include "core/fxcrt/fx_coordinates.h"
15 #include "core/fxcrt/fx_string.h"
16 #include "core/fxcrt/fx_system.h"
17 
18 class CFX_RenderDevice;
19 class CPDF_Dictionary;
20 class CPDF_Document;
21 class CPDF_Form;
22 class CPDF_Page;
23 class CPDF_RenderContext;
24 class CPDF_RenderOptions;
25 class CPDF_Stream;
26 
27 #define ANNOTFLAG_INVISIBLE 0x0001
28 #define ANNOTFLAG_HIDDEN 0x0002
29 #define ANNOTFLAG_PRINT 0x0004
30 #define ANNOTFLAG_NOZOOM 0x0008
31 #define ANNOTFLAG_NOROTATE 0x0010
32 #define ANNOTFLAG_NOVIEW 0x0020
33 #define ANNOTFLAG_READONLY 0x0040
34 #define ANNOTFLAG_LOCKED 0x0080
35 #define ANNOTFLAG_TOGGLENOVIEW 0x0100
36 
37 class CPDF_Annot {
38  public:
39   enum AppearanceMode { Normal, Rollover, Down };
40   enum class Subtype {
41     UNKNOWN = 0,
42     TEXT,
43     LINK,
44     FREETEXT,
45     LINE,
46     SQUARE,
47     CIRCLE,
48     POLYGON,
49     POLYLINE,
50     HIGHLIGHT,
51     UNDERLINE,
52     SQUIGGLY,
53     STRIKEOUT,
54     STAMP,
55     CARET,
56     INK,
57     POPUP,
58     FILEATTACHMENT,
59     SOUND,
60     MOVIE,
61     WIDGET,
62     SCREEN,
63     PRINTERMARK,
64     TRAPNET,
65     WATERMARK,
66     THREED,
67     RICHMEDIA,
68     XFAWIDGET
69   };
70 
71   static bool IsAnnotationHidden(CPDF_Dictionary* pAnnotDict);
72   static CPDF_Annot::Subtype StringToAnnotSubtype(
73       const CFX_ByteString& sSubtype);
74   static CFX_ByteString AnnotSubtypeToString(CPDF_Annot::Subtype nSubtype);
75   static CFX_FloatRect RectFromQuadPoints(CPDF_Dictionary* pAnnotDict);
76 
77   // The second constructor does not take ownership of the dictionary.
78   CPDF_Annot(std::unique_ptr<CPDF_Dictionary> pDict, CPDF_Document* pDocument);
79   CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument);
80   ~CPDF_Annot();
81 
82   CPDF_Annot::Subtype GetSubtype() const;
83   uint32_t GetFlags() const;
84   CFX_FloatRect GetRect() const;
GetDocument()85   CPDF_Document* GetDocument() const { return m_pDocument; }
GetAnnotDict()86   CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict.Get(); }
87 
88   bool DrawAppearance(CPDF_Page* pPage,
89                       CFX_RenderDevice* pDevice,
90                       const CFX_Matrix* pUser2Device,
91                       AppearanceMode mode,
92                       const CPDF_RenderOptions* pOptions);
93   bool DrawInContext(const CPDF_Page* pPage,
94                      CPDF_RenderContext* pContext,
95                      const CFX_Matrix* pUser2Device,
96                      AppearanceMode mode);
97 
98   void ClearCachedAP();
99   void DrawBorder(CFX_RenderDevice* pDevice,
100                   const CFX_Matrix* pUser2Device,
101                   const CPDF_RenderOptions* pOptions);
102   CPDF_Form* GetAPForm(const CPDF_Page* pPage, AppearanceMode mode);
SetOpenState(bool bOpenState)103   void SetOpenState(bool bOpenState) { m_bOpenState = bOpenState; }
GetPopupAnnot()104   CPDF_Annot* GetPopupAnnot() const { return m_pPopupAnnot; }
SetPopupAnnot(CPDF_Annot * pAnnot)105   void SetPopupAnnot(CPDF_Annot* pAnnot) { m_pPopupAnnot = pAnnot; }
106 
107  private:
108   void Init();
109   void GenerateAPIfNeeded();
110   bool ShouldDrawAnnotation();
111 
112   CFX_FloatRect RectForDrawing() const;
113 
114   CFX_MaybeOwned<CPDF_Dictionary> m_pAnnotDict;
115   CPDF_Document* const m_pDocument;
116   CPDF_Annot::Subtype m_nSubtype;
117   std::map<CPDF_Stream*, std::unique_ptr<CPDF_Form>> m_APMap;
118   // |m_bOpenState| is only set for popup annotations.
119   bool m_bOpenState = false;
120   bool m_bHasGeneratedAP;
121   bool m_bIsTextMarkupAnnotation;
122   // Not owned. If there is a valid pointer in |m_pPopupAnnot|,
123   // then this annot is never a popup.
124   CPDF_Annot* m_pPopupAnnot = nullptr;
125 };
126 
127 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict,
128                                 CPDF_Annot::AppearanceMode mode);
129 
130 #endif  // CORE_FPDFDOC_CPDF_ANNOT_H_
131