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

Side by Side Diff: fpdfsdk/cba_annotiterator.cpp

Issue 2295953002: Use enum class for subtypes of CPDF_Annot. (Closed)
Patch Set: Use enum class for subtypes of CPDF_Annot. Created 4 years, 3 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
« no previous file with comments | « core/fpdfdoc/include/cpdf_annot.h ('k') | fpdfsdk/cpdfsdk_annot.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/include/cba_annotiterator.h" 7 #include "fpdfsdk/include/cba_annotiterator.h"
8 8
9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" 9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
10 #include "fpdfsdk/include/cpdfsdk_annot.h" 10 #include "fpdfsdk/include/cpdfsdk_annot.h"
11 #include "fpdfsdk/include/fsdk_mgr.h" 11 #include "fpdfsdk/include/fsdk_mgr.h"
12 12
13 // static 13 // static
14 bool CBA_AnnotIterator::CompareByLeftAscending(const CPDFSDK_Annot* p1, 14 bool CBA_AnnotIterator::CompareByLeftAscending(const CPDFSDK_Annot* p1,
15 const CPDFSDK_Annot* p2) { 15 const CPDFSDK_Annot* p2) {
16 return GetAnnotRect(p1).left < GetAnnotRect(p2).left; 16 return GetAnnotRect(p1).left < GetAnnotRect(p2).left;
17 } 17 }
18 18
19 // static 19 // static
20 bool CBA_AnnotIterator::CompareByTopDescending(const CPDFSDK_Annot* p1, 20 bool CBA_AnnotIterator::CompareByTopDescending(const CPDFSDK_Annot* p1,
21 const CPDFSDK_Annot* p2) { 21 const CPDFSDK_Annot* p2) {
22 return GetAnnotRect(p1).top > GetAnnotRect(p2).top; 22 return GetAnnotRect(p1).top > GetAnnotRect(p2).top;
23 } 23 }
24 24
25 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, 25 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView,
26 const CFX_ByteString& sAnnotSubtype) 26 CPDF_Annot::Subtype nAnnotSubtype)
27 : m_eTabOrder(STRUCTURE), 27 : m_eTabOrder(STRUCTURE),
28 m_pPageView(pPageView), 28 m_pPageView(pPageView),
29 m_sAnnotSubtype(sAnnotSubtype) { 29 m_nAnnotSubtype(nAnnotSubtype) {
30 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage(); 30 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage();
31 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetStringBy("Tabs"); 31 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetStringBy("Tabs");
32 if (sTabs == "R") 32 if (sTabs == "R")
33 m_eTabOrder = ROW; 33 m_eTabOrder = ROW;
34 else if (sTabs == "C") 34 else if (sTabs == "C")
35 m_eTabOrder = COLUMN; 35 m_eTabOrder = COLUMN;
36 36
37 GenerateResults(); 37 GenerateResults();
38 } 38 }
39 39
(...skipping 24 matching lines...) Expand all
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::GenerateResults() { 69 void CBA_AnnotIterator::GenerateResults() {
70 switch (m_eTabOrder) { 70 switch (m_eTabOrder) {
71 case STRUCTURE: { 71 case STRUCTURE: {
72 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { 72 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
73 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); 73 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
74 if (pAnnot->GetAnnotSubtype() == m_sAnnotSubtype && 74 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype &&
75 !pAnnot->IsSignatureWidget()) 75 !pAnnot->IsSignatureWidget())
76 m_Annots.push_back(pAnnot); 76 m_Annots.push_back(pAnnot);
77 } 77 }
78 break; 78 break;
79 } 79 }
80 case ROW: { 80 case ROW: {
81 std::vector<CPDFSDK_Annot*> sa; 81 std::vector<CPDFSDK_Annot*> sa;
82 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { 82 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
83 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); 83 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
84 if (pAnnot->GetAnnotSubtype() == m_sAnnotSubtype && 84 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype &&
85 !pAnnot->IsSignatureWidget()) 85 !pAnnot->IsSignatureWidget())
86 sa.push_back(pAnnot); 86 sa.push_back(pAnnot);
87 } 87 }
88 88
89 std::sort(sa.begin(), sa.end(), CompareByLeftAscending); 89 std::sort(sa.begin(), sa.end(), CompareByLeftAscending);
90 while (!sa.empty()) { 90 while (!sa.empty()) {
91 int nLeftTopIndex = -1; 91 int nLeftTopIndex = -1;
92 FX_FLOAT fTop = 0.0f; 92 FX_FLOAT fTop = 0.0f;
93 for (int i = sa.size() - 1; i >= 0; i--) { 93 for (int i = sa.size() - 1; i >= 0; i--) {
94 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); 94 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
(...skipping 21 matching lines...) Expand all
116 for (int i = aSelect.size() - 1; i >= 0; --i) 116 for (int i = aSelect.size() - 1; i >= 0; --i)
117 sa.erase(sa.begin() + aSelect[i]); 117 sa.erase(sa.begin() + aSelect[i]);
118 } 118 }
119 } 119 }
120 break; 120 break;
121 } 121 }
122 case COLUMN: { 122 case COLUMN: {
123 std::vector<CPDFSDK_Annot*> sa; 123 std::vector<CPDFSDK_Annot*> sa;
124 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { 124 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
125 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); 125 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
126 if (pAnnot->GetAnnotSubtype() == m_sAnnotSubtype && 126 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype &&
127 !pAnnot->IsSignatureWidget()) 127 !pAnnot->IsSignatureWidget())
128 sa.push_back(pAnnot); 128 sa.push_back(pAnnot);
129 } 129 }
130 130
131 std::sort(sa.begin(), sa.end(), CompareByTopDescending); 131 std::sort(sa.begin(), sa.end(), CompareByTopDescending);
132 while (!sa.empty()) { 132 while (!sa.empty()) {
133 int nLeftTopIndex = -1; 133 int nLeftTopIndex = -1;
134 FX_FLOAT fLeft = -1.0f; 134 FX_FLOAT fLeft = -1.0f;
135 for (int i = sa.size() - 1; i >= 0; --i) { 135 for (int i = sa.size() - 1; i >= 0; --i) {
136 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); 136 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
(...skipping 27 matching lines...) Expand all
164 } 164 }
165 } 165 }
166 break; 166 break;
167 } 167 }
168 } 168 }
169 } 169 }
170 170
171 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { 171 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) {
172 return pAnnot->GetPDFAnnot()->GetRect(); 172 return pAnnot->GetPDFAnnot()->GetRect();
173 } 173 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/include/cpdf_annot.h ('k') | fpdfsdk/cpdfsdk_annot.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698