OLD | NEW |
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& sType, | 26 const CFX_ByteString& sAnnotSubtype) |
27 const CFX_ByteString& sSubType) | |
28 : m_eTabOrder(STRUCTURE), | 27 : m_eTabOrder(STRUCTURE), |
29 m_pPageView(pPageView), | 28 m_pPageView(pPageView), |
30 m_sType(sType), | 29 m_sAnnotSubtype(sAnnotSubtype) { |
31 m_sSubType(sSubType) { | |
32 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage(); | 30 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage(); |
33 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetStringBy("Tabs"); | 31 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetStringBy("Tabs"); |
34 if (sTabs == "R") | 32 if (sTabs == "R") |
35 m_eTabOrder = ROW; | 33 m_eTabOrder = ROW; |
36 else if (sTabs == "C") | 34 else if (sTabs == "C") |
37 m_eTabOrder = COLUMN; | 35 m_eTabOrder = COLUMN; |
38 | 36 |
39 GenerateResults(); | 37 GenerateResults(); |
40 } | 38 } |
41 | 39 |
(...skipping 24 matching lines...) Expand all Loading... |
66 if (iter == m_Annots.begin()) | 64 if (iter == m_Annots.begin()) |
67 iter = m_Annots.end(); | 65 iter = m_Annots.end(); |
68 return *(--iter); | 66 return *(--iter); |
69 } | 67 } |
70 | 68 |
71 void CBA_AnnotIterator::GenerateResults() { | 69 void CBA_AnnotIterator::GenerateResults() { |
72 switch (m_eTabOrder) { | 70 switch (m_eTabOrder) { |
73 case STRUCTURE: { | 71 case STRUCTURE: { |
74 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { | 72 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
75 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); | 73 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
76 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) | 74 if (pAnnot->GetAnnotSubtype() == m_sAnnotSubtype && |
| 75 !pAnnot->IsSignatureWidget()) |
77 m_Annots.push_back(pAnnot); | 76 m_Annots.push_back(pAnnot); |
78 } | 77 } |
79 break; | 78 break; |
80 } | 79 } |
81 case ROW: { | 80 case ROW: { |
82 std::vector<CPDFSDK_Annot*> sa; | 81 std::vector<CPDFSDK_Annot*> sa; |
83 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { | 82 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
84 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); | 83 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
85 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) | 84 if (pAnnot->GetAnnotSubtype() == m_sAnnotSubtype && |
| 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]); |
95 if (rcAnnot.top > fTop) { | 95 if (rcAnnot.top > fTop) { |
(...skipping 20 matching lines...) Expand all Loading... |
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->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) | 126 if (pAnnot->GetAnnotSubtype() == m_sAnnotSubtype && |
| 127 !pAnnot->IsSignatureWidget()) |
127 sa.push_back(pAnnot); | 128 sa.push_back(pAnnot); |
128 } | 129 } |
129 | 130 |
130 std::sort(sa.begin(), sa.end(), CompareByTopDescending); | 131 std::sort(sa.begin(), sa.end(), CompareByTopDescending); |
131 while (!sa.empty()) { | 132 while (!sa.empty()) { |
132 int nLeftTopIndex = -1; | 133 int nLeftTopIndex = -1; |
133 FX_FLOAT fLeft = -1.0f; | 134 FX_FLOAT fLeft = -1.0f; |
134 for (int i = sa.size() - 1; i >= 0; --i) { | 135 for (int i = sa.size() - 1; i >= 0; --i) { |
135 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); | 136 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
136 if (fLeft < 0) { | 137 if (fLeft < 0) { |
(...skipping 26 matching lines...) Expand all Loading... |
163 } | 164 } |
164 } | 165 } |
165 break; | 166 break; |
166 } | 167 } |
167 } | 168 } |
168 } | 169 } |
169 | 170 |
170 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { | 171 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { |
171 return pAnnot->GetPDFAnnot()->GetRect(); | 172 return pAnnot->GetPDFAnnot()->GetRect(); |
172 } | 173 } |
OLD | NEW |