diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-04-26 13:50:33 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-26 21:25:42 +0000 |
commit | 827db14d7f3d0085253b686587717361ffbcad1b (patch) | |
tree | dd2039623b87ba0c40b48f9a0344a463b1f3fb53 /core/fpdfapi | |
parent | e47e0c96009b8633294eebbb9eb0e84caf525c57 (diff) | |
download | pdfium-827db14d7f3d0085253b686587717361ffbcad1b.tar.xz |
Remove a few more |new|s.
Change-Id: I8a50ed680c1e101f855644fca8d282dd21470577
Reviewed-on: https://pdfium-review.googlesource.com/4533
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/font/cpdf_type3char.cpp | 6 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_type3char.h | 3 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_type3font.cpp | 7 | ||||
-rw-r--r-- | core/fpdfapi/font/ttgsubtable.cpp | 26 | ||||
-rw-r--r-- | core/fpdfapi/font/ttgsubtable.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_form.cpp | 6 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_page.cpp | 10 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_pageobjectholder.cpp | 20 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_pageobjectholder.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 24 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.cpp | 8 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.cpp | 3 |
12 files changed, 60 insertions, 57 deletions
diff --git a/core/fpdfapi/font/cpdf_type3char.cpp b/core/fpdfapi/font/cpdf_type3char.cpp index 4f116a1afb..8ac062568d 100644 --- a/core/fpdfapi/font/cpdf_type3char.cpp +++ b/core/fpdfapi/font/cpdf_type3char.cpp @@ -6,14 +6,16 @@ #include "core/fpdfapi/font/cpdf_type3char.h" +#include <utility> + #include "core/fpdfapi/page/cpdf_form.h" #include "core/fpdfapi/page/cpdf_image.h" #include "core/fpdfapi/page/cpdf_imageobject.h" #include "core/fpdfapi/page/cpdf_pageobject.h" #include "core/fxge/fx_dib.h" -CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) - : m_pForm(pForm), m_bColored(false) {} +CPDF_Type3Char::CPDF_Type3Char(std::unique_ptr<CPDF_Form> pForm) + : m_pForm(std::move(pForm)), m_bColored(false) {} CPDF_Type3Char::~CPDF_Type3Char() {} diff --git a/core/fpdfapi/font/cpdf_type3char.h b/core/fpdfapi/font/cpdf_type3char.h index 3215802e0c..18c564150c 100644 --- a/core/fpdfapi/font/cpdf_type3char.h +++ b/core/fpdfapi/font/cpdf_type3char.h @@ -18,8 +18,7 @@ class CPDF_RenderContext; class CPDF_Type3Char { public: - // Takes ownership of |pForm|. - explicit CPDF_Type3Char(CPDF_Form* pForm); + explicit CPDF_Type3Char(std::unique_ptr<CPDF_Form> pForm); ~CPDF_Type3Char(); bool LoadBitmap(CPDF_RenderContext* pContext); diff --git a/core/fpdfapi/font/cpdf_type3font.cpp b/core/fpdfapi/font/cpdf_type3font.cpp index da3b183c13..79f6617ce3 100644 --- a/core/fpdfapi/font/cpdf_type3font.cpp +++ b/core/fpdfapi/font/cpdf_type3font.cpp @@ -105,9 +105,10 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(uint32_t charcode) { if (!pStream) return nullptr; - auto pNewChar = pdfium::MakeUnique<CPDF_Type3Char>(new CPDF_Form( - m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources, - pStream, nullptr)); + auto pNewChar = + pdfium::MakeUnique<CPDF_Type3Char>(pdfium::MakeUnique<CPDF_Form>( + m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources, + pStream, nullptr)); // This can trigger recursion into this method. The content of |m_CacheMap| // can change as a result. Thus after it returns, check the cache again for diff --git a/core/fpdfapi/font/ttgsubtable.cpp b/core/fpdfapi/font/ttgsubtable.cpp index d2a6b9ab52..5b3d4cd4b9 100644 --- a/core/fpdfapi/font/ttgsubtable.cpp +++ b/core/fpdfapi/font/ttgsubtable.cpp @@ -6,6 +6,8 @@ #include "core/fpdfapi/font/ttgsubtable.h" +#include <utility> + #include "core/fxge/fx_freetype.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" @@ -298,19 +300,21 @@ void CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw, TLookup* rec) { ParseSingleSubst(&raw[GetUInt16(sp)], &subTable); } -CFX_CTTGSUBTable::TCoverageFormatBase* CFX_CTTGSUBTable::ParseCoverage( - FT_Bytes raw) { +std::unique_ptr<CFX_CTTGSUBTable::TCoverageFormatBase> +CFX_CTTGSUBTable::ParseCoverage(FT_Bytes raw) { FT_Bytes sp = raw; uint16_t format = GetUInt16(sp); - TCoverageFormatBase* rec = nullptr; if (format == 1) { - rec = new TCoverageFormat1(); - ParseCoverageFormat1(raw, static_cast<TCoverageFormat1*>(rec)); - } else if (format == 2) { - rec = new TCoverageFormat2(); - ParseCoverageFormat2(raw, static_cast<TCoverageFormat2*>(rec)); + auto rec = pdfium::MakeUnique<TCoverageFormat1>(); + ParseCoverageFormat1(raw, rec.get()); + return std::move(rec); + } + if (format == 2) { + auto rec = pdfium::MakeUnique<TCoverageFormat2>(); + ParseCoverageFormat2(raw, rec.get()); + return std::move(rec); } - return rec; + return nullptr; } void CFX_CTTGSUBTable::ParseCoverageFormat1(FT_Bytes raw, @@ -357,7 +361,7 @@ void CFX_CTTGSUBTable::ParseSingleSubstFormat1(FT_Bytes raw, FT_Bytes sp = raw; GetUInt16(sp); uint16_t offset = GetUInt16(sp); - rec->Coverage.reset(ParseCoverage(&raw[offset])); + rec->Coverage = ParseCoverage(&raw[offset]); rec->DeltaGlyphID = GetInt16(sp); } @@ -366,7 +370,7 @@ void CFX_CTTGSUBTable::ParseSingleSubstFormat2(FT_Bytes raw, FT_Bytes sp = raw; (void)GetUInt16(sp); uint16_t offset = GetUInt16(sp); - rec->Coverage.reset(ParseCoverage(&raw[offset])); + rec->Coverage = ParseCoverage(&raw[offset]); rec->Substitutes = std::vector<uint16_t>(GetUInt16(sp)); for (auto& substitute : rec->Substitutes) substitute = GetUInt16(sp); diff --git a/core/fpdfapi/font/ttgsubtable.h b/core/fpdfapi/font/ttgsubtable.h index f927269540..4b937f0473 100644 --- a/core/fpdfapi/font/ttgsubtable.h +++ b/core/fpdfapi/font/ttgsubtable.h @@ -278,7 +278,7 @@ class CFX_CTTGSUBTable { void ParseFeature(FT_Bytes raw, TFeature* rec); void ParseLookupList(FT_Bytes raw, TLookupList* rec); void ParseLookup(FT_Bytes raw, TLookup* rec); - TCoverageFormatBase* ParseCoverage(FT_Bytes raw); + std::unique_ptr<TCoverageFormatBase> ParseCoverage(FT_Bytes raw); void ParseCoverageFormat1(FT_Bytes raw, TCoverageFormat1* rec); void ParseCoverageFormat2(FT_Bytes raw, TCoverageFormat2* rec); void ParseSingleSubst(FT_Bytes raw, std::unique_ptr<TSubTableBase>* rec); diff --git a/core/fpdfapi/page/cpdf_form.cpp b/core/fpdfapi/page/cpdf_form.cpp index b3f2b372e3..2245f934f6 100644 --- a/core/fpdfapi/page/cpdf_form.cpp +++ b/core/fpdfapi/page/cpdf_form.cpp @@ -17,10 +17,10 @@ CPDF_Form::CPDF_Form(CPDF_Document* pDoc, CPDF_Dictionary* pPageResources, CPDF_Stream* pFormStream, - CPDF_Dictionary* pParentResources) { - m_pDocument = pDoc; + CPDF_Dictionary* pParentResources) + : CPDF_PageObjectHolder(pDoc, + pFormStream ? pFormStream->GetDict() : nullptr) { m_pFormStream = pFormStream; - m_pFormDict = pFormStream ? pFormStream->GetDict() : nullptr; m_pResources = m_pFormDict->GetDictFor("Resources"); m_pPageResources = pPageResources; if (!m_pResources) diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp index 314b8acbaa..496ed7cc58 100644 --- a/core/fpdfapi/page/cpdf_page.cpp +++ b/core/fpdfapi/page/cpdf_page.cpp @@ -23,12 +23,12 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument, CPDF_Dictionary* pPageDict, bool bPageCache) - : m_PageWidth(100), + : CPDF_PageObjectHolder(pDocument, pPageDict), + m_PageWidth(100), m_PageHeight(100), - m_pView(nullptr), - m_pPageRender(bPageCache ? new CPDF_PageRenderCache(this) : nullptr) { - m_pFormDict = pPageDict; - m_pDocument = pDocument; + m_pView(nullptr) { + if (bPageCache) + m_pPageRender = pdfium::MakeUnique<CPDF_PageRenderCache>(this); if (!pPageDict) return; diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/core/fpdfapi/page/cpdf_pageobjectholder.cpp index 5f5597e5ac..1d2b51e959 100644 --- a/core/fpdfapi/page/cpdf_pageobjectholder.cpp +++ b/core/fpdfapi/page/cpdf_pageobjectholder.cpp @@ -13,10 +13,11 @@ #include "core/fpdfapi/page/pageint.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" -CPDF_PageObjectHolder::CPDF_PageObjectHolder() - : m_pFormDict(nullptr), +CPDF_PageObjectHolder::CPDF_PageObjectHolder(CPDF_Document* pDoc, + CPDF_Dictionary* pFormDict) + : m_pFormDict(pFormDict), m_pFormStream(nullptr), - m_pDocument(nullptr), + m_pDocument(pDoc), m_pPageResources(nullptr), m_pResources(nullptr), m_Transparency(0), @@ -26,14 +27,15 @@ CPDF_PageObjectHolder::CPDF_PageObjectHolder() CPDF_PageObjectHolder::~CPDF_PageObjectHolder() {} void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) { - if (!m_pParser) { + if (!m_pParser) return; - } + m_pParser->Continue(pPause); - if (m_pParser->GetStatus() == CPDF_ContentParser::Done) { - m_ParseState = CONTENT_PARSED; - m_pParser.reset(); - } + if (m_pParser->GetStatus() != CPDF_ContentParser::Done) + return; + + m_ParseState = CONTENT_PARSED; + m_pParser.reset(); } void CPDF_PageObjectHolder::AddImageMaskBoundingBox(const CFX_FloatRect& box) { diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.h b/core/fpdfapi/page/cpdf_pageobjectholder.h index 0b88a86518..f5b60fff9d 100644 --- a/core/fpdfapi/page/cpdf_pageobjectholder.h +++ b/core/fpdfapi/page/cpdf_pageobjectholder.h @@ -26,7 +26,7 @@ class CPDF_ContentParser; class CPDF_PageObjectHolder { public: - CPDF_PageObjectHolder(); + CPDF_PageObjectHolder(CPDF_Document* pDoc, CPDF_Dictionary* pFormDict); virtual ~CPDF_PageObjectHolder(); void ContinueParse(IFX_Pause* pPause); diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index d9f12f121b..3e6e75a53e 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -1319,31 +1319,27 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning() { } return; } - CFX_ByteString* pStrs = new CFX_ByteString[nsegs]; - float* pKerning = FX_Alloc(float, nsegs); + std::vector<CFX_ByteString> strs(nsegs); + std::vector<float> kernings(nsegs); size_t iSegment = 0; float fInitKerning = 0; for (size_t i = 0; i < n; i++) { CPDF_Object* pObj = pArray->GetDirectObjectAt(i); if (pObj->IsString()) { CFX_ByteString str = pObj->GetString(); - if (str.IsEmpty()) { + if (str.IsEmpty()) continue; - } - pStrs[iSegment] = str; - pKerning[iSegment++] = 0; + strs[iSegment] = str; + kernings[iSegment++] = 0; } else { - float num = pObj ? pObj->GetNumber() : 0; - if (iSegment == 0) { + float num = pObj->GetNumber(); + if (iSegment == 0) fInitKerning += num; - } else { - pKerning[iSegment - 1] += num; - } + else + kernings[iSegment - 1] += num; } } - AddTextObject(pStrs, fInitKerning, pKerning, iSegment); - delete[] pStrs; - FX_Free(pKerning); + AddTextObject(strs.data(), fInitKerning, kernings.data(), iSegment); } void CPDF_StreamContentParser::Handle_SetTextLeading() { diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 41a3f0dae2..3195821279 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -645,10 +645,10 @@ bool CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); - std::unique_ptr<CPDF_HintTables> pHintTables( - new CPDF_HintTables(this, m_pLinearized.get())); - std::unique_ptr<CPDF_Object> pHintStream( - ParseIndirectObjectAt(szHintStart, 0)); + auto pHintTables = + pdfium::MakeUnique<CPDF_HintTables>(this, m_pLinearized.get()); + std::unique_ptr<CPDF_Object> pHintStream = + ParseIndirectObjectAt(szHintStart, 0); CPDF_Stream* pStream = ToStream(pHintStream.get()); if (pStream && pHintTables->LoadHintStream(pStream)) m_pHintTables = std::move(pHintTables); diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 48791262ea..73d3081a9f 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -887,8 +887,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(); pBaseDict->SetNewFor<CPDF_Name>("Type", "Font"); - std::unique_ptr<CFX_UnicodeEncoding> pEncoding( - new CFX_UnicodeEncoding(pFont)); + auto pEncoding = pdfium::MakeUnique<CFX_UnicodeEncoding>(pFont); CPDF_Dictionary* pFontDict = pBaseDict; if (!bCJK) { auto pWidths = pdfium::MakeUnique<CPDF_Array>(); |