Home | History | Annotate | Download | only in fpdfsdk
      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       copiedList.erase(it);
     29       copiedList.insert(copiedList.begin(), pTopMostAnnot);
     30     }
     31   }
     32   if (bReverse)
     33     std::reverse(copiedList.begin(), copiedList.end());
     34 
     35   m_List.reserve(copiedList.size());
     36   for (auto* pAnnot : copiedList)
     37     m_List.emplace_back(pAnnot);
     38 }
     39 
     40 CPDFSDK_AnnotIteration::~CPDFSDK_AnnotIteration() {}
     41