Chromium Code Reviews| 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/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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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::GenerateResults() { | 69 void CBA_AnnotIterator::GenerateResults() { |
| 70 switch (m_eTabOrder) { | 70 if (m_eTabOrder == STRUCTURE) { |
|
Tom Sepez
2016/10/05 17:08:28
Dunno, I kinda like the switch and pulling the com
dsinclair
2016/10/05 17:52:51
Done.
| |
| 71 case STRUCTURE: { | 71 for (auto pAnnot : m_pPageView->GetAnnotList()) { |
| 72 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { | 72 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype && |
| 73 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); | 73 !pAnnot->IsSignatureWidget()) { |
| 74 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype && | 74 m_Annots.push_back(pAnnot); |
| 75 !pAnnot->IsSignatureWidget()) | |
| 76 m_Annots.push_back(pAnnot); | |
| 77 } | 75 } |
| 78 break; | |
| 79 } | 76 } |
| 80 case ROW: { | 77 return; |
| 81 std::vector<CPDFSDK_Annot*> sa; | 78 } |
| 82 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { | |
| 83 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); | |
| 84 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype && | |
| 85 !pAnnot->IsSignatureWidget()) | |
| 86 sa.push_back(pAnnot); | |
| 87 } | |
| 88 | 79 |
| 89 std::sort(sa.begin(), sa.end(), CompareByLeftAscending); | 80 std::vector<CPDFSDK_Annot*> sa; |
|
dsinclair
2016/10/05 14:06:47
This chunk of code was the same between ROW and CO
Tom Sepez
2016/10/05 17:08:28
Can we have a helper method like
void CBA_AnnotIt
dsinclair
2016/10/05 17:52:51
Done.
| |
| 90 while (!sa.empty()) { | 81 for (auto pAnnot : m_pPageView->GetAnnotList()) { |
| 91 int nLeftTopIndex = -1; | 82 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype && |
| 92 FX_FLOAT fTop = 0.0f; | 83 !pAnnot->IsSignatureWidget()) { |
| 93 for (int i = sa.size() - 1; i >= 0; i--) { | 84 sa.push_back(pAnnot); |
| 94 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); | 85 } |
| 95 if (rcAnnot.top > fTop) { | 86 } |
| 96 nLeftTopIndex = i; | 87 if (sa.empty()) |
| 97 fTop = rcAnnot.top; | 88 return; |
| 98 } | |
| 99 } | |
| 100 if (nLeftTopIndex >= 0) { | |
| 101 CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex]; | |
| 102 CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot); | |
| 103 m_Annots.push_back(pLeftTopAnnot); | |
| 104 sa.erase(sa.begin() + nLeftTopIndex); | |
| 105 | 89 |
| 106 std::vector<int> aSelect; | 90 if (m_eTabOrder == ROW) { |
| 107 for (size_t i = 0; i < sa.size(); ++i) { | 91 std::sort(sa.begin(), sa.end(), CompareByLeftAscending); |
| 108 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); | 92 while (!sa.empty()) { |
| 109 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f; | 93 int nLeftTopIndex = -1; |
|
Tom Sepez
2016/10/05 17:08:28
Maybe code from 93-100 becomes a function GetLeftT
dsinclair
2016/10/05 17:52:51
The actual comparisons done at ~97 are different b
Tom Sepez
2016/10/05 17:59:52
Ah, ok. nevermind.
| |
| 110 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top) | 94 FX_FLOAT fTop = 0.0f; |
| 111 aSelect.push_back(i); | 95 for (int i = sa.size() - 1; i >= 0; i--) { |
| 112 } | 96 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
| 113 for (size_t i = 0; i < aSelect.size(); ++i) | 97 if (rcAnnot.top > fTop) { |
| 114 m_Annots.push_back(sa[aSelect[i]]); | 98 nLeftTopIndex = i; |
| 115 | 99 fTop = rcAnnot.top; |
| 116 for (int i = aSelect.size() - 1; i >= 0; --i) | |
| 117 sa.erase(sa.begin() + aSelect[i]); | |
| 118 } | 100 } |
| 119 } | 101 } |
| 120 break; | 102 if (nLeftTopIndex >= 0) { |
| 103 CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex]; | |
| 104 CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot); | |
| 105 m_Annots.push_back(pLeftTopAnnot); | |
| 106 sa.erase(sa.begin() + nLeftTopIndex); | |
| 107 | |
| 108 std::vector<int> aSelect; | |
| 109 for (size_t i = 0; i < sa.size(); ++i) { | |
| 110 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); | |
| 111 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f; | |
| 112 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top) | |
| 113 aSelect.push_back(i); | |
| 114 } | |
| 115 for (size_t i = 0; i < aSelect.size(); ++i) | |
| 116 m_Annots.push_back(sa[aSelect[i]]); | |
| 117 | |
| 118 for (int i = aSelect.size() - 1; i >= 0; --i) | |
| 119 sa.erase(sa.begin() + aSelect[i]); | |
| 120 } | |
| 121 } | 121 } |
| 122 case COLUMN: { | 122 return; |
| 123 std::vector<CPDFSDK_Annot*> sa; | 123 } |
| 124 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { | 124 |
| 125 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); | 125 std::sort(sa.begin(), sa.end(), CompareByTopDescending); |
| 126 if (pAnnot->GetAnnotSubtype() == m_nAnnotSubtype && | 126 while (!sa.empty()) { |
| 127 !pAnnot->IsSignatureWidget()) | 127 int nLeftTopIndex = -1; |
| 128 sa.push_back(pAnnot); | 128 FX_FLOAT fLeft = -1.0f; |
| 129 for (int i = sa.size() - 1; i >= 0; --i) { | |
| 130 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); | |
| 131 if (fLeft < 0) { | |
| 132 nLeftTopIndex = 0; | |
| 133 fLeft = rcAnnot.left; | |
| 134 } else if (rcAnnot.left < fLeft) { | |
| 135 nLeftTopIndex = i; | |
| 136 fLeft = rcAnnot.left; | |
| 129 } | 137 } |
| 138 } | |
| 130 | 139 |
| 131 std::sort(sa.begin(), sa.end(), CompareByTopDescending); | 140 if (nLeftTopIndex >= 0) { |
| 132 while (!sa.empty()) { | 141 CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex]; |
| 133 int nLeftTopIndex = -1; | 142 CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot); |
| 134 FX_FLOAT fLeft = -1.0f; | 143 m_Annots.push_back(pLeftTopAnnot); |
| 135 for (int i = sa.size() - 1; i >= 0; --i) { | 144 sa.erase(sa.begin() + nLeftTopIndex); |
| 136 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); | |
| 137 if (fLeft < 0) { | |
| 138 nLeftTopIndex = 0; | |
| 139 fLeft = rcAnnot.left; | |
| 140 } else if (rcAnnot.left < fLeft) { | |
| 141 nLeftTopIndex = i; | |
| 142 fLeft = rcAnnot.left; | |
| 143 } | |
| 144 } | |
| 145 | 145 |
| 146 if (nLeftTopIndex >= 0) { | 146 std::vector<int> aSelect; |
| 147 CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex]; | 147 for (size_t i = 0; i < sa.size(); ++i) { |
| 148 CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot); | 148 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
| 149 m_Annots.push_back(pLeftTopAnnot); | 149 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f; |
| 150 sa.erase(sa.begin() + nLeftTopIndex); | 150 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right) |
| 151 aSelect.push_back(i); | |
| 152 } | |
| 153 for (size_t i = 0; i < aSelect.size(); ++i) | |
| 154 m_Annots.push_back(sa[aSelect[i]]); | |
| 151 | 155 |
| 152 std::vector<int> aSelect; | 156 for (int i = aSelect.size() - 1; i >= 0; --i) |
| 153 for (size_t i = 0; i < sa.size(); ++i) { | 157 sa.erase(sa.begin() + aSelect[i]); |
| 154 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); | |
| 155 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f; | |
| 156 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right) | |
| 157 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 } | |
| 165 } | |
| 166 break; | |
| 167 } | 158 } |
| 168 } | 159 } |
| 169 } | 160 } |
| 170 | 161 |
| 171 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { | 162 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { |
| 172 return pAnnot->GetPDFAnnot()->GetRect(); | 163 return pAnnot->GetPDFAnnot()->GetRect(); |
| 173 } | 164 } |
| OLD | NEW |