• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
CPDF_ContentMark()13 CPDF_ContentMark::CPDF_ContentMark() {}
14 
CPDF_ContentMark(const CPDF_ContentMark & that)15 CPDF_ContentMark::CPDF_ContentMark(const CPDF_ContentMark& that)
16     : m_Ref(that.m_Ref) {}
17 
~CPDF_ContentMark()18 CPDF_ContentMark::~CPDF_ContentMark() {}
19 
CountItems() const20 size_t CPDF_ContentMark::CountItems() const {
21   return m_Ref.GetObject()->CountItems();
22 }
23 
GetItem(size_t i) const24 const CPDF_ContentMarkItem& CPDF_ContentMark::GetItem(size_t i) const {
25   return m_Ref.GetObject()->GetItem(i);
26 }
27 
GetMarkedContentID() const28 int CPDF_ContentMark::GetMarkedContentID() const {
29   const MarkData* pData = m_Ref.GetObject();
30   return pData ? pData->GetMarkedContentID() : -1;
31 }
32 
AddMark(const ByteString & name,CPDF_Dictionary * pDict,bool bDirect)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 
DeleteLastMark()39 void CPDF_ContentMark::DeleteLastMark() {
40   m_Ref.GetPrivateCopy()->DeleteLastMark();
41   if (CountItems() == 0)
42     m_Ref.SetNull();
43 }
44 
MarkData()45 CPDF_ContentMark::MarkData::MarkData() {}
46 
MarkData(const MarkData & src)47 CPDF_ContentMark::MarkData::MarkData(const MarkData& src)
48     : m_Marks(src.m_Marks) {}
49 
~MarkData()50 CPDF_ContentMark::MarkData::~MarkData() {}
51 
CountItems() const52 size_t CPDF_ContentMark::MarkData::CountItems() const {
53   return m_Marks.size();
54 }
55 
GetItem(size_t index) const56 const CPDF_ContentMarkItem& CPDF_ContentMark::MarkData::GetItem(
57     size_t index) const {
58   return m_Marks[index];
59 }
60 
GetMarkedContentID() const61 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 
AddMark(const ByteString & name,CPDF_Dictionary * pDict,bool bDirect)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 
DeleteLastMark()84 void CPDF_ContentMark::MarkData::DeleteLastMark() {
85   if (!m_Marks.empty())
86     m_Marks.pop_back();
87 }
88