From 70c4afd5c3c5c44cd24f814423a23a6ef05bba02 Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 15 Nov 2016 11:33:44 -0800 Subject: Make AddIndirectObject() take a unique_ptr. Add convenience routines to create and add object in one step. Review-Url: https://codereview.chromium.org/2489283003 --- core/fpdfdoc/cpvt_generateap.cpp | 42 +++++++++++++++------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'core/fpdfdoc/cpvt_generateap.cpp') diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index 0802e907fd..c8bba64b1e 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -61,16 +61,12 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(sFontName.Mid(1)); if (!pFontDict) { - auto pNewFontDict = - pdfium::MakeUnique(pDoc->GetByteStringPool()); - pNewFontDict->SetNameFor("Type", "Font"); - pNewFontDict->SetNameFor("Subtype", "Type1"); - pNewFontDict->SetNameFor("BaseFont", "Helvetica"); - pNewFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); - // Ownership passes to AddIndirectObject(). - pFontDict = pNewFontDict.release(); - pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, - pDoc->AddIndirectObject(pFontDict)); + pFontDict = pDoc->NewIndirect(pDoc->GetByteStringPool()); + pFontDict->SetNameFor("Type", "Font"); + pFontDict->SetNameFor("Subtype", "Type1"); + pFontDict->SetNameFor("BaseFont", "Helvetica"); + pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); + pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, pFontDict); } CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); if (!pDefFont) @@ -177,10 +173,8 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, } CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N"); if (!pNormalStream) { - auto pNewNormalStream = pdfium::MakeUnique(); - // Ownership passes to AddIndirectObject(). - pNormalStream = pNewNormalStream.release(); - pAPDict->SetReferenceFor("N", pDoc, pDoc->AddIndirectObject(pNormalStream)); + pNormalStream = pDoc->NewIndirect(); + pAPDict->SetReferenceFor("N", pDoc, pNormalStream); } CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); if (pStreamDict) { @@ -197,8 +191,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, pStreamResList->SetFor("Font", pStreamResFontList); } if (!pStreamResFontList->KeyExist(sFontName)) - pStreamResFontList->SetReferenceFor(sFontName, pDoc, - pFontDict->GetObjNum()); + pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict); } else { pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone().release()); @@ -452,8 +445,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, pStreamResList->SetFor("Font", pStreamResFontList); } if (!pStreamResFontList->KeyExist(sFontName)) - pStreamResFontList->SetReferenceFor(sFontName, pDoc, - pFontDict->GetObjNum()); + pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict); } else { pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone().release()); @@ -580,8 +572,8 @@ std::unique_ptr GenerateExtGStateDict( std::unique_ptr GenerateResourceFontDict( CPDF_Document* pDoc, const CFX_ByteString& sFontDictName) { - auto pFontDict = - pdfium::MakeUnique(pDoc->GetByteStringPool()); + CPDF_Dictionary* pFontDict = + pDoc->NewIndirect(pDoc->GetByteStringPool()); pFontDict->SetNameFor("Type", "Font"); pFontDict->SetNameFor("Subtype", "Type1"); pFontDict->SetNameFor("BaseFont", "Helvetica"); @@ -589,8 +581,7 @@ std::unique_ptr GenerateResourceFontDict( auto pResourceFontDict = pdfium::MakeUnique(pDoc->GetByteStringPool()); - pResourceFontDict->SetReferenceFor( - sFontDictName, pDoc, pDoc->AddIndirectObject(pFontDict.release())); + pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict); return pResourceFontDict; } @@ -612,15 +603,14 @@ void GenerateAndSetAPDict(CPDF_Document* pDoc, const CFX_ByteTextBuf& sAppStream, std::unique_ptr pResourceDict, bool bIsTextMarkupAnnotation) { - auto pNormalStream = pdfium::MakeUnique(); + CPDF_Stream* pNormalStream = pDoc->NewIndirect(); pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize()); - CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); auto pAPDict = pdfium::MakeUnique(pDoc->GetByteStringPool()); - pAPDict->SetReferenceFor("N", pDoc, - pDoc->AddIndirectObject(pNormalStream.release())); + pAPDict->SetReferenceFor("N", pDoc, pNormalStream); pAnnotDict->SetFor("AP", pAPDict.release()); + CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); pStreamDict->SetIntegerFor("FormType", 1); pStreamDict->SetStringFor("Subtype", "Form"); pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); -- cgit v1.2.3