Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1171)

Unified Diff: fpdfsdk/cba_annotiterator.cpp

Issue 2384323005: Cleanup some CPDFSDK_PageView annotation code. (Closed)
Patch Set: Review feedback Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fpdfsdk/cba_annotiterator.h ('k') | fpdfsdk/cpdfsdk_document.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/cba_annotiterator.cpp
diff --git a/fpdfsdk/cba_annotiterator.cpp b/fpdfsdk/cba_annotiterator.cpp
index ef9ab2ad31e59620fbac064be846f12ae746b9a8..a447034cda3ae1aafd9894b5eb0dc99fb23aea0c 100644
--- a/fpdfsdk/cba_annotiterator.cpp
+++ b/fpdfsdk/cba_annotiterator.cpp
@@ -10,18 +10,22 @@
#include "fpdfsdk/cpdfsdk_annot.h"
#include "fpdfsdk/cpdfsdk_pageview.h"
-// static
-bool CBA_AnnotIterator::CompareByLeftAscending(const CPDFSDK_Annot* p1,
- const CPDFSDK_Annot* p2) {
+namespace {
+
+CFX_FloatRect GetAnnotRect(const CPDFSDK_Annot* pAnnot) {
+ return pAnnot->GetPDFAnnot()->GetRect();
+}
+
+bool CompareByLeftAscending(const CPDFSDK_Annot* p1, const CPDFSDK_Annot* p2) {
return GetAnnotRect(p1).left < GetAnnotRect(p2).left;
}
-// static
-bool CBA_AnnotIterator::CompareByTopDescending(const CPDFSDK_Annot* p1,
- const CPDFSDK_Annot* p2) {
+bool CompareByTopDescending(const CPDFSDK_Annot* p1, const CPDFSDK_Annot* p2) {
return GetAnnotRect(p1).top > GetAnnotRect(p2).top;
}
+} // namespace
+
CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView,
CPDF_Annot::Subtype nAnnotSubtype)
: m_eTabOrder(STRUCTURE),
@@ -66,27 +70,45 @@ CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot) {
return *(--iter);
}
+void CBA_AnnotIterator::CollectAnnots(std::vector<CPDFSDK_Annot*>* pArray) {
+ for (auto pAnnot : m_pPageView->GetAnnotList()) {
+ if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype &&
+ !pAnnot->IsSignatureWidget()) {
+ pArray->push_back(pAnnot);
+ }
+ }
+}
+
+CFX_FloatRect CBA_AnnotIterator::AddToAnnotsList(
+ std::vector<CPDFSDK_Annot*>* sa,
+ size_t idx) {
+ CPDFSDK_Annot* pLeftTopAnnot = sa->at(idx);
+ CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
+ m_Annots.push_back(pLeftTopAnnot);
+ sa->erase(sa->begin() + idx);
+ return rcLeftTop;
+}
+
+void CBA_AnnotIterator::AddSelectedToAnnots(std::vector<CPDFSDK_Annot*>* sa,
+ std::vector<size_t>* aSelect) {
+ for (size_t i = 0; i < aSelect->size(); ++i)
+ m_Annots.push_back(sa->at(aSelect->at(i)));
+
+ for (int i = aSelect->size() - 1; i >= 0; --i)
+ sa->erase(sa->begin() + aSelect->at(i));
+}
+
void CBA_AnnotIterator::GenerateResults() {
switch (m_eTabOrder) {
- case STRUCTURE: {
- for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
- CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
- if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype &&
- !pAnnot->IsSignatureWidget())
- m_Annots.push_back(pAnnot);
- }
+ case STRUCTURE:
+ CollectAnnots(&m_Annots);
break;
- }
+
case ROW: {
std::vector<CPDFSDK_Annot*> sa;
- for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
- CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
- if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype &&
- !pAnnot->IsSignatureWidget())
- sa.push_back(pAnnot);
- }
-
+ CollectAnnots(&sa);
std::sort(sa.begin(), sa.end(), CompareByLeftAscending);
+
while (!sa.empty()) {
int nLeftTopIndex = -1;
FX_FLOAT fTop = 0.0f;
@@ -97,38 +119,28 @@ void CBA_AnnotIterator::GenerateResults() {
fTop = rcAnnot.top;
}
}
- if (nLeftTopIndex >= 0) {
- CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex];
- CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
- m_Annots.push_back(pLeftTopAnnot);
- sa.erase(sa.begin() + nLeftTopIndex);
-
- std::vector<int> aSelect;
- for (size_t i = 0; i < sa.size(); ++i) {
- CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
- FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
- if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
- aSelect.push_back(i);
- }
- for (size_t i = 0; i < aSelect.size(); ++i)
- m_Annots.push_back(sa[aSelect[i]]);
+ if (nLeftTopIndex < 0)
+ continue;
+
+ CFX_FloatRect rcLeftTop = AddToAnnotsList(&sa, nLeftTopIndex);
- for (int i = aSelect.size() - 1; i >= 0; --i)
- sa.erase(sa.begin() + aSelect[i]);
+ std::vector<size_t> aSelect;
+ for (size_t i = 0; i < sa.size(); ++i) {
+ CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
+ FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
+ if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
+ aSelect.push_back(i);
}
+ AddSelectedToAnnots(&sa, &aSelect);
}
break;
}
+
case COLUMN: {
std::vector<CPDFSDK_Annot*> sa;
- for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
- CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
- if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype &&
- !pAnnot->IsSignatureWidget())
- sa.push_back(pAnnot);
- }
-
+ CollectAnnots(&sa);
std::sort(sa.begin(), sa.end(), CompareByTopDescending);
+
while (!sa.empty()) {
int nLeftTopIndex = -1;
FX_FLOAT fLeft = -1.0f;
@@ -142,32 +154,21 @@ void CBA_AnnotIterator::GenerateResults() {
fLeft = rcAnnot.left;
}
}
+ if (nLeftTopIndex < 0)
+ continue;
- if (nLeftTopIndex >= 0) {
- CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex];
- CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
- m_Annots.push_back(pLeftTopAnnot);
- sa.erase(sa.begin() + nLeftTopIndex);
-
- std::vector<int> aSelect;
- for (size_t i = 0; i < sa.size(); ++i) {
- CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
- FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
- if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
- aSelect.push_back(i);
- }
- for (size_t i = 0; i < aSelect.size(); ++i)
- m_Annots.push_back(sa[aSelect[i]]);
+ CFX_FloatRect rcLeftTop = AddToAnnotsList(&sa, nLeftTopIndex);
- for (int i = aSelect.size() - 1; i >= 0; --i)
- sa.erase(sa.begin() + aSelect[i]);
+ std::vector<size_t> aSelect;
+ for (size_t i = 0; i < sa.size(); ++i) {
+ CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
+ FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
+ if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
+ aSelect.push_back(i);
}
+ AddSelectedToAnnots(&sa, &aSelect);
}
break;
}
}
}
-
-CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) {
- return pAnnot->GetPDFAnnot()->GetRect();
-}
« no previous file with comments | « fpdfsdk/cba_annotiterator.h ('k') | fpdfsdk/cpdfsdk_document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698