diff options
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r-- | core/fpdfapi/parser/cpdf_dictionary.cpp | 11 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_dictionary.h | 3 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_object_unittest.cpp | 30 |
3 files changed, 44 insertions, 0 deletions
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp index 7ef5a53551..54aafd43b1 100644 --- a/core/fpdfapi/parser/cpdf_dictionary.cpp +++ b/core/fpdfapi/parser/cpdf_dictionary.cpp @@ -192,6 +192,17 @@ void CPDF_Dictionary::SetFor(const CFX_ByteString& key, CPDF_Object* pObj) { m_Map.erase(it); } +void CPDF_Dictionary::ConvertToIndirectObjectFor( + const CFX_ByteString& key, + CPDF_IndirectObjectHolder* pHolder) { + auto it = m_Map.find(key); + if (it == m_Map.end() || it->second->IsReference()) + return; + + uint32_t objnum = pHolder->AddIndirectObject(it->second); + it->second = new CPDF_Reference(pHolder, objnum); +} + void CPDF_Dictionary::RemoveFor(const CFX_ByteString& key) { auto it = m_Map.find(key); if (it == m_Map.end()) diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h index 23f2e0e3ca..b56e40a6ef 100644 --- a/core/fpdfapi/parser/cpdf_dictionary.h +++ b/core/fpdfapi/parser/cpdf_dictionary.h @@ -70,6 +70,9 @@ class CPDF_Dictionary : public CPDF_Object { void SetMatrixFor(const CFX_ByteString& key, const CFX_Matrix& matrix); void SetBooleanFor(const CFX_ByteString& key, bool bValue); + void ConvertToIndirectObjectFor(const CFX_ByteString& key, + CPDF_IndirectObjectHolder* pHolder); + // Invalidates iterators for the element with the key |key|. void RemoveFor(const CFX_ByteString& key); diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp index b2177afd8a..502d2a06d2 100644 --- a/core/fpdfapi/parser/cpdf_object_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp @@ -766,6 +766,21 @@ TEST(PDFArrayTest, CloneDirectObject) { EXPECT_FALSE(cloned_obj); } +TEST(PDFArrayTest, ConvertIndirect) { + CPDF_IndirectObjectHolder objects_holder; + ScopedArray array(new CPDF_Array); + CPDF_Object* pObj = new CPDF_Number(42); + array->Add(pObj); + array->ConvertToIndirectObjectAt(0, &objects_holder); + CPDF_Object* pRef = array->GetObjectAt(0); + CPDF_Object* pNum = array->GetDirectObjectAt(0); + EXPECT_TRUE(pRef->IsReference()); + EXPECT_TRUE(pNum->IsNumber()); + EXPECT_NE(pObj, pRef); + EXPECT_EQ(pObj, pNum); + EXPECT_EQ(42, array->GetIntegerAt(0)); +} + TEST(PDFDictionaryTest, CloneDirectObject) { CPDF_IndirectObjectHolder objects_holder; ScopedDict dict(new CPDF_Dictionary()); @@ -833,3 +848,18 @@ TEST(PDFObjectTest, CloneCheckLoop) { EXPECT_EQ(nullptr, cloned_arr->AsArray()->GetObjectAt(0)); } } + +TEST(PDFDictionaryTest, ConvertIndirect) { + CPDF_IndirectObjectHolder objects_holder; + ScopedDict dict(new CPDF_Dictionary); + CPDF_Object* pObj = new CPDF_Number(42); + dict->SetFor("clams", pObj); + dict->ConvertToIndirectObjectFor("clams", &objects_holder); + CPDF_Object* pRef = dict->GetObjectFor("clams"); + CPDF_Object* pNum = dict->GetDirectObjectFor("clams"); + EXPECT_TRUE(pRef->IsReference()); + EXPECT_TRUE(pNum->IsNumber()); + EXPECT_NE(pObj, pRef); + EXPECT_EQ(pObj, pNum); + EXPECT_EQ(42, dict->GetIntegerFor("clams")); +} |