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