summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_annot.cpp (renamed from core/fpdfdoc/doc_annot.cpp)113
-rw-r--r--core/fpdfdoc/cpdf_annot.h70
-rw-r--r--core/fpdfdoc/cpdf_annotlist.cpp132
-rw-r--r--core/fpdfdoc/cpdf_annotlist.h64
-rw-r--r--core/fpdfdoc/include/fpdf_doc.h91
5 files changed, 271 insertions, 199 deletions
diff --git a/core/fpdfdoc/doc_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index e1a976005b..dcdd89c3f4 100644
--- a/core/fpdfdoc/doc_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -1,126 +1,19 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "core/fpdfdoc/cpdf_annot.h"
+
#include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
-#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
#include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h"
#include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h"
-#include "core/fpdfdoc/cpvt_generateap.h"
-#include "core/fpdfdoc/include/fpdf_doc.h"
#include "core/fxge/include/fx_ge.h"
-CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
- : m_pDocument(pPage->m_pDocument) {
- if (!pPage->m_pFormDict)
- return;
-
- CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots");
- if (!pAnnots)
- return;
-
- CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
- CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm");
- FX_BOOL bRegenerateAP =
- pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances");
- for (size_t i = 0; i < pAnnots->GetCount(); ++i) {
- CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i));
- if (!pDict)
- continue;
-
- uint32_t dwObjNum = pDict->GetObjNum();
- if (dwObjNum == 0) {
- dwObjNum = m_pDocument->AddIndirectObject(pDict);
- CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum);
- pAnnots->InsertAt(i, pAction);
- pAnnots->RemoveAt(i + 1);
- pDict = pAnnots->GetDictAt(i);
- }
- m_AnnotList.push_back(
- std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument)));
- if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" &&
- CPDF_InterForm::IsUpdateAPEnabled()) {
- FPDF_GenerateAP(m_pDocument, pDict);
- }
- }
-}
-
-CPDF_AnnotList::~CPDF_AnnotList() {}
-
-void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage,
- CFX_RenderDevice* pDevice,
- CPDF_RenderContext* pContext,
- FX_BOOL bPrinting,
- CFX_Matrix* pMatrix,
- FX_BOOL bWidgetPass,
- CPDF_RenderOptions* pOptions,
- FX_RECT* clip_rect) {
- for (const auto& pAnnot : m_AnnotList) {
- bool bWidget = pAnnot->GetSubType() == "Widget";
- if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget))
- continue;
-
- uint32_t annot_flags = pAnnot->GetFlags();
- if (annot_flags & ANNOTFLAG_HIDDEN)
- continue;
-
- if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0)
- continue;
-
- if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW))
- continue;
-
- if (pOptions) {
- CPDF_OCContext* pOCContext = pOptions->m_pOCContext;
- CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict();
- if (pOCContext && pAnnotDict &&
- !pOCContext->CheckOCGVisible(pAnnotDict->GetDictBy("OC"))) {
- continue;
- }
- }
- CFX_FloatRect annot_rect_f;
- pAnnot->GetRect(annot_rect_f);
- CFX_Matrix matrix = *pMatrix;
- if (clip_rect) {
- annot_rect_f.Transform(&matrix);
- FX_RECT annot_rect = annot_rect_f.GetOutterRect();
- annot_rect.Intersect(*clip_rect);
- if (annot_rect.IsEmpty()) {
- continue;
- }
- }
- if (pContext) {
- pAnnot->DrawInContext(pPage, pContext, &matrix, CPDF_Annot::Normal);
- } else if (!pAnnot->DrawAppearance(pPage, pDevice, &matrix,
- CPDF_Annot::Normal, pOptions)) {
- pAnnot->DrawBorder(pDevice, &matrix, pOptions);
- }
- }
-}
-
-void CPDF_AnnotList::DisplayAnnots(CPDF_Page* pPage,
- CFX_RenderDevice* pDevice,
- CPDF_RenderContext* pContext,
- FX_BOOL bPrinting,
- CFX_Matrix* pUser2Device,
- uint32_t dwAnnotFlags,
- CPDF_RenderOptions* pOptions,
- FX_RECT* pClipRect) {
- if (dwAnnotFlags & 0x01) {
- DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, FALSE,
- pOptions, pClipRect);
- }
- if (dwAnnotFlags & 0x02) {
- DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, TRUE,
- pOptions, pClipRect);
- }
-}
-
CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument)
: m_pAnnotDict(pDict),
m_pDocument(pDocument),
diff --git a/core/fpdfdoc/cpdf_annot.h b/core/fpdfdoc/cpdf_annot.h
new file mode 100644
index 0000000000..b5d9186fd3
--- /dev/null
+++ b/core/fpdfdoc/cpdf_annot.h
@@ -0,0 +1,70 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFDOC_CPDF_ANNOT_H_
+#define CORE_FPDFDOC_CPDF_ANNOT_H_
+
+#include <map>
+#include <memory>
+
+#include "core/fxcrt/include/fx_coordinates.h"
+#include "core/fxcrt/include/fx_string.h"
+#include "core/fxcrt/include/fx_system.h"
+
+class CFX_RenderDevice;
+class CPDF_Dictionary;
+class CPDF_Document;
+class CPDF_Form;
+class CPDF_Page;
+class CPDF_RenderContext;
+class CPDF_RenderOptions;
+class CPDF_Stream;
+
+#define ANNOTFLAG_INVISIBLE 0x0001
+#define ANNOTFLAG_HIDDEN 0x0002
+#define ANNOTFLAG_PRINT 0x0004
+#define ANNOTFLAG_NOZOOM 0x0008
+#define ANNOTFLAG_NOROTATE 0x0010
+#define ANNOTFLAG_NOVIEW 0x0020
+#define ANNOTFLAG_READONLY 0x0040
+#define ANNOTFLAG_LOCKED 0x0080
+#define ANNOTFLAG_TOGGLENOVIEW 0x0100
+
+class CPDF_Annot {
+ public:
+ enum AppearanceMode { Normal, Rollover, Down };
+
+ CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument);
+ ~CPDF_Annot();
+
+ CFX_ByteString GetSubType() const;
+ uint32_t GetFlags() const;
+ void GetRect(CFX_FloatRect& rect) const;
+ const CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict; }
+ CPDF_Dictionary* GetAnnotDict() { return m_pAnnotDict; }
+ FX_BOOL DrawAppearance(CPDF_Page* pPage,
+ CFX_RenderDevice* pDevice,
+ const CFX_Matrix* pUser2Device,
+ AppearanceMode mode,
+ const CPDF_RenderOptions* pOptions);
+ FX_BOOL DrawInContext(const CPDF_Page* pPage,
+ CPDF_RenderContext* pContext,
+ const CFX_Matrix* pUser2Device,
+ AppearanceMode mode);
+ void ClearCachedAP();
+ void DrawBorder(CFX_RenderDevice* pDevice,
+ const CFX_Matrix* pUser2Device,
+ const CPDF_RenderOptions* pOptions);
+ CPDF_Form* GetAPForm(const CPDF_Page* pPage, AppearanceMode mode);
+
+ private:
+ CPDF_Dictionary* const m_pAnnotDict;
+ CPDF_Document* const m_pDocument;
+ const CFX_ByteString m_sSubtype;
+ std::map<CPDF_Stream*, CPDF_Form*> m_APMap;
+};
+
+#endif // CORE_FPDFDOC_CPDF_ANNOT_H_
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
new file mode 100644
index 0000000000..8b8c0e98bb
--- /dev/null
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -0,0 +1,132 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfdoc/cpdf_annotlist.h"
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
+#include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h"
+#include "core/fpdfdoc/cpdf_annot.h"
+#include "core/fpdfdoc/cpvt_generateap.h"
+
+CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
+ : m_pDocument(pPage->m_pDocument) {
+ if (!pPage->m_pFormDict)
+ return;
+
+ CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots");
+ if (!pAnnots)
+ return;
+
+ CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
+ CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm");
+ FX_BOOL bRegenerateAP =
+ pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances");
+ for (size_t i = 0; i < pAnnots->GetCount(); ++i) {
+ CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i));
+ if (!pDict)
+ continue;
+
+ uint32_t dwObjNum = pDict->GetObjNum();
+ if (dwObjNum == 0) {
+ dwObjNum = m_pDocument->AddIndirectObject(pDict);
+ CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum);
+ pAnnots->InsertAt(i, pAction);
+ pAnnots->RemoveAt(i + 1);
+ pDict = pAnnots->GetDictAt(i);
+ }
+ m_AnnotList.push_back(
+ std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument)));
+ if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" &&
+ CPDF_InterForm::IsUpdateAPEnabled()) {
+ FPDF_GenerateAP(m_pDocument, pDict);
+ }
+ }
+}
+
+CPDF_AnnotList::~CPDF_AnnotList() {}
+
+void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage,
+ CFX_RenderDevice* pDevice,
+ CPDF_RenderContext* pContext,
+ FX_BOOL bPrinting,
+ CFX_Matrix* pMatrix,
+ FX_BOOL bWidgetPass,
+ CPDF_RenderOptions* pOptions,
+ FX_RECT* clip_rect) {
+ for (const auto& pAnnot : m_AnnotList) {
+ bool bWidget = pAnnot->GetSubType() == "Widget";
+ if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget))
+ continue;
+
+ uint32_t annot_flags = pAnnot->GetFlags();
+ if (annot_flags & ANNOTFLAG_HIDDEN)
+ continue;
+
+ if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0)
+ continue;
+
+ if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW))
+ continue;
+
+ if (pOptions) {
+ CPDF_OCContext* pOCContext = pOptions->m_pOCContext;
+ CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict();
+ if (pOCContext && pAnnotDict &&
+ !pOCContext->CheckOCGVisible(pAnnotDict->GetDictBy("OC"))) {
+ continue;
+ }
+ }
+ CFX_FloatRect annot_rect_f;
+ pAnnot->GetRect(annot_rect_f);
+ CFX_Matrix matrix = *pMatrix;
+ if (clip_rect) {
+ annot_rect_f.Transform(&matrix);
+ FX_RECT annot_rect = annot_rect_f.GetOutterRect();
+ annot_rect.Intersect(*clip_rect);
+ if (annot_rect.IsEmpty()) {
+ continue;
+ }
+ }
+ if (pContext) {
+ pAnnot->DrawInContext(pPage, pContext, &matrix, CPDF_Annot::Normal);
+ } else if (!pAnnot->DrawAppearance(pPage, pDevice, &matrix,
+ CPDF_Annot::Normal, pOptions)) {
+ pAnnot->DrawBorder(pDevice, &matrix, pOptions);
+ }
+ }
+}
+
+void CPDF_AnnotList::DisplayAnnots(CPDF_Page* pPage,
+ CFX_RenderDevice* pDevice,
+ CPDF_RenderContext* pContext,
+ FX_BOOL bPrinting,
+ CFX_Matrix* pUser2Device,
+ uint32_t dwAnnotFlags,
+ CPDF_RenderOptions* pOptions,
+ FX_RECT* pClipRect) {
+ if (dwAnnotFlags & ANNOTFLAG_INVISIBLE) {
+ DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, FALSE,
+ pOptions, pClipRect);
+ }
+ if (dwAnnotFlags & ANNOTFLAG_HIDDEN) {
+ DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, TRUE,
+ pOptions, pClipRect);
+ }
+}
+
+void CPDF_AnnotList::DisplayAnnots(CPDF_Page* pPage,
+ CPDF_RenderContext* pContext,
+ FX_BOOL bPrinting,
+ CFX_Matrix* pMatrix,
+ FX_BOOL bShowWidget,
+ CPDF_RenderOptions* pOptions) {
+ uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN
+ : ANNOTFLAG_INVISIBLE;
+ DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags,
+ pOptions, nullptr);
+}
diff --git a/core/fpdfdoc/cpdf_annotlist.h b/core/fpdfdoc/cpdf_annotlist.h
new file mode 100644
index 0000000000..afe85f33af
--- /dev/null
+++ b/core/fpdfdoc/cpdf_annotlist.h
@@ -0,0 +1,64 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFDOC_CPDF_ANNOTLIST_H_
+#define CORE_FPDFDOC_CPDF_ANNOTLIST_H_
+
+#include <memory>
+#include <vector>
+
+#include "core/fxcrt/include/fx_coordinates.h"
+#include "core/fxcrt/include/fx_system.h"
+
+class CFX_RenderDevice;
+class CPDF_Annot;
+class CPDF_Document;
+class CPDF_Page;
+class CPDF_RenderContext;
+class CPDF_RenderOptions;
+
+class CPDF_AnnotList {
+ public:
+ explicit CPDF_AnnotList(CPDF_Page* pPage);
+ ~CPDF_AnnotList();
+
+ void DisplayAnnots(CPDF_Page* pPage,
+ CPDF_RenderContext* pContext,
+ FX_BOOL bPrinting,
+ CFX_Matrix* pMatrix,
+ FX_BOOL bShowWidget,
+ CPDF_RenderOptions* pOptions);
+
+ void DisplayAnnots(CPDF_Page* pPage,
+ CFX_RenderDevice* pDevice,
+ CPDF_RenderContext* pContext,
+ FX_BOOL bPrinting,
+ CFX_Matrix* pMatrix,
+ uint32_t dwAnnotFlags,
+ CPDF_RenderOptions* pOptions,
+ FX_RECT* pClipRect);
+
+ size_t Count() const { return m_AnnotList.size(); }
+ CPDF_Annot* GetAt(size_t index) const { return m_AnnotList[index].get(); }
+ const std::vector<std::unique_ptr<CPDF_Annot>>& All() const {
+ return m_AnnotList;
+ }
+
+ private:
+ void DisplayPass(CPDF_Page* pPage,
+ CFX_RenderDevice* pDevice,
+ CPDF_RenderContext* pContext,
+ FX_BOOL bPrinting,
+ CFX_Matrix* pMatrix,
+ FX_BOOL bWidget,
+ CPDF_RenderOptions* pOptions,
+ FX_RECT* clip_rect);
+
+ CPDF_Document* const m_pDocument;
+ std::vector<std::unique_ptr<CPDF_Annot>> m_AnnotList;
+};
+
+#endif // CORE_FPDFDOC_CPDF_ANNOTLIST_H_
diff --git a/core/fpdfdoc/include/fpdf_doc.h b/core/fpdfdoc/include/fpdf_doc.h
index 887b0dc5b1..edcec239f6 100644
--- a/core/fpdfdoc/include/fpdf_doc.h
+++ b/core/fpdfdoc/include/fpdf_doc.h
@@ -14,6 +14,8 @@
#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
+#include "core/fpdfdoc/cpdf_annot.h"
+#include "core/fpdfdoc/cpdf_annotlist.h"
#include "core/fxge/include/fx_dib.h"
class CFDF_Document;
@@ -22,8 +24,6 @@ class CFX_RenderDevice;
class CPDF_AAction;
class CPDF_Action;
class CPDF_ActionFields;
-class CPDF_Annot;
-class CPDF_AnnotList;
class CPDF_ApSettings;
class CPDF_Bookmark;
class CPDF_BookmarkTree;
@@ -306,93 +306,6 @@ class CPDF_Link {
CPDF_Dictionary* m_pDict;
};
-#define ANNOTFLAG_INVISIBLE 0x0001
-#define ANNOTFLAG_HIDDEN 0x0002
-#define ANNOTFLAG_PRINT 0x0004
-#define ANNOTFLAG_NOZOOM 0x0008
-#define ANNOTFLAG_NOROTATE 0x0010
-#define ANNOTFLAG_NOVIEW 0x0020
-#define ANNOTFLAG_READONLY 0x0040
-#define ANNOTFLAG_LOCKED 0x0080
-#define ANNOTFLAG_TOGGLENOVIEW 0x0100
-
-class CPDF_Annot {
- public:
- enum AppearanceMode { Normal, Rollover, Down };
-
- CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument);
- ~CPDF_Annot();
-
- CFX_ByteString GetSubType() const;
- uint32_t GetFlags() const;
- void GetRect(CFX_FloatRect& rect) const;
- const CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict; }
- CPDF_Dictionary* GetAnnotDict() { return m_pAnnotDict; }
- FX_BOOL DrawAppearance(CPDF_Page* pPage,
- CFX_RenderDevice* pDevice,
- const CFX_Matrix* pUser2Device,
- AppearanceMode mode,
- const CPDF_RenderOptions* pOptions);
- FX_BOOL DrawInContext(const CPDF_Page* pPage,
- CPDF_RenderContext* pContext,
- const CFX_Matrix* pUser2Device,
- AppearanceMode mode);
- void ClearCachedAP();
- void DrawBorder(CFX_RenderDevice* pDevice,
- const CFX_Matrix* pUser2Device,
- const CPDF_RenderOptions* pOptions);
- CPDF_Form* GetAPForm(const CPDF_Page* pPage, AppearanceMode mode);
-
- private:
- CPDF_Dictionary* const m_pAnnotDict;
- CPDF_Document* const m_pDocument;
- const CFX_ByteString m_sSubtype;
- std::map<CPDF_Stream*, CPDF_Form*> m_APMap;
-};
-
-class CPDF_AnnotList {
- public:
- explicit CPDF_AnnotList(CPDF_Page* pPage);
- ~CPDF_AnnotList();
-
- void DisplayAnnots(CPDF_Page* pPage,
- CPDF_RenderContext* pContext,
- FX_BOOL bPrinting,
- CFX_Matrix* pMatrix,
- FX_BOOL bShowWidget,
- CPDF_RenderOptions* pOptions) {
- DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix,
- bShowWidget ? 3 : 1, pOptions, nullptr);
- }
-
- void DisplayAnnots(CPDF_Page* pPage,
- CFX_RenderDevice* pDevice,
- CPDF_RenderContext* pContext,
- FX_BOOL bPrinting,
- CFX_Matrix* pMatrix,
- uint32_t dwAnnotFlags,
- CPDF_RenderOptions* pOptions,
- FX_RECT* pClipRect);
- size_t Count() const { return m_AnnotList.size(); }
- CPDF_Annot* GetAt(size_t index) const { return m_AnnotList[index].get(); }
- const std::vector<std::unique_ptr<CPDF_Annot>>& All() const {
- return m_AnnotList;
- }
-
- protected:
- void DisplayPass(CPDF_Page* pPage,
- CFX_RenderDevice* pDevice,
- CPDF_RenderContext* pContext,
- FX_BOOL bPrinting,
- CFX_Matrix* pMatrix,
- FX_BOOL bWidget,
- CPDF_RenderOptions* pOptions,
- FX_RECT* clip_rect);
-
- CPDF_Document* const m_pDocument;
- std::vector<std::unique_ptr<CPDF_Annot>> m_AnnotList;
-};
-
#define COLORTYPE_TRANSPARENT 0
#define COLORTYPE_GRAY 1
#define COLORTYPE_RGB 2