From 06104a8abc71ecd824d6a461b6f6f31c32fd2135 Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 21 Nov 2016 16:22:10 -0800 Subject: Remove some WrapUnique() calls by returing unique_ptrs Return these from underlying methods as appropriate. Review-Url: https://codereview.chromium.org/2520133002 --- core/fpdfapi/parser/cpdf_document.cpp | 39 ++++++++++++++++++----------------- core/fpdfapi/parser/cpdf_parser.cpp | 17 ++++++++++----- 2 files changed, 32 insertions(+), 24 deletions(-) (limited to 'core/fpdfapi/parser') diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 97f55f872d..207071c69c 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -299,7 +299,7 @@ void ProcessNonbCJK(CPDF_Dictionary* pBaseDict, bool bold, bool italic, CFX_ByteString basefont, - CPDF_Array* pWidths) { + std::unique_ptr pWidths) { if (bold && italic) basefont += ",BoldItalic"; else if (bold) @@ -310,23 +310,24 @@ void ProcessNonbCJK(CPDF_Dictionary* pBaseDict, pBaseDict->SetNewFor("BaseFont", basefont); pBaseDict->SetNewFor("FirstChar", 32); pBaseDict->SetNewFor("LastChar", 255); - pBaseDict->SetFor("Widths", pdfium::WrapUnique(pWidths)); + pBaseDict->SetFor("Widths", std::move(pWidths)); } -std::unique_ptr CalculateFontDesc(CPDF_Document* pDoc, - CFX_ByteString basefont, - int flags, - int italicangle, - int ascend, - int descend, - CPDF_Array* bbox, - int32_t stemV) { +std::unique_ptr CalculateFontDesc( + CPDF_Document* pDoc, + CFX_ByteString basefont, + int flags, + int italicangle, + int ascend, + int descend, + std::unique_ptr bbox, + int32_t stemV) { auto pFontDesc = pdfium::MakeUnique(pDoc->GetByteStringPool()); pFontDesc->SetNewFor("Type", "FontDescriptor"); pFontDesc->SetNewFor("FontName", basefont); pFontDesc->SetNewFor("Flags", flags); - pFontDesc->SetFor("FontBBox", pdfium::WrapUnique(bbox)); + pFontDesc->SetFor("FontBBox", std::move(bbox)); pFontDesc->SetNewFor("ItalicAngle", italicangle); pFontDesc->SetNewFor("Ascent", ascend); pFontDesc->SetNewFor("Descent", descend); @@ -883,7 +884,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { new CFX_UnicodeEncoding(pFont)); CPDF_Dictionary* pFontDict = pBaseDict; if (!bCJK) { - CPDF_Array* pWidths = new CPDF_Array; + auto pWidths = pdfium::MakeUnique(); for (int charcode = 32; charcode < 128; charcode++) { int glyph_index = pEncoding->GlyphFromCharCode(charcode); int char_width = pFont->GetGlyphWidth(glyph_index); @@ -909,7 +910,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { } } ProcessNonbCJK(pBaseDict, pFont->IsBold(), pFont->IsItalic(), basefont, - pWidths); + std::move(pWidths)); } else { pFontDict = ProcessbCJK(pBaseDict, charset, bVert, basefont, [pFont, &pEncoding](FX_WCHAR start, FX_WCHAR end, @@ -922,7 +923,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0; FX_RECT bbox; pFont->GetBBox(bbox); - CPDF_Array* pBBox = new CPDF_Array; + auto pBBox = pdfium::MakeUnique(); pBBox->AddNew(bbox.left); pBBox->AddNew(bbox.bottom); pBBox->AddNew(bbox.right); @@ -944,7 +945,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { } CPDF_Dictionary* pFontDesc = ToDictionary(AddIndirectObject( CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(), - pFont->GetDescent(), pBBox, nStemV))); + pFont->GetDescent(), std::move(pBBox), nStemV))); pFontDict->SetNewFor("FontDescriptor", this, pFontDesc->GetObjNum()); return LoadFont(pBaseDict); @@ -1021,11 +1022,11 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, } int char_widths[224]; GetCharWidth(hDC, 32, 255, char_widths); - CPDF_Array* pWidths = new CPDF_Array; + auto pWidths = pdfium::MakeUnique(); for (size_t i = 0; i < 224; i++) pWidths->AddNew(char_widths[i]); ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, - pLogFont->lfItalic != 0, basefont, pWidths); + pLogFont->lfItalic != 0, basefont, std::move(pWidths)); } else { pFontDict = ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, @@ -1033,12 +1034,12 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, InsertWidthArray(hDC, start, end, widthArr); }); } - CPDF_Array* pBBox = new CPDF_Array; + auto pBBox = pdfium::MakeUnique(); for (int i = 0; i < 4; i++) pBBox->AddNew(bbox[i]); std::unique_ptr pFontDesc = CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, - pBBox, pLogFont->lfWeight / 5); + std::move(pBBox), pLogFont->lfWeight / 5); pFontDesc->SetNewFor("CapHeight", capheight); pFontDict->SetNewFor( "FontDescriptor", this, diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index 5354417eda..2f432ed9f9 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp @@ -1070,14 +1070,21 @@ bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) { } CPDF_Array* CPDF_Parser::GetIDArray() { - CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetObjectFor("ID") : nullptr; + if (!m_pTrailer) + return nullptr; + + CPDF_Object* pID = m_pTrailer->GetObjectFor("ID"); if (!pID) return nullptr; - if (CPDF_Reference* pRef = pID->AsReference()) { - pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()).release(); - m_pTrailer->SetFor("ID", pdfium::WrapUnique(pID)); - } + CPDF_Reference* pRef = pID->AsReference(); + if (!pRef) + return ToArray(pID); + + std::unique_ptr pNewObj = + ParseIndirectObject(nullptr, pRef->GetRefObjNum()); + pID = pNewObj.get(); + m_pTrailer->SetFor("ID", std::move(pNewObj)); return ToArray(pID); } -- cgit v1.2.3