OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "fpdfsdk/cpdfsdk_annotiteration.h" | |
8 | |
9 #include <algorithm> | |
10 #include <utility> | |
11 | |
12 #include "fpdfsdk/cpdfsdk_annot.h" | |
13 #include "fpdfsdk/cpdfsdk_pageview.h" | |
14 | |
15 CPDFSDK_AnnotIteration::CPDFSDK_AnnotIteration(CPDFSDK_PageView* pPageView, | |
16 bool bReverse) { | |
17 // Copying/sorting ObservedPtrs is expensive, so do it once at the end. | |
18 std::vector<CPDFSDK_Annot*> copiedList = pPageView->GetAnnotList(); | |
19 std::stable_sort(copiedList.begin(), copiedList.end(), | |
20 [](const CPDFSDK_Annot* p1, const CPDFSDK_Annot* p2) { | |
21 return p1->GetLayoutOrder() < p2->GetLayoutOrder(); | |
22 }); | |
23 | |
24 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot(); | |
25 if (pTopMostAnnot) { | |
26 auto it = std::find(copiedList.begin(), copiedList.end(), pTopMostAnnot); | |
27 if (it != copiedList.end()) { | |
28 CPDFSDK_Annot* pSaved = *it; | |
dsinclair
2017/01/11 21:44:24
Is this needed? Won't pSaved == pTopMostAnnot?
Tom Sepez
2017/01/11 21:48:52
Done.
| |
29 copiedList.erase(it); | |
30 copiedList.insert(copiedList.begin(), pSaved); | |
31 } | |
32 } | |
33 if (bReverse) | |
34 std::reverse(copiedList.begin(), copiedList.end()); | |
35 | |
36 m_List.reserve(copiedList.size()); | |
37 for (const auto& pAnnot : copiedList) | |
38 m_List.emplace_back(pAnnot); | |
39 } | |
40 | |
41 CPDFSDK_AnnotIteration::~CPDFSDK_AnnotIteration() {} | |
OLD | NEW |