From 827db14d7f3d0085253b686587717361ffbcad1b Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 26 Apr 2017 13:50:33 -0700 Subject: Remove a few more |new|s. Change-Id: I8a50ed680c1e101f855644fca8d282dd21470577 Reviewed-on: https://pdfium-review.googlesource.com/4533 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- core/fpdfapi/font/cpdf_type3char.cpp | 6 ++++-- core/fpdfapi/font/cpdf_type3char.h | 3 +-- core/fpdfapi/font/cpdf_type3font.cpp | 7 ++++--- core/fpdfapi/font/ttgsubtable.cpp | 26 +++++++++++++++----------- core/fpdfapi/font/ttgsubtable.h | 2 +- 5 files changed, 25 insertions(+), 19 deletions(-) (limited to 'core/fpdfapi/font') 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 + #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 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 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(new CPDF_Form( - m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources, - pStream, nullptr)); + auto pNewChar = + pdfium::MakeUnique(pdfium::MakeUnique( + 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 + #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::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(rec)); - } else if (format == 2) { - rec = new TCoverageFormat2(); - ParseCoverageFormat2(raw, static_cast(rec)); + auto rec = pdfium::MakeUnique(); + ParseCoverageFormat1(raw, rec.get()); + return std::move(rec); + } + if (format == 2) { + auto rec = pdfium::MakeUnique(); + 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(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 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* rec); -- cgit v1.2.3