7#include "fpdfsdk/cpdfsdk_annotiterator.h"
11#include "core/fpdfapi/page/cpdf_page.h"
12#include "core/fpdfapi/parser/cpdf_dictionary.h"
13#include "core/fxcrt/stl_util.h"
14#include "fpdfsdk/cpdfsdk_annot.h"
15#include "fpdfsdk/cpdfsdk_pageview.h"
16#include "fpdfsdk/cpdfsdk_widget.h"
17#include "third_party/base/containers/adapters.h"
18#include "third_party/base/containers/contains.h"
19#include "third_party/base/containers/span.h"
28 return GetAnnotRect(p1)
.left < GetAnnotRect(p2)
.left;
32 return GetAnnotRect(p1)
.top > GetAnnotRect(p2)
.top;
38 CPDFSDK_PageView* pPageView,
39 const std::vector<CPDF_Annot::Subtype>& subtypes_to_iterate)
42 m_eTabOrder(GetTabOrder(pPageView)) {
49 return m_Annots.empty() ?
nullptr : m_Annots.front();
53 return m_Annots.empty() ?
nullptr : m_Annots.back();
57 auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot);
58 if (iter == m_Annots.end())
61 if (iter == m_Annots.end())
67 auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot);
68 if (iter == m_Annots.begin() || iter == m_Annots.end())
74 std::vector<UnownedPtr<CPDFSDK_Annot>>* pArray) {
75 for (
auto* pAnnot : m_pPageView->GetAnnotList()) {
76 if (pdfium::Contains(m_subtypes, pAnnot->GetAnnotSubtype())) {
77 CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot);
78 if (!pWidget || !pWidget->IsSignatureWidget())
79 pArray->emplace_back(pAnnot);
85 std::vector<UnownedPtr<CPDFSDK_Annot>>& sa,
89 m_Annots.emplace_back(pLeftTopAnnot);
90 sa.erase(sa.begin() + idx);
95 std::vector<UnownedPtr<CPDFSDK_Annot>>& sa,
96 pdfium::span<
const size_t> aSelect) {
97 for (size_t select_idx : aSelect) {
98 m_Annots.emplace_back(sa[select_idx]);
101 for (size_t select_idx : pdfium::base::Reversed(aSelect)) {
102 sa.erase(sa.begin() + select_idx);
108 CPDFSDK_PageView* pPageView) {
110 ByteString sTabs = pPDFPage->GetDict()->GetByteStringFor(
"Tabs");
112 return TabOrder::kRow;
114 return TabOrder::kColumn;
115 return TabOrder::kStructure;
119 switch (m_eTabOrder) {
120 case TabOrder::kStructure:
121 CollectAnnots(&m_Annots);
124 case TabOrder::kRow: {
125 std::vector<UnownedPtr<CPDFSDK_Annot>> sa;
127 std::sort(sa.begin(), sa.end(), CompareByLeftAscending);
129 while (!sa.empty()) {
130 int nLeftTopIndex = -1;
132 for (
int i =
fxcrt::CollectionSize<
int>(sa) - 1; i >= 0; i--) {
134 if (rcAnnot
.top > fTop) {
139 if (nLeftTopIndex < 0)
142 CFX_FloatRect rcLeftTop = AddToAnnotsList(sa, nLeftTopIndex);
144 std::vector<size_t> aSelect;
145 for (size_t i = 0; i < sa.size(); ++i) {
147 float fCenterY = (rcAnnot
.top + rcAnnot
.bottom) / 2.0f;
148 if (fCenterY > rcLeftTop
.bottom && fCenterY < rcLeftTop
.top)
149 aSelect.push_back(i);
151 AddSelectedToAnnots(sa, aSelect);
156 case TabOrder::kColumn: {
157 std::vector<UnownedPtr<CPDFSDK_Annot>> sa;
159 std::sort(sa.begin(), sa.end(), CompareByTopDescending);
161 while (!sa.empty()) {
162 int nLeftTopIndex = -1;
164 for (
int i =
fxcrt::CollectionSize<
int>(sa) - 1; i >= 0; --i) {
168 fLeft = rcAnnot
.left;
169 }
else if (rcAnnot
.left < fLeft) {
171 fLeft = rcAnnot
.left;
174 if (nLeftTopIndex < 0)
177 CFX_FloatRect rcLeftTop = AddToAnnotsList(sa, nLeftTopIndex);
179 std::vector<size_t> aSelect;
180 for (size_t i = 0; i < sa.size(); ++i) {
182 float fCenterX = (rcAnnot
.left + rcAnnot
.right) / 2.0f;
183 if (fCenterX > rcLeftTop
.left && fCenterX < rcLeftTop
.right)
184 aSelect.push_back(i);
186 AddSelectedToAnnots(sa, aSelect);
CPDFSDK_Annot * GetFirstAnnot()
CPDFSDK_Annot * GetLastAnnot()
CPDFSDK_AnnotIterator(CPDFSDK_PageView *pPageView, const std::vector< CPDF_Annot::Subtype > &subtypes_to_iterate)
CPDFSDK_Annot * GetNextAnnot(CPDFSDK_Annot *pAnnot)
CPDFSDK_Annot * GetPrevAnnot(CPDFSDK_Annot *pAnnot)
virtual CPDF_Annot * GetPDFAnnot() const
CPDF_Page * GetPDFPage() const
CFX_FloatRect GetRect() const
bool operator==(const char *ptr) const