| OLD | NEW |
| (Empty) |
| 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/fpdf_page/cpdf_contentmark.h" | |
| 8 | |
| 9 #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h" | |
| 10 #include "third_party/base/stl_util.h" | |
| 11 | |
| 12 CPDF_ContentMark::CPDF_ContentMark() {} | |
| 13 | |
| 14 CPDF_ContentMark::CPDF_ContentMark(const CPDF_ContentMark& that) | |
| 15 : m_Ref(that.m_Ref) {} | |
| 16 | |
| 17 CPDF_ContentMark::~CPDF_ContentMark() {} | |
| 18 | |
| 19 void CPDF_ContentMark::SetNull() { | |
| 20 m_Ref.SetNull(); | |
| 21 } | |
| 22 | |
| 23 int CPDF_ContentMark::CountItems() const { | |
| 24 return m_Ref.GetObject()->CountItems(); | |
| 25 } | |
| 26 | |
| 27 const CPDF_ContentMarkItem& CPDF_ContentMark::GetItem(int i) const { | |
| 28 return m_Ref.GetObject()->GetItem(i); | |
| 29 } | |
| 30 | |
| 31 int CPDF_ContentMark::GetMCID() const { | |
| 32 const MarkData* pData = m_Ref.GetObject(); | |
| 33 return pData ? pData->GetMCID() : -1; | |
| 34 } | |
| 35 | |
| 36 void CPDF_ContentMark::AddMark(const CFX_ByteString& name, | |
| 37 CPDF_Dictionary* pDict, | |
| 38 FX_BOOL bDirect) { | |
| 39 m_Ref.GetPrivateCopy()->AddMark(name, pDict, bDirect); | |
| 40 } | |
| 41 | |
| 42 void CPDF_ContentMark::DeleteLastMark() { | |
| 43 m_Ref.GetPrivateCopy()->DeleteLastMark(); | |
| 44 if (CountItems() == 0) | |
| 45 m_Ref.SetNull(); | |
| 46 } | |
| 47 | |
| 48 bool CPDF_ContentMark::HasMark(const CFX_ByteStringC& mark) const { | |
| 49 const MarkData* pData = m_Ref.GetObject(); | |
| 50 if (!pData) | |
| 51 return false; | |
| 52 | |
| 53 for (int i = 0; i < pData->CountItems(); i++) { | |
| 54 if (pData->GetItem(i).GetName() == mark) | |
| 55 return true; | |
| 56 } | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 bool CPDF_ContentMark::LookupMark(const CFX_ByteStringC& mark, | |
| 61 CPDF_Dictionary*& pDict) const { | |
| 62 const MarkData* pData = m_Ref.GetObject(); | |
| 63 if (!pData) | |
| 64 return false; | |
| 65 | |
| 66 for (int i = 0; i < pData->CountItems(); i++) { | |
| 67 const CPDF_ContentMarkItem& item = pData->GetItem(i); | |
| 68 if (item.GetName() == mark) { | |
| 69 pDict = item.GetParam(); | |
| 70 return true; | |
| 71 } | |
| 72 } | |
| 73 return false; | |
| 74 } | |
| 75 | |
| 76 CPDF_ContentMark::MarkData::MarkData() {} | |
| 77 | |
| 78 CPDF_ContentMark::MarkData::MarkData(const MarkData& src) | |
| 79 : m_Marks(src.m_Marks) {} | |
| 80 | |
| 81 CPDF_ContentMark::MarkData::~MarkData() {} | |
| 82 | |
| 83 int CPDF_ContentMark::MarkData::CountItems() const { | |
| 84 return pdfium::CollectionSize<int>(m_Marks); | |
| 85 } | |
| 86 | |
| 87 CPDF_ContentMarkItem& CPDF_ContentMark::MarkData::GetItem(int index) { | |
| 88 return m_Marks[index]; | |
| 89 } | |
| 90 | |
| 91 const CPDF_ContentMarkItem& CPDF_ContentMark::MarkData::GetItem( | |
| 92 int index) const { | |
| 93 return m_Marks[index]; | |
| 94 } | |
| 95 | |
| 96 int CPDF_ContentMark::MarkData::GetMCID() const { | |
| 97 for (const auto& mark : m_Marks) { | |
| 98 CPDF_Dictionary* pDict = mark.GetParam(); | |
| 99 if (pDict && pDict->KeyExist("MCID")) | |
| 100 return pDict->GetIntegerFor("MCID"); | |
| 101 } | |
| 102 return -1; | |
| 103 } | |
| 104 | |
| 105 void CPDF_ContentMark::MarkData::AddMark(const CFX_ByteString& name, | |
| 106 CPDF_Dictionary* pDict, | |
| 107 FX_BOOL bDirect) { | |
| 108 CPDF_ContentMarkItem item; | |
| 109 item.SetName(name); | |
| 110 if (pDict) { | |
| 111 if (bDirect) { | |
| 112 item.SetDirectDict( | |
| 113 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>( | |
| 114 ToDictionary(pDict->Clone()))); | |
| 115 } else { | |
| 116 item.SetPropertiesDict(pDict); | |
| 117 } | |
| 118 } | |
| 119 m_Marks.push_back(std::move(item)); | |
| 120 } | |
| 121 | |
| 122 void CPDF_ContentMark::MarkData::DeleteLastMark() { | |
| 123 if (!m_Marks.empty()) | |
| 124 m_Marks.pop_back(); | |
| 125 } | |
| OLD | NEW |