| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fpdfapi/fpdf_page/cpdf_contentmark.h" | 7 #include "core/fpdfapi/fpdf_page/cpdf_contentmark.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
| 10 #include "third_party/base/stl_util.h" |
| 11 |
| 9 CPDF_ContentMark::CPDF_ContentMark() {} | 12 CPDF_ContentMark::CPDF_ContentMark() {} |
| 10 | 13 |
| 11 CPDF_ContentMark::CPDF_ContentMark(const CPDF_ContentMark& that) | 14 CPDF_ContentMark::CPDF_ContentMark(const CPDF_ContentMark& that) |
| 12 : m_Ref(that.m_Ref) {} | 15 : m_Ref(that.m_Ref) {} |
| 13 | 16 |
| 14 CPDF_ContentMark::~CPDF_ContentMark() {} | 17 CPDF_ContentMark::~CPDF_ContentMark() {} |
| 15 | 18 |
| 16 void CPDF_ContentMark::SetNull() { | 19 void CPDF_ContentMark::SetNull() { |
| 17 m_Ref.SetNull(); | 20 m_Ref.SetNull(); |
| 18 } | 21 } |
| 19 | 22 |
| 20 int CPDF_ContentMark::CountItems() const { | 23 int CPDF_ContentMark::CountItems() const { |
| 21 return m_Ref.GetObject()->CountItems(); | 24 return m_Ref.GetObject()->CountItems(); |
| 22 } | 25 } |
| 23 | 26 |
| 24 const CPDF_ContentMarkItem& CPDF_ContentMark::GetItem(int i) const { | 27 const CPDF_ContentMarkItem& CPDF_ContentMark::GetItem(int i) const { |
| 25 return m_Ref.GetObject()->GetItem(i); | 28 return m_Ref.GetObject()->GetItem(i); |
| 26 } | 29 } |
| 27 | 30 |
| 28 int CPDF_ContentMark::GetMCID() const { | 31 int CPDF_ContentMark::GetMCID() const { |
| 29 const CPDF_ContentMarkData* pData = m_Ref.GetObject(); | 32 const MarkData* pData = m_Ref.GetObject(); |
| 30 return pData ? pData->GetMCID() : -1; | 33 return pData ? pData->GetMCID() : -1; |
| 31 } | 34 } |
| 32 | 35 |
| 33 void CPDF_ContentMark::AddMark(const CFX_ByteString& name, | 36 void CPDF_ContentMark::AddMark(const CFX_ByteString& name, |
| 34 CPDF_Dictionary* pDict, | 37 CPDF_Dictionary* pDict, |
| 35 FX_BOOL bDirect) { | 38 FX_BOOL bDirect) { |
| 36 m_Ref.GetPrivateCopy()->AddMark(name, pDict, bDirect); | 39 m_Ref.GetPrivateCopy()->AddMark(name, pDict, bDirect); |
| 37 } | 40 } |
| 38 | 41 |
| 39 void CPDF_ContentMark::DeleteLastMark() { | 42 void CPDF_ContentMark::DeleteLastMark() { |
| 40 m_Ref.GetPrivateCopy()->DeleteLastMark(); | 43 m_Ref.GetPrivateCopy()->DeleteLastMark(); |
| 41 if (CountItems() == 0) | 44 if (CountItems() == 0) |
| 42 m_Ref.SetNull(); | 45 m_Ref.SetNull(); |
| 43 } | 46 } |
| 44 | 47 |
| 45 bool CPDF_ContentMark::HasMark(const CFX_ByteStringC& mark) const { | 48 bool CPDF_ContentMark::HasMark(const CFX_ByteStringC& mark) const { |
| 46 const CPDF_ContentMarkData* pData = m_Ref.GetObject(); | 49 const MarkData* pData = m_Ref.GetObject(); |
| 47 if (!pData) | 50 if (!pData) |
| 48 return false; | 51 return false; |
| 49 | 52 |
| 50 for (int i = 0; i < pData->CountItems(); i++) { | 53 for (int i = 0; i < pData->CountItems(); i++) { |
| 51 if (pData->GetItem(i).GetName() == mark) | 54 if (pData->GetItem(i).GetName() == mark) |
| 52 return true; | 55 return true; |
| 53 } | 56 } |
| 54 return false; | 57 return false; |
| 55 } | 58 } |
| 56 | 59 |
| 57 bool CPDF_ContentMark::LookupMark(const CFX_ByteStringC& mark, | 60 bool CPDF_ContentMark::LookupMark(const CFX_ByteStringC& mark, |
| 58 CPDF_Dictionary*& pDict) const { | 61 CPDF_Dictionary*& pDict) const { |
| 59 const CPDF_ContentMarkData* pData = m_Ref.GetObject(); | 62 const MarkData* pData = m_Ref.GetObject(); |
| 60 if (!pData) | 63 if (!pData) |
| 61 return false; | 64 return false; |
| 62 | 65 |
| 63 for (int i = 0; i < pData->CountItems(); i++) { | 66 for (int i = 0; i < pData->CountItems(); i++) { |
| 64 const CPDF_ContentMarkItem& item = pData->GetItem(i); | 67 const CPDF_ContentMarkItem& item = pData->GetItem(i); |
| 65 if (item.GetName() == mark) { | 68 if (item.GetName() == mark) { |
| 66 pDict = nullptr; | 69 pDict = nullptr; |
| 67 if (item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict || | 70 if (item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict || |
| 68 item.GetParamType() == CPDF_ContentMarkItem::DirectDict) { | 71 item.GetParamType() == CPDF_ContentMarkItem::DirectDict) { |
| 69 pDict = item.GetParam(); | 72 pDict = item.GetParam(); |
| 70 } | 73 } |
| 71 return true; | 74 return true; |
| 72 } | 75 } |
| 73 } | 76 } |
| 74 return false; | 77 return false; |
| 75 } | 78 } |
| 79 |
| 80 CPDF_ContentMark::MarkData::MarkData() {} |
| 81 |
| 82 CPDF_ContentMark::MarkData::MarkData(const MarkData& src) |
| 83 : m_Marks(src.m_Marks) {} |
| 84 |
| 85 CPDF_ContentMark::MarkData::~MarkData() {} |
| 86 |
| 87 int CPDF_ContentMark::MarkData::CountItems() const { |
| 88 return pdfium::CollectionSize<int>(m_Marks); |
| 89 } |
| 90 |
| 91 CPDF_ContentMarkItem& CPDF_ContentMark::MarkData::GetItem(int index) { |
| 92 return m_Marks[index]; |
| 93 } |
| 94 |
| 95 const CPDF_ContentMarkItem& CPDF_ContentMark::MarkData::GetItem( |
| 96 int index) const { |
| 97 return m_Marks[index]; |
| 98 } |
| 99 |
| 100 int CPDF_ContentMark::MarkData::GetMCID() const { |
| 101 for (const auto& mark : m_Marks) { |
| 102 CPDF_ContentMarkItem::ParamType type = mark.GetParamType(); |
| 103 if (type == CPDF_ContentMarkItem::PropertiesDict || |
| 104 type == CPDF_ContentMarkItem::DirectDict) { |
| 105 CPDF_Dictionary* pDict = mark.GetParam(); |
| 106 if (pDict->KeyExist("MCID")) |
| 107 return pDict->GetIntegerBy("MCID"); |
| 108 } |
| 109 } |
| 110 return -1; |
| 111 } |
| 112 |
| 113 void CPDF_ContentMark::MarkData::AddMark(const CFX_ByteString& name, |
| 114 CPDF_Dictionary* pDict, |
| 115 FX_BOOL bDirect) { |
| 116 CPDF_ContentMarkItem item; |
| 117 item.SetName(name); |
| 118 if (pDict) { |
| 119 if (bDirect) { |
| 120 item.SetParam(CPDF_ContentMarkItem::DirectDict, |
| 121 ToDictionary(pDict->Clone())); |
| 122 } else { |
| 123 item.SetParam(CPDF_ContentMarkItem::PropertiesDict, pDict); |
| 124 } |
| 125 } |
| 126 m_Marks.push_back(item); |
| 127 } |
| 128 |
| 129 void CPDF_ContentMark::MarkData::DeleteLastMark() { |
| 130 if (!m_Marks.empty()) |
| 131 m_Marks.pop_back(); |
| 132 } |
| OLD | NEW |