summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdfsdk_annotiterator.cpp
diff options
context:
space:
mode:
authorjaepark <jaepark@google.com>2016-08-15 10:51:11 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-15 10:51:11 -0700
commit98e10199db97c8cae846cb2c0c571bda5033f61a (patch)
tree0ce8be14d90c2b6694180713484a7067df0027ff /fpdfsdk/cpdfsdk_annotiterator.cpp
parent1679d3ae2e0e64c7aba811476341a153dcef8b04 (diff)
downloadpdfium-98e10199db97c8cae846cb2c0c571bda5033f61a.tar.xz
Split fpdfsdk/fsdk_annothandler.h into individual classes.
This CL moves classes in fsdk_annothandler.h, which are CPDFSDK_AnnotIterator, CPDFSDK_AnnotHandlerMgr, IPDFSDK_AnnotHandler, CPDFSDK_XFAAnnotHandler and CPDFSDK_BFAnnotHandler, to their own files. Review-Url: https://codereview.chromium.org/2243623002
Diffstat (limited to 'fpdfsdk/cpdfsdk_annotiterator.cpp')
-rw-r--r--fpdfsdk/cpdfsdk_annotiterator.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/fpdfsdk/cpdfsdk_annotiterator.cpp b/fpdfsdk/cpdfsdk_annotiterator.cpp
new file mode 100644
index 0000000000..01a4e15379
--- /dev/null
+++ b/fpdfsdk/cpdfsdk_annotiterator.cpp
@@ -0,0 +1,54 @@
+// 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 "fpdfsdk/include/cpdfsdk_annotiterator.h"
+
+#include <algorithm>
+
+#include "fpdfsdk/include/cpdfsdk_annot.h"
+#include "fpdfsdk/include/fsdk_mgr.h"
+
+CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
+ bool bReverse)
+ : m_bReverse(bReverse), m_pos(0) {
+ const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList();
+ m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(),
+ annots.rend());
+ std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
+ [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
+ return p1->GetLayoutOrder() < p2->GetLayoutOrder();
+ });
+
+ CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
+ if (!pTopMostAnnot)
+ return;
+
+ auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(),
+ pTopMostAnnot);
+ if (it != m_iteratorAnnotList.end()) {
+ CPDFSDK_Annot* pReaderAnnot = *it;
+ m_iteratorAnnotList.erase(it);
+ m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot);
+ }
+}
+
+CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() {}
+
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() {
+ if (m_pos < m_iteratorAnnotList.size())
+ return m_iteratorAnnotList[m_pos++];
+ return nullptr;
+}
+
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() {
+ if (m_pos < m_iteratorAnnotList.size())
+ return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos];
+ return nullptr;
+}
+
+CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() {
+ return m_bReverse ? PrevAnnot() : NextAnnot();
+}