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 --- fpdfsdk/cpdfsdk_baannot.cpp | 5 ++--- fpdfsdk/formfiller/cba_fontmap.cpp | 2 +- fpdfsdk/fpdf_flatten.cpp | 9 ++++----- fpdfsdk/fpdf_transformpage.cpp | 6 +++--- fpdfsdk/fpdfsave.cpp | 4 ++-- 5 files changed, 12 insertions(+), 14 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp index e023ae79f1..2c63780772 100644 --- a/fpdfsdk/cpdfsdk_baannot.cpp +++ b/fpdfsdk/cpdfsdk_baannot.cpp @@ -320,7 +320,7 @@ void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, } if (!pStream) { - pStream = new CPDF_Stream(nullptr, 0, nullptr); + pStream = new CPDF_Stream; CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); int32_t objnum = pDoc->AddIndirectObject(pStream); pParentDict->SetReferenceFor(sAPType, pDoc, objnum); @@ -340,8 +340,7 @@ void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, pStreamDict->SetRectFor("BBox", rcBBox); } - pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE, - FALSE); + pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength()); } FX_BOOL CPDFSDK_BAAnnot::IsVisible() const { diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp index 264366bfa4..fe690f23d5 100644 --- a/fpdfsdk/formfiller/cba_fontmap.cpp +++ b/fpdfsdk/formfiller/cba_fontmap.cpp @@ -167,7 +167,7 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); if (!pStream) { - pStream = new CPDF_Stream(nullptr, 0, nullptr); + pStream = new CPDF_Stream; int32_t objnum = m_pDocument->AddIndirectObject(pStream); pAPDict->SetReferenceFor(m_sAPType, m_pDocument, objnum); } diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index de6baf1f01..aa21b280ed 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -200,8 +200,7 @@ void SetPageContents(CFX_ByteString key, CFX_ByteString sStream; sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); - pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, - FALSE); + pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); } return; } @@ -219,7 +218,7 @@ void SetPageContents(CFX_ByteString key, CFX_ByteString sBody = CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); sStream = sStream + sBody + "\nQ"; - pContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); + pContents->SetData(sStream.raw_str(), sStream.GetLength()); pContentsArray->AddReference(pDocument, dwObjNum); break; } @@ -246,7 +245,7 @@ void SetPageContents(CFX_ByteString key, CFX_ByteString sStream; sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); - pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); + pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); } } @@ -506,7 +505,7 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, sFormName.c_str()); sStream += sTemp; - pNewXObject->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); + pNewXObject->SetData(sStream.raw_str(), sStream.GetLength()); } pPageDict->RemoveFor("Annots"); diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index 7b2bf73871..204e49b695 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -127,7 +127,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, CPDF_Dictionary* pDic = new CPDF_Dictionary; CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); - pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE); + pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize()); CPDF_Document* pDoc = pPage->m_pDocument; if (!pDoc) return FALSE; @@ -135,7 +135,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, pDic = new CPDF_Dictionary; CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic); - pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE); + pEndStream->SetData((const uint8_t*)" Q", 2); pDoc->AddIndirectObject(pEndStream); CPDF_Array* pContentArray = nullptr; @@ -302,7 +302,7 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, } CPDF_Dictionary* pDic = new CPDF_Dictionary; CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); - pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE); + pStream->SetData(strClip.GetBuffer(), strClip.GetSize()); CPDF_Document* pDoc = pPage->m_pDocument; if (!pDoc) return; diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp index 243ba2a817..307163d1af 100644 --- a/fpdfsdk/fpdfsave.cpp +++ b/fpdfsdk/fpdfsave.cpp @@ -183,7 +183,7 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument, if (pDataSetsStream) pDataSetsStream->InitStreamFromFile(pDsfileWrite.get(), pDataDict); } else { - CPDF_Stream* pData = new CPDF_Stream(nullptr, 0, nullptr); + CPDF_Stream* pData = new CPDF_Stream; pData->InitStreamFromFile(pDsfileWrite.get(), pDataDict); pPDFDocument->AddIndirectObject(pData); iLast = pArray->GetCount() - 2; @@ -204,7 +204,7 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument, if (pFormStream) pFormStream->InitStreamFromFile(pfileWrite.get(), pDataDict); } else { - CPDF_Stream* pData = new CPDF_Stream(nullptr, 0, nullptr); + CPDF_Stream* pData = new CPDF_Stream; pData->InitStreamFromFile(pfileWrite.get(), pDataDict); pPDFDocument->AddIndirectObject(pData); iLast = pArray->GetCount() - 2; -- cgit v1.2.3