14d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann// Copyright 2016 PDFium Authors. All rights reserved.
24d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann// Use of this source code is governed by a BSD-style license that can be
34d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann// found in the LICENSE file.
44d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
54d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
64d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
74d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#ifndef CORE_FPDFDOC_CPDF_ANNOT_H_
84d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#define CORE_FPDFDOC_CPDF_ANNOT_H_
94d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
104d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include <map>
114d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include <memory>
124d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
134d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "core/fxcrt/fx_coordinates.h"
144d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "core/fxcrt/fx_string.h"
154d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "core/fxcrt/fx_system.h"
16d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann#include "core/fxcrt/maybe_owned.h"
174d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
184d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannclass CFX_RenderDevice;
194d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannclass CPDF_Dictionary;
204d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannclass CPDF_Document;
214d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannclass CPDF_Form;
224d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannclass CPDF_Page;
234d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannclass CPDF_RenderContext;
244d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannclass CPDF_RenderOptions;
254d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannclass CPDF_Stream;
264d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
274d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#define ANNOTFLAG_INVISIBLE 0x0001
284d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#define ANNOTFLAG_HIDDEN 0x0002
294d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#define ANNOTFLAG_PRINT 0x0004
304d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#define ANNOTFLAG_NOVIEW 0x0020
314d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
324d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannclass CPDF_Annot {
334d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann public:
344d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  enum AppearanceMode { Normal, Rollover, Down };
354d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  enum class Subtype {
364d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    UNKNOWN = 0,
374d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    TEXT,
384d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    LINK,
394d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    FREETEXT,
404d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    LINE,
414d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    SQUARE,
424d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    CIRCLE,
434d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    POLYGON,
444d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    POLYLINE,
454d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    HIGHLIGHT,
464d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    UNDERLINE,
474d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    SQUIGGLY,
484d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    STRIKEOUT,
494d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    STAMP,
504d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    CARET,
514d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    INK,
524d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    POPUP,
534d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    FILEATTACHMENT,
544d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    SOUND,
554d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    MOVIE,
564d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    WIDGET,
574d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    SCREEN,
584d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    PRINTERMARK,
594d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    TRAPNET,
604d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    WATERMARK,
614d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    THREED,
624d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    RICHMEDIA,
634d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    XFAWIDGET
644d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  };
654d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
664d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  static bool IsAnnotationHidden(CPDF_Dictionary* pAnnotDict);
67d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann  static CPDF_Annot::Subtype StringToAnnotSubtype(const ByteString& sSubtype);
68d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann  static ByteString AnnotSubtypeToString(CPDF_Annot::Subtype nSubtype);
694d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  static CFX_FloatRect RectFromQuadPoints(CPDF_Dictionary* pAnnotDict);
704d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
714d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  // The second constructor does not take ownership of the dictionary.
724d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  CPDF_Annot(std::unique_ptr<CPDF_Dictionary> pDict, CPDF_Document* pDocument);
734d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument);
744d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  ~CPDF_Annot();
754d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
764d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  CPDF_Annot::Subtype GetSubtype() const;
774d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  uint32_t GetFlags() const;
784d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  CFX_FloatRect GetRect() const;
79d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann  CPDF_Document* GetDocument() const { return m_pDocument.Get(); }
804d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict.Get(); }
814d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
824d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  bool DrawAppearance(CPDF_Page* pPage,
834d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann                      CFX_RenderDevice* pDevice,
84d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann                      const CFX_Matrix& mtUser2Device,
854d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann                      AppearanceMode mode,
864d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann                      const CPDF_RenderOptions* pOptions);
874d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  bool DrawInContext(const CPDF_Page* pPage,
884d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann                     CPDF_RenderContext* pContext,
894d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann                     const CFX_Matrix* pUser2Device,
904d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann                     AppearanceMode mode);
914d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
924d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  void ClearCachedAP();
934d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  void DrawBorder(CFX_RenderDevice* pDevice,
944d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann                  const CFX_Matrix* pUser2Device,
954d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann                  const CPDF_RenderOptions* pOptions);
964d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  CPDF_Form* GetAPForm(const CPDF_Page* pPage, AppearanceMode mode);
974d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  void SetOpenState(bool bOpenState) { m_bOpenState = bOpenState; }
984d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  CPDF_Annot* GetPopupAnnot() const { return m_pPopupAnnot; }
994d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  void SetPopupAnnot(CPDF_Annot* pAnnot) { m_pPopupAnnot = pAnnot; }
1004d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
1014d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann private:
1024d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  void Init();
1034d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  void GenerateAPIfNeeded();
1044d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  bool ShouldDrawAnnotation();
1054d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
1064d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  CFX_FloatRect RectForDrawing() const;
1074d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
108d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann  MaybeOwned<CPDF_Dictionary> m_pAnnotDict;
109d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann  UnownedPtr<CPDF_Document> const m_pDocument;
1104d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  CPDF_Annot::Subtype m_nSubtype;
1114d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  std::map<CPDF_Stream*, std::unique_ptr<CPDF_Form>> m_APMap;
1124d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  // |m_bOpenState| is only set for popup annotations.
1134d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  bool m_bOpenState = false;
1144d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  bool m_bHasGeneratedAP;
1154d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  bool m_bIsTextMarkupAnnotation;
1164d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  // Not owned. If there is a valid pointer in |m_pPopupAnnot|,
1174d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  // then this annot is never a popup.
1184d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  CPDF_Annot* m_pPopupAnnot = nullptr;
1194d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann};
1204d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
121d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann// Get the AP in an annotation dict for a given appearance mode.
122d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann// If |eMode| is not Normal and there is not AP for that mode, falls back to
123d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann// the Normal AP.
124d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. MoltmannCPDF_Stream* FPDFDOC_GetAnnotAP(const CPDF_Dictionary* pAnnotDict,
125d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann                                CPDF_Annot::AppearanceMode eMode);
126d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann
127d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann// Get the AP in an annotation dict for a given appearance mode.
128d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann// No fallbacks to Normal like in FPDFDOC_GetAnnotAP.
129d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. MoltmannCPDF_Stream* FPDFDOC_GetAnnotAPNoFallback(const CPDF_Dictionary* pAnnotDict,
130d904c1ec7e8d1d86ed56f0dd252435d12cd345aePhilip P. Moltmann                                          CPDF_Annot::AppearanceMode eMode);
1314d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
1324d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#endif  // CORE_FPDFDOC_CPDF_ANNOT_H_
133