1 // Copyright 2016 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 "core/fpdfapi/page/cpdf_contentmark.h" 8 9 #include <utility> 10 11 #include "core/fpdfapi/parser/cpdf_dictionary.h" 12 13 CPDF_ContentMark::CPDF_ContentMark() {} 14 15 CPDF_ContentMark::CPDF_ContentMark(const CPDF_ContentMark& that) 16 : m_Ref(that.m_Ref) {} 17 18 CPDF_ContentMark::~CPDF_ContentMark() {} 19 20 size_t CPDF_ContentMark::CountItems() const { 21 return m_Ref.GetObject()->CountItems(); 22 } 23 24 const CPDF_ContentMarkItem& CPDF_ContentMark::GetItem(size_t i) const { 25 return m_Ref.GetObject()->GetItem(i); 26 } 27 28 int CPDF_ContentMark::GetMarkedContentID() const { 29 const MarkData* pData = m_Ref.GetObject(); 30 return pData ? pData->GetMarkedContentID() : -1; 31 } 32 33 void CPDF_ContentMark::AddMark(const ByteString& name, 34 CPDF_Dictionary* pDict, 35 bool bDirect) { 36 m_Ref.GetPrivateCopy()->AddMark(name, pDict, bDirect); 37 } 38 39 void CPDF_ContentMark::DeleteLastMark() { 40 m_Ref.GetPrivateCopy()->DeleteLastMark(); 41 if (CountItems() == 0) 42 m_Ref.SetNull(); 43 } 44 45 CPDF_ContentMark::MarkData::MarkData() {} 46 47 CPDF_ContentMark::MarkData::MarkData(const MarkData& src) 48 : m_Marks(src.m_Marks) {} 49 50 CPDF_ContentMark::MarkData::~MarkData() {} 51 52 size_t CPDF_ContentMark::MarkData::CountItems() const { 53 return m_Marks.size(); 54 } 55 56 const CPDF_ContentMarkItem& CPDF_ContentMark::MarkData::GetItem( 57 size_t index) const { 58 return m_Marks[index]; 59 } 60 61 int CPDF_ContentMark::MarkData::GetMarkedContentID() const { 62 for (const auto& mark : m_Marks) { 63 const CPDF_Dictionary* pDict = mark.GetParam(); 64 if (pDict && pDict->KeyExist("MCID")) 65 return pDict->GetIntegerFor("MCID"); 66 } 67 return -1; 68 } 69 70 void CPDF_ContentMark::MarkData::AddMark(const ByteString& name, 71 CPDF_Dictionary* pDict, 72 bool bDirect) { 73 CPDF_ContentMarkItem item; 74 item.SetName(name); 75 if (pDict) { 76 if (bDirect) 77 item.SetDirectDict(ToDictionary(pDict->Clone())); 78 else 79 item.SetPropertiesDict(pDict); 80 } 81 m_Marks.push_back(std::move(item)); 82 } 83 84 void CPDF_ContentMark::MarkData::DeleteLastMark() { 85 if (!m_Marks.empty()) 86 m_Marks.pop_back(); 87 } 88