diff options
author | tsepez <tsepez@chromium.org> | 2016-11-21 16:22:10 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-21 16:22:10 -0800 |
commit | 06104a8abc71ecd824d6a461b6f6f31c32fd2135 (patch) | |
tree | 713f7dfacbdaec5e0ac25e8fe1d197a27453a725 /core/fpdfapi/parser | |
parent | dc7ec035a6962b788e75f4beaa4cf8fbddd83d39 (diff) | |
download | pdfium-06104a8abc71ecd824d6a461b6f6f31c32fd2135.tar.xz |
Remove some WrapUnique() calls by returing unique_ptrs
Return these from underlying methods as appropriate.
Review-Url: https://codereview.chromium.org/2520133002
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.cpp | 39 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_parser.cpp | 17 |
2 files changed, 32 insertions, 24 deletions
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<CPDF_Array> pWidths) { if (bold && italic) basefont += ",BoldItalic"; else if (bold) @@ -310,23 +310,24 @@ void ProcessNonbCJK(CPDF_Dictionary* pBaseDict, pBaseDict->SetNewFor<CPDF_Name>("BaseFont", basefont); pBaseDict->SetNewFor<CPDF_Number>("FirstChar", 32); pBaseDict->SetNewFor<CPDF_Number>("LastChar", 255); - pBaseDict->SetFor("Widths", pdfium::WrapUnique(pWidths)); + pBaseDict->SetFor("Widths", std::move(pWidths)); } -std::unique_ptr<CPDF_Dictionary> CalculateFontDesc(CPDF_Document* pDoc, - CFX_ByteString basefont, - int flags, - int italicangle, - int ascend, - int descend, - CPDF_Array* bbox, - int32_t stemV) { +std::unique_ptr<CPDF_Dictionary> CalculateFontDesc( + CPDF_Document* pDoc, + CFX_ByteString basefont, + int flags, + int italicangle, + int ascend, + int descend, + std::unique_ptr<CPDF_Array> bbox, + int32_t stemV) { auto pFontDesc = pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); pFontDesc->SetNewFor<CPDF_Name>("Type", "FontDescriptor"); pFontDesc->SetNewFor<CPDF_Name>("FontName", basefont); pFontDesc->SetNewFor<CPDF_Number>("Flags", flags); - pFontDesc->SetFor("FontBBox", pdfium::WrapUnique(bbox)); + pFontDesc->SetFor("FontBBox", std::move(bbox)); pFontDesc->SetNewFor<CPDF_Number>("ItalicAngle", italicangle); pFontDesc->SetNewFor<CPDF_Number>("Ascent", ascend); pFontDesc->SetNewFor<CPDF_Number>("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<CPDF_Array>(); 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<CPDF_Array>(); pBBox->AddNew<CPDF_Number>(bbox.left); pBBox->AddNew<CPDF_Number>(bbox.bottom); pBBox->AddNew<CPDF_Number>(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<CPDF_Reference>("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<CPDF_Array>(); for (size_t i = 0; i < 224; i++) pWidths->AddNew<CPDF_Number>(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<CPDF_Array>(); for (int i = 0; i < 4; i++) pBBox->AddNew<CPDF_Number>(bbox[i]); std::unique_ptr<CPDF_Dictionary> pFontDesc = CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, - pBBox, pLogFont->lfWeight / 5); + std::move(pBBox), pLogFont->lfWeight / 5); pFontDesc->SetNewFor<CPDF_Number>("CapHeight", capheight); pFontDict->SetNewFor<CPDF_Reference>( "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<CPDF_Object> pNewObj = + ParseIndirectObject(nullptr, pRef->GetRefObjNum()); + pID = pNewObj.get(); + m_pTrailer->SetFor("ID", std::move(pNewObj)); return ToArray(pID); } |