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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fpdfsdk/cba_annotiterator.h" 7 #include "fpdfsdk/cba_annotiterator.h"
8 8
9 #include "core/fpdfapi/page/cpdf_page.h" 9 #include "core/fpdfapi/page/cpdf_page.h"
10 #include "fpdfsdk/cpdfsdk_annot.h" 10 #include "fpdfsdk/cpdfsdk_annot.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot) { 60 CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot) {
61 auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot); 61 auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot);
62 if (iter == m_Annots.end()) 62 if (iter == m_Annots.end())
63 return nullptr; 63 return nullptr;
64 if (iter == m_Annots.begin()) 64 if (iter == m_Annots.begin())
65 iter = m_Annots.end(); 65 iter = m_Annots.end();
66 return *(--iter); 66 return *(--iter);
67 } 67 }
68 68
69 void CBA_AnnotIterator::CollectAnnots(std::vector<CPDFSDK_Annot*>* pArray) {
70 for (auto pAnnot : m_pPageView->GetAnnotList()) {
71 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype &&
72 !pAnnot->IsSignatureWidget()) {
73 pArray->push_back(pAnnot);
74 }
75 }
76 }
77
78 CFX_FloatRect CBA_AnnotIterator::AddToAnnotsList(
79 std::vector<CPDFSDK_Annot*>& sa,
80 size_t idx) {
81 CPDFSDK_Annot* pLeftTopAnnot = sa[idx];
82 CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
83 m_Annots.push_back(pLeftTopAnnot);
84 sa.erase(sa.begin() + idx);
85 return rcLeftTop;
86 }
87
88 void CBA_AnnotIterator::AddSelectedToAnnots(std::vector<CPDFSDK_Annot*>& sa,
89 std::vector<size_t>& aSelect) {
90 for (size_t i = 0; i < aSelect.size(); ++i)
91 m_Annots.push_back(sa[aSelect[i]]);
92
93 for (int i = aSelect.size() - 1; i >= 0; --i)
94 sa.erase(sa.begin() + aSelect[i]);
95 }
96
69 void CBA_AnnotIterator::GenerateResults() { 97 void CBA_AnnotIterator::GenerateResults() {
70 switch (m_eTabOrder) { 98 switch (m_eTabOrder) {
71 case STRUCTURE: { 99 case STRUCTURE:
72 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { 100 CollectAnnots(&m_Annots);
73 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
74 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype &&
75 !pAnnot->IsSignatureWidget())
76 m_Annots.push_back(pAnnot);
77 }
78 break; 101 break;
79 } 102
80 case ROW: { 103 case ROW: {
81 std::vector<CPDFSDK_Annot*> sa; 104 std::vector<CPDFSDK_Annot*> sa;
82 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { 105 CollectAnnots(&sa);
83 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
84 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype &&
85 !pAnnot->IsSignatureWidget())
86 sa.push_back(pAnnot);
87 }
88 106
89 std::sort(sa.begin(), sa.end(), CompareByLeftAscending); 107 std::sort(sa.begin(), sa.end(), CompareByLeftAscending);
Tom Sepez 2016/10/05 17:59:52 super-super-super-nit: I'd put the blank line aft
dsinclair 2016/10/05 18:26:56 Done.
90 while (!sa.empty()) { 108 while (!sa.empty()) {
91 int nLeftTopIndex = -1; 109 int nLeftTopIndex = -1;
92 FX_FLOAT fTop = 0.0f; 110 FX_FLOAT fTop = 0.0f;
93 for (int i = sa.size() - 1; i >= 0; i--) { 111 for (int i = sa.size() - 1; i >= 0; i--) {
94 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); 112 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
95 if (rcAnnot.top > fTop) { 113 if (rcAnnot.top > fTop) {
96 nLeftTopIndex = i; 114 nLeftTopIndex = i;
97 fTop = rcAnnot.top; 115 fTop = rcAnnot.top;
98 } 116 }
99 } 117 }
100 if (nLeftTopIndex >= 0) { 118 if (nLeftTopIndex < 0)
101 CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex]; 119 continue;
102 CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
103 m_Annots.push_back(pLeftTopAnnot);
104 sa.erase(sa.begin() + nLeftTopIndex);
105 120
106 std::vector<int> aSelect; 121 CFX_FloatRect rcLeftTop = AddToAnnotsList(sa, nLeftTopIndex);
107 for (size_t i = 0; i < sa.size(); ++i) {
108 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
109 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
110 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
111 aSelect.push_back(i);
112 }
113 for (size_t i = 0; i < aSelect.size(); ++i)
114 m_Annots.push_back(sa[aSelect[i]]);
115 122
116 for (int i = aSelect.size() - 1; i >= 0; --i) 123 std::vector<size_t> aSelect;
117 sa.erase(sa.begin() + aSelect[i]); 124 for (size_t i = 0; i < sa.size(); ++i) {
125 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
126 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
127 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
128 aSelect.push_back(i);
118 } 129 }
130 AddSelectedToAnnots(sa, aSelect);
119 } 131 }
120 break; 132 break;
121 } 133 }
134
122 case COLUMN: { 135 case COLUMN: {
123 std::vector<CPDFSDK_Annot*> sa; 136 std::vector<CPDFSDK_Annot*> sa;
124 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { 137 CollectAnnots(&sa);
125 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
126 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype &&
127 !pAnnot->IsSignatureWidget())
128 sa.push_back(pAnnot);
129 }
130 138
131 std::sort(sa.begin(), sa.end(), CompareByTopDescending); 139 std::sort(sa.begin(), sa.end(), CompareByTopDescending);
132 while (!sa.empty()) { 140 while (!sa.empty()) {
133 int nLeftTopIndex = -1; 141 int nLeftTopIndex = -1;
134 FX_FLOAT fLeft = -1.0f; 142 FX_FLOAT fLeft = -1.0f;
135 for (int i = sa.size() - 1; i >= 0; --i) { 143 for (int i = sa.size() - 1; i >= 0; --i) {
136 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); 144 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
137 if (fLeft < 0) { 145 if (fLeft < 0) {
138 nLeftTopIndex = 0; 146 nLeftTopIndex = 0;
139 fLeft = rcAnnot.left; 147 fLeft = rcAnnot.left;
140 } else if (rcAnnot.left < fLeft) { 148 } else if (rcAnnot.left < fLeft) {
141 nLeftTopIndex = i; 149 nLeftTopIndex = i;
142 fLeft = rcAnnot.left; 150 fLeft = rcAnnot.left;
143 } 151 }
144 } 152 }
153 if (nLeftTopIndex < 0)
154 continue;
145 155
146 if (nLeftTopIndex >= 0) { 156 CFX_FloatRect rcLeftTop = AddToAnnotsList(sa, nLeftTopIndex);
147 CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex];
148 CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
149 m_Annots.push_back(pLeftTopAnnot);
150 sa.erase(sa.begin() + nLeftTopIndex);
151 157
152 std::vector<int> aSelect; 158 std::vector<size_t> aSelect;
153 for (size_t i = 0; i < sa.size(); ++i) { 159 for (size_t i = 0; i < sa.size(); ++i) {
154 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); 160 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
155 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f; 161 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
156 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right) 162 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
157 aSelect.push_back(i); 163 aSelect.push_back(i);
158 }
159 for (size_t i = 0; i < aSelect.size(); ++i)
160 m_Annots.push_back(sa[aSelect[i]]);
161
162 for (int i = aSelect.size() - 1; i >= 0; --i)
163 sa.erase(sa.begin() + aSelect[i]);
164 } 164 }
165 AddSelectedToAnnots(sa, aSelect);
165 } 166 }
166 break; 167 break;
167 } 168 }
168 } 169 }
169 } 170 }
170 171
171 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { 172 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) {
172 return pAnnot->GetPDFAnnot()->GetRect(); 173 return pAnnot->GetPDFAnnot()->GetRect();
173 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698