• 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/fx_coordinates.h"
14 #include "core/fxcrt/fx_string.h"
15 #include "core/fxcrt/fx_system.h"
16 #include "core/fxcrt/maybe_owned.h"
17 
18 class CFX_RenderDevice;
19 class CPDF_Array;
20 class CPDF_Dictionary;
21 class CPDF_Document;
22 class CPDF_Form;
23 class CPDF_Page;
24 class CPDF_RenderContext;
25 class CPDF_RenderOptions;
26 class CPDF_Stream;
27 
28 class CPDF_Annot {
29  public:
30   enum AppearanceMode { Normal, Rollover, Down };
31   enum class Subtype {
32     UNKNOWN = 0,
33     TEXT,
34     LINK,
35     FREETEXT,
36     LINE,
37     SQUARE,
38     CIRCLE,
39     POLYGON,
40     POLYLINE,
41     HIGHLIGHT,
42     UNDERLINE,
43     SQUIGGLY,
44     STRIKEOUT,
45     STAMP,
46     CARET,
47     INK,
48     POPUP,
49     FILEATTACHMENT,
50     SOUND,
51     MOVIE,
52     WIDGET,
53     SCREEN,
54     PRINTERMARK,
55     TRAPNET,
56     WATERMARK,
57     THREED,
58     RICHMEDIA,
59     XFAWIDGET
60   };
61 
62   static CPDF_Annot::Subtype StringToAnnotSubtype(const ByteString& sSubtype);
63   static ByteString AnnotSubtypeToString(CPDF_Annot::Subtype nSubtype);
64   static CFX_FloatRect RectFromQuadPointsArray(const CPDF_Array* pArray,
65                                                size_t nIndex);
66   static CFX_FloatRect BoundingRectFromQuadPoints(
67       const CPDF_Dictionary* pAnnotDict);
68   static CFX_FloatRect RectFromQuadPoints(const CPDF_Dictionary* pAnnotDict,
69                                           size_t nIndex);
70   static size_t QuadPointCount(const CPDF_Array* pArray);
71 
72   // The second constructor does not take ownership of the dictionary.
73   CPDF_Annot(RetainPtr<CPDF_Dictionary> pDict, CPDF_Document* pDocument);
74   CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument);
75   ~CPDF_Annot();
76 
77   CPDF_Annot::Subtype GetSubtype() const;
78   uint32_t GetFlags() const;
79   CFX_FloatRect GetRect() const;
GetDocument()80   CPDF_Document* GetDocument() const { return m_pDocument.Get(); }
GetAnnotDict()81   const CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict.Get(); }
GetAnnotDict()82   CPDF_Dictionary* GetAnnotDict() { return m_pAnnotDict.Get(); }
83 
84   bool IsHidden() const;
85 
86   bool DrawAppearance(CPDF_Page* pPage,
87                       CFX_RenderDevice* pDevice,
88                       const CFX_Matrix& mtUser2Device,
89                       AppearanceMode mode,
90                       const CPDF_RenderOptions* pOptions);
91   bool DrawInContext(const CPDF_Page* pPage,
92                      CPDF_RenderContext* pContext,
93                      const CFX_Matrix* pUser2Device,
94                      AppearanceMode mode);
95 
96   void ClearCachedAP();
97   void DrawBorder(CFX_RenderDevice* pDevice,
98                   const CFX_Matrix* pUser2Device,
99                   const CPDF_RenderOptions* pOptions);
100   CPDF_Form* GetAPForm(const CPDF_Page* pPage, AppearanceMode mode);
SetOpenState(bool bOpenState)101   void SetOpenState(bool bOpenState) { m_bOpenState = bOpenState; }
GetPopupAnnot()102   CPDF_Annot* GetPopupAnnot() const { return m_pPopupAnnot.Get(); }
SetPopupAnnot(CPDF_Annot * pAnnot)103   void SetPopupAnnot(CPDF_Annot* pAnnot) { m_pPopupAnnot = pAnnot; }
104 
105  private:
106   void Init();
107   void GenerateAPIfNeeded();
108   bool ShouldGenerateAP() const;
109   bool ShouldDrawAnnotation() const;
110 
111   CFX_FloatRect RectForDrawing() const;
112 
113   RetainPtr<CPDF_Dictionary> const m_pAnnotDict;
114   UnownedPtr<CPDF_Document> const m_pDocument;
115   CPDF_Annot::Subtype m_nSubtype;
116   std::map<CPDF_Stream*, std::unique_ptr<CPDF_Form>> m_APMap;
117   // If non-null, then this is not a popup annotation.
118   UnownedPtr<CPDF_Annot> m_pPopupAnnot;
119   // |m_bOpenState| is only set for popup annotations.
120   bool m_bOpenState = false;
121   bool m_bHasGeneratedAP;
122   bool m_bIsTextMarkupAnnotation;
123 };
124 
125 // Get the AP in an annotation dict for a given appearance mode.
126 // If |eMode| is not Normal and there is not AP for that mode, falls back to
127 // the Normal AP.
128 CPDF_Stream* GetAnnotAP(CPDF_Dictionary* pAnnotDict,
129                         CPDF_Annot::AppearanceMode eMode);
130 
131 // Get the AP in an annotation dict for a given appearance mode.
132 // No fallbacks to Normal like in GetAnnotAP.
133 CPDF_Stream* GetAnnotAPNoFallback(CPDF_Dictionary* pAnnotDict,
134                                   CPDF_Annot::AppearanceMode eMode);
135 
136 #endif  // CORE_FPDFDOC_CPDF_ANNOT_H_
137