diff options
Diffstat (limited to 'core/fpdfapi/edit')
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 25 | ||||
-rw-r--r-- | core/fpdfapi/edit/fpdf_edit_create.cpp | 20 |
2 files changed, 26 insertions, 19 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index 80450a8025..837697273f 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -16,6 +16,8 @@ #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/parser/cpdf_name.h" +#include "core/fpdfapi/parser/cpdf_reference.h" #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "core/fpdfapi/parser/fpdf_parser_decode.h" @@ -54,7 +56,8 @@ void CPDF_PageContentGenerator::GenerateContent() { CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); pStream->SetData(buf.GetBuffer(), buf.GetLength()); - pPageDict->SetReferenceFor("Contents", m_pDocument, pStream); + pPageDict->SetNewFor<CPDF_Reference>("Contents", m_pDocument, + pStream->GetObjNum()); } CFX_ByteString CPDF_PageContentGenerator::RealizeResource( @@ -63,14 +66,13 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource( ASSERT(dwResourceObjNum); if (!m_pPage->m_pResources) { m_pPage->m_pResources = m_pDocument->NewIndirect<CPDF_Dictionary>(); - m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, - m_pPage->m_pResources); + m_pPage->m_pFormDict->SetNewFor<CPDF_Reference>( + "Resources", m_pDocument, m_pPage->m_pResources->GetObjNum()); } CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); - if (!pResList) { - pResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); - m_pPage->m_pResources->SetFor(bsType, pResList); - } + if (!pResList) + pResList = m_pPage->m_pResources->SetNewFor<CPDF_Dictionary>(bsType); + CFX_ByteString name; int idnum = 1; while (1) { @@ -80,7 +82,7 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource( } idnum++; } - pResList->SetReferenceFor(name, m_pDocument, dwResourceObjNum); + pResList->SetNewFor<CPDF_Reference>(name, m_pDocument, dwResourceObjNum); return name; } @@ -126,8 +128,8 @@ void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf, CPDF_Dictionary* pFormDict = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); - pFormDict->SetNameFor("Type", "XObject"); - pFormDict->SetNameFor("Subtype", "Form"); + pFormDict->SetNewFor<CPDF_Name>("Type", "XObject"); + pFormDict->SetNewFor<CPDF_Name>("Subtype", "Form"); pFormDict->SetRectFor("BBox", bbox); CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); @@ -179,5 +181,6 @@ void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { } CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); pStream->SetData(buf.GetBuffer(), buf.GetLength()); - m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, pStream); + m_pPage->m_pFormDict->SetNewFor<CPDF_Reference>("Contents", m_pDocument, + pStream->GetObjNum()); } diff --git a/core/fpdfapi/edit/fpdf_edit_create.cpp b/core/fpdfapi/edit/fpdf_edit_create.cpp index 360472948d..b2e31054c0 100644 --- a/core/fpdfapi/edit/fpdf_edit_create.cpp +++ b/core/fpdfapi/edit/fpdf_edit_create.cpp @@ -13,6 +13,8 @@ #include "core/fpdfapi/parser/cpdf_crypto_handler.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/parser/cpdf_name.h" +#include "core/fpdfapi/parser/cpdf_number.h" #include "core/fpdfapi/parser/cpdf_parser.h" #include "core/fpdfapi/parser/cpdf_reference.h" #include "core/fpdfapi/parser/cpdf_security_handler.h" @@ -128,7 +130,7 @@ int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, const CPDF_Dictionary* p = pObj->AsDictionary(); for (const auto& it : *p) { const CFX_ByteString& key = it.first; - CPDF_Object* pValue = it.second; + CPDF_Object* pValue = it.second.get(); if (pFile->AppendString("/") < 0) { return -1; } @@ -197,7 +199,7 @@ int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, CPDF_Dictionary* p = pParser->GetTrailer(); for (const auto& it : *p) { const CFX_ByteString& key = it.first; - CPDF_Object* pValue = it.second; + CPDF_Object* pValue = it.second.get(); if (key == "Encrypt" || key == "Size" || key == "Filter" || key == "Index" || key == "Length" || key == "Prev" || key == "W" || key == "XRefStm" || key == "Type" || key == "ID") { @@ -440,8 +442,8 @@ CPDF_FlateEncoder::CPDF_FlateEncoder(CPDF_Stream* pStream, bool bFlateEncode) // TODO(thestig): Move to Init() and check return value. ::FlateEncode(m_Acc.GetData(), m_Acc.GetSize(), &m_pData, &m_dwSize); m_pDict = ToDictionary(pStream->GetDict()->Clone().release()); - m_pDict->SetIntegerFor("Length", m_dwSize); - m_pDict->SetNameFor("Filter", "FlateDecode"); + m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(m_dwSize)); + m_pDict->SetNewFor<CPDF_Name>("Filter", "FlateDecode"); m_pDict->RemoveFor("DecodeParms"); } @@ -993,7 +995,8 @@ int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream, if ((uint32_t)encoder.m_pDict->GetIntegerFor("Length") != encryptor.m_dwSize) { encoder.CloneDict(); - encoder.m_pDict->SetIntegerFor("Length", encryptor.m_dwSize); + encoder.m_pDict->SetNewFor<CPDF_Number>( + "Length", static_cast<int>(encryptor.m_dwSize)); } if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { return -1; @@ -1106,7 +1109,8 @@ int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum, if ((uint32_t)encoder.m_pDict->GetIntegerFor("Length") != encryptor.m_dwSize) { encoder.CloneDict(); - encoder.m_pDict->SetIntegerFor("Length", encryptor.m_dwSize); + encoder.m_pDict->SetNewFor<CPDF_Number>( + "Length", static_cast<int>(encryptor.m_dwSize)); } if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { return -1; @@ -1189,7 +1193,7 @@ int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum, for (const auto& it : *p) { bool bSignValue = false; const CFX_ByteString& key = it.first; - CPDF_Object* pValue = it.second; + CPDF_Object* pValue = it.second.get(); if (m_File.AppendString("/") < 0) { return -1; } @@ -1711,7 +1715,7 @@ int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) { CPDF_Dictionary* p = m_pParser->GetTrailer(); for (const auto& it : *p) { const CFX_ByteString& key = it.first; - CPDF_Object* pValue = it.second; + CPDF_Object* pValue = it.second.get(); // TODO(ochang): Consolidate with similar check in // PDF_CreatorWriteTrailer. if (key == "Encrypt" || key == "Size" || key == "Filter" || |