From e6db16e7e6cdc3dd213c16de0d792b77656ac7a6 Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 19 Sep 2016 10:45:09 -0700 Subject: Clean up CPDF_Stream. Replace the CPDF_Stream(nullptr, 0, nullptr) pattern with a default ctor. Remove unused parameters from CPDF_Stream::SetData(). Both are always passed as FALSE. CPDF_Stream declared its own m_GenNum, which shadowed the one in CPDF_Object. It was used only to distinguish file/memory streams, so add a bool explicitly for this purpose. Remove the union, it would be sad if we confused user data with a C++ object with virtual function calls. Use unique_ptrs with appropriate deleters to manage memory. Review-Url: https://codereview.chromium.org/2347993002 --- core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'core/fpdfapi/fpdf_edit') diff --git a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp index d3d55b91b5..7acd368683 100644 --- a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp @@ -53,8 +53,8 @@ void CPDF_PageContentGenerator::GenerateContent() { if (pContent) { pPageDict->RemoveFor("Contents"); } - CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); - pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); + CPDF_Stream* pStream = new CPDF_Stream; + pStream->SetData(buf.GetBuffer(), buf.GetLength()); m_pDocument->AddIndirectObject(pStream); pPageDict->SetReferenceFor("Contents", m_pDocument, pStream->GetObjNum()); } @@ -109,21 +109,25 @@ void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf, const uint8_t* data, uint32_t size, CFX_Matrix& matrix) { - if (!data || !size) { + if (!data || !size) return; - } - CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); + CPDF_Dictionary* pFormDict = new CPDF_Dictionary; pFormDict->SetNameFor("Type", "XObject"); pFormDict->SetNameFor("Subtype", "Form"); + CFX_FloatRect bbox = m_pPage->GetPageBBox(); matrix.TransformRect(bbox); pFormDict->SetRectFor("BBox", bbox); + + CPDF_Stream* pStream = new CPDF_Stream; pStream->InitStream(data, size, pFormDict); buf << "q " << matrix << " cm "; + CFX_ByteString name = RealizeResource(pStream, "XObject"); buf << "/" << PDF_NameEncode(name) << " Do Q\n"; } + void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { CPDF_Dictionary* pDict = m_pPage->m_pFormDict; CPDF_Object* pContent = @@ -164,8 +168,8 @@ void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { contentStream.LoadAllData(pStream); ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); } - CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); - pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); + CPDF_Stream* pStream = new CPDF_Stream; + pStream->SetData(buf.GetBuffer(), buf.GetLength()); m_pDocument->AddIndirectObject(pStream); m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, pStream->GetObjNum()); -- cgit v1.2.3