diff options
author | tsepez <tsepez@chromium.org> | 2016-11-15 11:33:44 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-15 11:33:44 -0800 |
commit | 70c4afd5c3c5c44cd24f814423a23a6ef05bba02 (patch) | |
tree | cbe593d0b6c0bfc6fd5038bf60a77a94e49c69c9 /core/fpdfdoc/cpvt_generateap.cpp | |
parent | f16f6b8b52277348f5d571b7641bb0bbd5239589 (diff) | |
download | pdfium-70c4afd5c3c5c44cd24f814423a23a6ef05bba02.tar.xz |
Make AddIndirectObject() take a unique_ptr.
Add convenience routines to create and add object in
one step.
Review-Url: https://codereview.chromium.org/2489283003
Diffstat (limited to 'core/fpdfdoc/cpvt_generateap.cpp')
-rw-r--r-- | core/fpdfdoc/cpvt_generateap.cpp | 42 |
1 files changed, 16 insertions, 26 deletions
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<CPDF_Dictionary>(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<CPDF_Dictionary>(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<CPDF_Stream>(); - // Ownership passes to AddIndirectObject(). - pNormalStream = pNewNormalStream.release(); - pAPDict->SetReferenceFor("N", pDoc, pDoc->AddIndirectObject(pNormalStream)); + pNormalStream = pDoc->NewIndirect<CPDF_Stream>(); + 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<CPDF_Dictionary> GenerateExtGStateDict( std::unique_ptr<CPDF_Dictionary> GenerateResourceFontDict( CPDF_Document* pDoc, const CFX_ByteString& sFontDictName) { - auto pFontDict = - pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); + CPDF_Dictionary* pFontDict = + pDoc->NewIndirect<CPDF_Dictionary>(pDoc->GetByteStringPool()); pFontDict->SetNameFor("Type", "Font"); pFontDict->SetNameFor("Subtype", "Type1"); pFontDict->SetNameFor("BaseFont", "Helvetica"); @@ -589,8 +581,7 @@ std::unique_ptr<CPDF_Dictionary> GenerateResourceFontDict( auto pResourceFontDict = pdfium::MakeUnique<CPDF_Dictionary>(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<CPDF_Dictionary> pResourceDict, bool bIsTextMarkupAnnotation) { - auto pNormalStream = pdfium::MakeUnique<CPDF_Stream>(); + CPDF_Stream* pNormalStream = pDoc->NewIndirect<CPDF_Stream>(); pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize()); - CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); auto pAPDict = pdfium::MakeUnique<CPDF_Dictionary>(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()); |