diff options
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/fpdf_font/cpdf_font.cpp | 8 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/font_int.h | 1 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/fpdf_font_cid.cpp | 15 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/include/cpdf_font.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/ttgsubtable.cpp | 160 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/ttgsubtable.h | 122 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_formobject.cpp | 8 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/include/cpdf_formobject.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render.cpp | 2 |
10 files changed, 124 insertions, 204 deletions
diff --git a/core/fpdfapi/fpdf_font/cpdf_font.cpp b/core/fpdfapi/fpdf_font/cpdf_font.cpp index 061b477f17..07a79ed607 100644 --- a/core/fpdfapi/fpdf_font/cpdf_font.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_font.cpp @@ -6,8 +6,6 @@ #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" -#include <memory> - #include "core/fpdfapi/fpdf_font/cpdf_truetypefont.h" #include "core/fpdfapi/fpdf_font/cpdf_type1font.h" #include "core/fpdfapi/fpdf_font/cpdf_type3font.h" @@ -50,7 +48,6 @@ FX_BOOL GetPredefinedEncoding(int& basemap, const CFX_ByteString& value) { CPDF_Font::CPDF_Font() : m_pFontFile(nullptr), m_pFontDict(nullptr), - m_pToUnicodeMap(nullptr), m_bToUnicodeLoaded(FALSE), m_Flags(0), m_StemV(0), @@ -59,9 +56,6 @@ CPDF_Font::CPDF_Font() m_ItalicAngle(0) {} CPDF_Font::~CPDF_Font() { - delete m_pToUnicodeMap; - m_pToUnicodeMap = nullptr; - if (m_pFontFile) { m_pDocument->GetPageData()->ReleaseFontFileStreamAcc( const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream())); @@ -285,7 +279,7 @@ void CPDF_Font::LoadUnicodeMap() const { if (!pStream) { return; } - m_pToUnicodeMap = new CPDF_ToUnicodeMap; + m_pToUnicodeMap.reset(new CPDF_ToUnicodeMap); m_pToUnicodeMap->Load(pStream); } diff --git a/core/fpdfapi/fpdf_font/font_int.h b/core/fpdfapi/fpdf_font/font_int.h index fd2d87f5d8..e14707f997 100644 --- a/core/fpdfapi/fpdf_font/font_int.h +++ b/core/fpdfapi/fpdf_font/font_int.h @@ -169,7 +169,6 @@ class CPDF_CMap { uint8_t* m_pAddMapping; FX_BOOL m_bLoaded; const FXCMAP_CMap* m_pEmbedMap; - CPDF_CMap* m_pUseMap; }; class CPDF_CID2UnicodeMap { diff --git a/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp index 289782bfb3..f6d3bdc711 100644 --- a/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp +++ b/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp @@ -512,14 +512,12 @@ CPDF_CMap::CPDF_CMap() { m_pLeadingBytes = nullptr; m_pAddMapping = nullptr; m_pEmbedMap = nullptr; - m_pUseMap = nullptr; m_nCodeRanges = 0; } CPDF_CMap::~CPDF_CMap() { FX_Free(m_pMapping); FX_Free(m_pAddMapping); FX_Free(m_pLeadingBytes); - delete m_pUseMap; } void CPDF_CMap::Release() { if (m_PredefinedCMap.IsEmpty()) { @@ -616,23 +614,14 @@ uint16_t CPDF_CMap::CIDFromCharCode(uint32_t charcode) const { if (m_pAddMapping) { void* found = FXSYS_bsearch(&charcode, m_pAddMapping + 4, *(uint32_t*)m_pAddMapping, 8, CompareCID); - if (!found) { - if (m_pUseMap) { - return m_pUseMap->CIDFromCharCode(charcode); - } + if (!found) return 0; - } return (uint16_t)(((uint32_t*)found)[1] % 65536 + charcode - *(uint32_t*)found); } - if (m_pUseMap) - return m_pUseMap->CIDFromCharCode(charcode); return 0; } - uint32_t CID = m_pMapping[charcode]; - if (!CID && m_pUseMap) - return m_pUseMap->CIDFromCharCode(charcode); - return (uint16_t)CID; + return m_pMapping[charcode]; } uint32_t CPDF_CMap::GetNextChar(const FX_CHAR* pString, diff --git a/core/fpdfapi/fpdf_font/include/cpdf_font.h b/core/fpdfapi/fpdf_font/include/cpdf_font.h index e8a7901043..390a3137b6 100644 --- a/core/fpdfapi/fpdf_font/include/cpdf_font.h +++ b/core/fpdfapi/fpdf_font/include/cpdf_font.h @@ -7,6 +7,8 @@ #ifndef CORE_FPDFAPI_FPDF_FONT_INCLUDE_CPDF_FONT_H_ #define CORE_FPDFAPI_FPDF_FONT_INCLUDE_CPDF_FONT_H_ +#include <memory> + #include "core/fxcrt/include/fx_string.h" #include "core/fxcrt/include/fx_system.h" #include "core/fxge/include/fx_font.h" @@ -114,7 +116,7 @@ class CPDF_Font { CFX_ByteString m_BaseFont; CPDF_StreamAcc* m_pFontFile; CPDF_Dictionary* m_pFontDict; - mutable CPDF_ToUnicodeMap* m_pToUnicodeMap; + mutable std::unique_ptr<CPDF_ToUnicodeMap> m_pToUnicodeMap; mutable FX_BOOL m_bToUnicodeLoaded; int m_Flags; FX_RECT m_FontBBox; diff --git a/core/fpdfapi/fpdf_font/ttgsubtable.cpp b/core/fpdfapi/fpdf_font/ttgsubtable.cpp index 56a388203f..c5ad7cae16 100644 --- a/core/fpdfapi/fpdf_font/ttgsubtable.cpp +++ b/core/fpdfapi/fpdf_font/ttgsubtable.cpp @@ -6,8 +6,6 @@ #include "core/fpdfapi/fpdf_font/ttgsubtable.h" -#include <memory> - #include "core/fxge/include/fx_freetype.h" #include "core/fxge/include/fx_ge.h" #include "third_party/base/stl_util.h" @@ -97,16 +95,10 @@ bool CFX_CTTGSUBTable::GetVerticalGlyph(uint32_t glyphnum, }; if (!m_bFeautureMapLoad) { for (int i = 0; i < ScriptList.ScriptCount; i++) { - for (int j = 0; j < (ScriptList.ScriptRecord + i)->Script.LangSysCount; - ++j) { - for (int k = 0; - k < ((ScriptList.ScriptRecord + i)->Script.LangSysRecord + j) - ->LangSys.FeatureCount; - ++k) { - uint32_t index = - *(((ScriptList.ScriptRecord + i)->Script.LangSysRecord + j) - ->LangSys.FeatureIndex + - k); + for (int j = 0; j < ScriptList.ScriptRecord[i].Script.LangSysCount; ++j) { + const auto& record = ScriptList.ScriptRecord[i].Script.LangSysRecord[j]; + for (int k = 0; k < record.LangSys.FeatureCount; ++k) { + uint32_t index = record.LangSys.FeatureIndex[k]; if (FeatureList.FeatureRecord[index].FeatureTag == tag[0] || FeatureList.FeatureRecord[index].FeatureTag == tag[1]) { if (!pdfium::ContainsKey(m_featureMap, index)) { @@ -137,7 +129,7 @@ bool CFX_CTTGSUBTable::GetVerticalGlyph(uint32_t glyphnum, bool CFX_CTTGSUBTable::GetVerticalGlyphSub(uint32_t glyphnum, uint32_t* vglyphnum, - struct TFeature* Feature) const { + TFeature* Feature) const { for (int i = 0; i < Feature->LookupCount; i++) { int index = Feature->LookupListIndex[i]; if (index < 0 || LookupList.LookupCount < index) { @@ -155,12 +147,12 @@ bool CFX_CTTGSUBTable::GetVerticalGlyphSub(uint32_t glyphnum, bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(uint32_t glyphnum, uint32_t* vglyphnum, - struct TLookup* Lookup) const { + TLookup* Lookup) const { for (int i = 0; i < Lookup->SubTableCount; i++) { switch (Lookup->SubTable[i]->SubstFormat) { case 1: { TSingleSubstFormat1* tbl1 = (TSingleSubstFormat1*)Lookup->SubTable[i]; - if (GetCoverageIndex(tbl1->Coverage, glyphnum) >= 0) { + if (GetCoverageIndex(tbl1->Coverage.get(), glyphnum) >= 0) { *vglyphnum = glyphnum + tbl1->DeltaGlyphID; return true; } @@ -169,7 +161,7 @@ bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(uint32_t glyphnum, case 2: { TSingleSubstFormat2* tbl2 = (TSingleSubstFormat2*)Lookup->SubTable[i]; int index = -1; - index = GetCoverageIndex(tbl2->Coverage, glyphnum); + index = GetCoverageIndex(tbl2->Coverage.get(), glyphnum); if (0 <= index && index < tbl2->GlyphCount) { *vglyphnum = tbl2->Substitute[index]; return true; @@ -181,7 +173,7 @@ bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(uint32_t glyphnum, return false; } -int CFX_CTTGSUBTable::GetCoverageIndex(struct TCoverageFormatBase* Coverage, +int CFX_CTTGSUBTable::GetCoverageIndex(TCoverageFormatBase* Coverage, uint32_t g) const { int i = 0; if (!Coverage) { @@ -252,14 +244,14 @@ bool CFX_CTTGSUBTable::Parse(FT_Bytes scriptlist, return true; } -void CFX_CTTGSUBTable::ParseScriptList(FT_Bytes raw, struct TScriptList* rec) { +void CFX_CTTGSUBTable::ParseScriptList(FT_Bytes raw, TScriptList* rec) { int i; FT_Bytes sp = raw; rec->ScriptCount = GetUInt16(sp); if (rec->ScriptCount <= 0) { return; } - rec->ScriptRecord = new struct TScriptRecord[rec->ScriptCount]; + rec->ScriptRecord.reset(new TScriptRecord[rec->ScriptCount]); for (i = 0; i < rec->ScriptCount; i++) { rec->ScriptRecord[i].ScriptTag = GetUInt32(sp); uint16_t offset = GetUInt16(sp); @@ -267,7 +259,7 @@ void CFX_CTTGSUBTable::ParseScriptList(FT_Bytes raw, struct TScriptList* rec) { } } -void CFX_CTTGSUBTable::ParseScript(FT_Bytes raw, struct TScript* rec) { +void CFX_CTTGSUBTable::ParseScript(FT_Bytes raw, TScript* rec) { int i; FT_Bytes sp = raw; rec->DefaultLangSys = GetUInt16(sp); @@ -275,7 +267,7 @@ void CFX_CTTGSUBTable::ParseScript(FT_Bytes raw, struct TScript* rec) { if (rec->LangSysCount <= 0) { return; } - rec->LangSysRecord = new struct TLangSysRecord[rec->LangSysCount]; + rec->LangSysRecord.reset(new TLangSysRecord[rec->LangSysCount]); for (i = 0; i < rec->LangSysCount; i++) { rec->LangSysRecord[i].LangSysTag = GetUInt32(sp); uint16_t offset = GetUInt16(sp); @@ -283,7 +275,7 @@ void CFX_CTTGSUBTable::ParseScript(FT_Bytes raw, struct TScript* rec) { } } -void CFX_CTTGSUBTable::ParseLangSys(FT_Bytes raw, struct TLangSys* rec) { +void CFX_CTTGSUBTable::ParseLangSys(FT_Bytes raw, TLangSys* rec) { FT_Bytes sp = raw; rec->LookupOrder = GetUInt16(sp); rec->ReqFeatureIndex = GetUInt16(sp); @@ -291,8 +283,9 @@ void CFX_CTTGSUBTable::ParseLangSys(FT_Bytes raw, struct TLangSys* rec) { if (rec->FeatureCount <= 0) { return; } - rec->FeatureIndex = new uint16_t[rec->FeatureCount]; - FXSYS_memset(rec->FeatureIndex, 0, sizeof(uint16_t) * rec->FeatureCount); + rec->FeatureIndex.reset(new uint16_t[rec->FeatureCount]); + FXSYS_memset(rec->FeatureIndex.get(), 0, + sizeof(uint16_t) * rec->FeatureCount); for (int i = 0; i < rec->FeatureCount; ++i) { rec->FeatureIndex[i] = GetUInt16(sp); } @@ -305,7 +298,7 @@ void CFX_CTTGSUBTable::ParseFeatureList(FT_Bytes raw, TFeatureList* rec) { if (rec->FeatureCount <= 0) { return; } - rec->FeatureRecord = new struct TFeatureRecord[rec->FeatureCount]; + rec->FeatureRecord.reset(new TFeatureRecord[rec->FeatureCount]); for (i = 0; i < rec->FeatureCount; i++) { rec->FeatureRecord[i].FeatureTag = GetUInt32(sp); uint16_t offset = GetUInt16(sp); @@ -321,7 +314,7 @@ void CFX_CTTGSUBTable::ParseFeature(FT_Bytes raw, TFeature* rec) { if (rec->LookupCount <= 0) { return; } - rec->LookupListIndex = new uint16_t[rec->LookupCount]; + rec->LookupListIndex.reset(new uint16_t[rec->LookupCount]); for (i = 0; i < rec->LookupCount; i++) { rec->LookupListIndex[i] = GetUInt16(sp); } @@ -334,7 +327,7 @@ void CFX_CTTGSUBTable::ParseLookupList(FT_Bytes raw, TLookupList* rec) { if (rec->LookupCount <= 0) { return; } - rec->Lookup = new struct TLookup[rec->LookupCount]; + rec->Lookup.reset(new TLookup[rec->LookupCount]); for (i = 0; i < rec->LookupCount; i++) { uint16_t offset = GetUInt16(sp); ParseLookup(&raw[offset], &rec->Lookup[i]); @@ -350,7 +343,7 @@ void CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw, TLookup* rec) { if (rec->SubTableCount <= 0) { return; } - rec->SubTable = new struct TSubTableBase*[rec->SubTableCount]; + rec->SubTable.reset(new TSubTableBase*[rec->SubTableCount]); for (i = 0; i < rec->SubTableCount; i++) { rec->SubTable[i] = nullptr; } @@ -363,19 +356,19 @@ void CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw, TLookup* rec) { } } -void CFX_CTTGSUBTable::ParseCoverage(FT_Bytes raw, TCoverageFormatBase** rec) { +CFX_CTTGSUBTable::TCoverageFormatBase* CFX_CTTGSUBTable::ParseCoverage( + FT_Bytes raw) { FT_Bytes sp = raw; - uint16_t Format = GetUInt16(sp); - switch (Format) { - case 1: - *rec = new TCoverageFormat1(); - ParseCoverageFormat1(raw, (TCoverageFormat1*)*rec); - break; - case 2: - *rec = new TCoverageFormat2(); - ParseCoverageFormat2(raw, (TCoverageFormat2*)*rec); - break; + 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)); } + return rec; } void CFX_CTTGSUBTable::ParseCoverageFormat1(FT_Bytes raw, @@ -387,7 +380,7 @@ void CFX_CTTGSUBTable::ParseCoverageFormat1(FT_Bytes raw, if (rec->GlyphCount <= 0) { return; } - rec->GlyphArray = new uint16_t[rec->GlyphCount]; + rec->GlyphArray.reset(new uint16_t[rec->GlyphCount]); for (i = 0; i < rec->GlyphCount; i++) { rec->GlyphArray[i] = GetUInt16(sp); } @@ -402,7 +395,7 @@ void CFX_CTTGSUBTable::ParseCoverageFormat2(FT_Bytes raw, if (rec->RangeCount <= 0) { return; } - rec->RangeRecord = new TRangeRecord[rec->RangeCount]; + rec->RangeRecord.reset(new TRangeRecord[rec->RangeCount]); for (i = 0; i < rec->RangeCount; i++) { rec->RangeRecord[i].Start = GetUInt16(sp); rec->RangeRecord[i].End = GetUInt16(sp); @@ -430,7 +423,7 @@ void CFX_CTTGSUBTable::ParseSingleSubstFormat1(FT_Bytes raw, FT_Bytes sp = raw; GetUInt16(sp); uint16_t offset = GetUInt16(sp); - ParseCoverage(&raw[offset], &rec->Coverage); + rec->Coverage.reset(ParseCoverage(&raw[offset])); rec->DeltaGlyphID = GetInt16(sp); } @@ -440,82 +433,71 @@ void CFX_CTTGSUBTable::ParseSingleSubstFormat2(FT_Bytes raw, FT_Bytes sp = raw; GetUInt16(sp); uint16_t offset = GetUInt16(sp); - ParseCoverage(&raw[offset], &rec->Coverage); + rec->Coverage.reset(ParseCoverage(&raw[offset])); rec->GlyphCount = GetUInt16(sp); if (rec->GlyphCount <= 0) { return; } - rec->Substitute = new uint16_t[rec->GlyphCount]; + rec->Substitute.reset(new uint16_t[rec->GlyphCount]); for (i = 0; i < rec->GlyphCount; i++) { rec->Substitute[i] = GetUInt16(sp); } } CFX_CTTGSUBTable::TCoverageFormat1::TCoverageFormat1() - : GlyphCount(0), GlyphArray(nullptr) { - CoverageFormat = 1; -} + : TCoverageFormatBase(1), GlyphCount(0) {} -CFX_CTTGSUBTable::TCoverageFormat1::~TCoverageFormat1() { - delete[] GlyphArray; -} +CFX_CTTGSUBTable::TCoverageFormat1::~TCoverageFormat1() {} CFX_CTTGSUBTable::TRangeRecord::TRangeRecord() : Start(0), End(0), StartCoverageIndex(0) {} CFX_CTTGSUBTable::TCoverageFormat2::TCoverageFormat2() - : RangeCount(0), RangeRecord(nullptr) { - CoverageFormat = 2; -} + : TCoverageFormatBase(2), RangeCount(0) {} -CFX_CTTGSUBTable::TCoverageFormat2::~TCoverageFormat2() { - delete[] RangeRecord; -} - -CFX_CTTGSUBTable::TClassDefFormat1::TClassDefFormat1() - : StartGlyph(0), GlyphCount(0), ClassValueArray(nullptr) { - ClassFormat = 1; -} - -CFX_CTTGSUBTable::TClassDefFormat1::~TClassDefFormat1() { - delete[] ClassValueArray; -} - -CFX_CTTGSUBTable::TClassDefFormat2::TClassDefFormat2() - : ClassRangeCount(0), ClassRangeRecord(nullptr) { - ClassFormat = 2; -} - -CFX_CTTGSUBTable::TClassDefFormat2::~TClassDefFormat2() { - delete[] ClassRangeRecord; -} +CFX_CTTGSUBTable::TCoverageFormat2::~TCoverageFormat2() {} CFX_CTTGSUBTable::TSingleSubstFormat1::TSingleSubstFormat1() - : Coverage(nullptr), DeltaGlyphID(0) { - SubstFormat = 1; -} + : TSubTableBase(1), DeltaGlyphID(0) {} -CFX_CTTGSUBTable::TSingleSubstFormat1::~TSingleSubstFormat1() { - delete Coverage; -} +CFX_CTTGSUBTable::TSingleSubstFormat1::~TSingleSubstFormat1() {} CFX_CTTGSUBTable::TSingleSubstFormat2::TSingleSubstFormat2() - : Coverage(nullptr), GlyphCount(0), Substitute(nullptr) { - SubstFormat = 2; -} + : TSubTableBase(2), GlyphCount(0) {} -CFX_CTTGSUBTable::TSingleSubstFormat2::~TSingleSubstFormat2() { - delete Coverage; - delete[] Substitute; -} +CFX_CTTGSUBTable::TSingleSubstFormat2::~TSingleSubstFormat2() {} CFX_CTTGSUBTable::TLookup::TLookup() - : LookupType(0), LookupFlag(0), SubTableCount(0), SubTable(nullptr) {} + : LookupType(0), LookupFlag(0), SubTableCount(0) {} CFX_CTTGSUBTable::TLookup::~TLookup() { if (SubTable) { for (int i = 0; i < SubTableCount; ++i) delete SubTable[i]; - delete[] SubTable; } } + +CFX_CTTGSUBTable::TScript::TScript() : DefaultLangSys(0), LangSysCount(0) {} + +CFX_CTTGSUBTable::TScript::~TScript() {} + +CFX_CTTGSUBTable::TScriptList::TScriptList() : ScriptCount(0) {} + +CFX_CTTGSUBTable::TScriptList::~TScriptList() {} + +CFX_CTTGSUBTable::TFeature::TFeature() : FeatureParams(0), LookupCount(0) {} + +CFX_CTTGSUBTable::TFeature::~TFeature() {} + +CFX_CTTGSUBTable::TFeatureList::TFeatureList() : FeatureCount(0) {} + +CFX_CTTGSUBTable::TFeatureList::~TFeatureList() {} + +CFX_CTTGSUBTable::TLookupList::TLookupList() : LookupCount(0) {} + +CFX_CTTGSUBTable::TLookupList::~TLookupList() {} + +CFX_CTTGSUBTable::TLangSys::TLangSys() + : LookupOrder(0), ReqFeatureIndex(0), FeatureCount(0) {} + +CFX_CTTGSUBTable::TLangSys::~TLangSys() {} diff --git a/core/fpdfapi/fpdf_font/ttgsubtable.h b/core/fpdfapi/fpdf_font/ttgsubtable.h index fc040b6e53..6e69517c72 100644 --- a/core/fpdfapi/fpdf_font/ttgsubtable.h +++ b/core/fpdfapi/fpdf_font/ttgsubtable.h @@ -10,6 +10,7 @@ #include <stdint.h> #include <map> +#include <memory> #include "core/fxcrt/include/fx_basic.h" #include "core/fxge/include/fx_font.h" @@ -45,17 +46,13 @@ class CFX_CTTGSUBTable { uint16_t LookupList; }; struct TLangSys { - TLangSys() - : LookupOrder(0), - ReqFeatureIndex(0), - FeatureCount(0), - FeatureIndex(nullptr) {} - ~TLangSys() { delete[] FeatureIndex; } + TLangSys(); + ~TLangSys(); uint16_t LookupOrder; uint16_t ReqFeatureIndex; uint16_t FeatureCount; - uint16_t* FeatureIndex; + std::unique_ptr<uint16_t[]> FeatureIndex; private: TLangSys(const TLangSys&); @@ -65,20 +62,19 @@ class CFX_CTTGSUBTable { TLangSysRecord() : LangSysTag(0) {} uint32_t LangSysTag; - struct TLangSys LangSys; + TLangSys LangSys; private: TLangSysRecord(const TLangSysRecord&); TLangSysRecord& operator=(const TLangSysRecord&); }; struct TScript { - TScript() : DefaultLangSys(0), LangSysCount(0), LangSysRecord(nullptr) {} - ~TScript() { delete[] LangSysRecord; } + TScript(); + ~TScript(); uint16_t DefaultLangSys; uint16_t LangSysCount; - // TODO(weili): Replace with a smart pointer type, pdfium:518. - struct TLangSysRecord* LangSysRecord; + std::unique_ptr<TLangSysRecord[]> LangSysRecord; private: TScript(const TScript&); @@ -88,30 +84,30 @@ class CFX_CTTGSUBTable { TScriptRecord() : ScriptTag(0) {} uint32_t ScriptTag; - struct TScript Script; + TScript Script; private: TScriptRecord(const TScriptRecord&); TScriptRecord& operator=(const TScriptRecord&); }; struct TScriptList { - TScriptList() : ScriptCount(0), ScriptRecord(nullptr) {} - ~TScriptList() { delete[] ScriptRecord; } + TScriptList(); + ~TScriptList(); uint16_t ScriptCount; - struct TScriptRecord* ScriptRecord; + std::unique_ptr<TScriptRecord[]> ScriptRecord; private: TScriptList(const TScriptList&); TScriptList& operator=(const TScriptList&); }; struct TFeature { - TFeature() : FeatureParams(0), LookupCount(0), LookupListIndex(nullptr) {} - ~TFeature() { delete[] LookupListIndex; } + TFeature(); + ~TFeature(); uint16_t FeatureParams; int LookupCount; - uint16_t* LookupListIndex; + std::unique_ptr<uint16_t[]> LookupListIndex; private: TFeature(const TFeature&); @@ -121,18 +117,18 @@ class CFX_CTTGSUBTable { TFeatureRecord() : FeatureTag(0) {} uint32_t FeatureTag; - struct TFeature Feature; + TFeature Feature; private: TFeatureRecord(const TFeatureRecord&); TFeatureRecord& operator=(const TFeatureRecord&); }; struct TFeatureList { - TFeatureList() : FeatureCount(0), FeatureRecord(nullptr) {} - ~TFeatureList() { delete[] FeatureRecord; } + TFeatureList(); + ~TFeatureList(); int FeatureCount; - struct TFeatureRecord* FeatureRecord; + std::unique_ptr<TFeatureRecord[]> FeatureRecord; private: TFeatureList(const TFeatureList&); @@ -148,6 +144,7 @@ class CFX_CTTGSUBTable { }; struct TCoverageFormatBase { TCoverageFormatBase() : CoverageFormat(0) {} + explicit TCoverageFormatBase(uint16_t format) : CoverageFormat(format) {} virtual ~TCoverageFormatBase() {} uint16_t CoverageFormat; @@ -162,7 +159,7 @@ class CFX_CTTGSUBTable { ~TCoverageFormat1() override; uint16_t GlyphCount; - uint16_t* GlyphArray; + std::unique_ptr<uint16_t[]> GlyphArray; private: TCoverageFormat1(const TCoverageFormat1&); @@ -187,56 +184,12 @@ class CFX_CTTGSUBTable { ~TCoverageFormat2() override; uint16_t RangeCount; - struct TRangeRecord* RangeRecord; + std::unique_ptr<TRangeRecord[]> RangeRecord; private: TCoverageFormat2(const TCoverageFormat2&); TCoverageFormat2& operator=(const TCoverageFormat2&); }; - struct TClassDefFormatBase { - TClassDefFormatBase() : ClassFormat(0) {} - virtual ~TClassDefFormatBase() {} - - uint16_t ClassFormat; - - private: - TClassDefFormatBase(const TClassDefFormatBase&); - TClassDefFormatBase& operator=(const TClassDefFormatBase&); - }; - struct TClassDefFormat1 : public TClassDefFormatBase { - TClassDefFormat1(); - ~TClassDefFormat1() override; - - uint16_t StartGlyph; - uint16_t GlyphCount; - uint16_t* ClassValueArray; - - private: - TClassDefFormat1(const TClassDefFormat1&); - TClassDefFormat1& operator=(const TClassDefFormat1&); - }; - struct TClassRangeRecord { - TClassRangeRecord() : Start(0), End(0), Class(0) {} - - uint16_t Start; - uint16_t End; - uint16_t Class; - - private: - TClassRangeRecord(const TClassRangeRecord&); - TClassRangeRecord& operator=(const TClassRangeRecord&); - }; - struct TClassDefFormat2 : public TClassDefFormatBase { - TClassDefFormat2(); - ~TClassDefFormat2() override; - - uint16_t ClassRangeCount; - struct TClassRangeRecord* ClassRangeRecord; - - private: - TClassDefFormat2(const TClassDefFormat2&); - TClassDefFormat2& operator=(const TClassDefFormat2&); - }; struct TDevice { TDevice() : StartSize(0), EndSize(0), DeltaFormat(0) {} @@ -250,6 +203,7 @@ class CFX_CTTGSUBTable { }; struct TSubTableBase { TSubTableBase() : SubstFormat(0) {} + explicit TSubTableBase(uint16_t format) : SubstFormat(format) {} virtual ~TSubTableBase() {} uint16_t SubstFormat; @@ -262,7 +216,7 @@ class CFX_CTTGSUBTable { TSingleSubstFormat1(); ~TSingleSubstFormat1() override; - TCoverageFormatBase* Coverage; + std::unique_ptr<TCoverageFormatBase> Coverage; int16_t DeltaGlyphID; private: @@ -273,9 +227,9 @@ class CFX_CTTGSUBTable { TSingleSubstFormat2(); ~TSingleSubstFormat2() override; - TCoverageFormatBase* Coverage; + std::unique_ptr<TCoverageFormatBase> Coverage; uint16_t GlyphCount; - uint16_t* Substitute; + std::unique_ptr<uint16_t[]> Substitute; private: TSingleSubstFormat2(const TSingleSubstFormat2&); @@ -288,18 +242,18 @@ class CFX_CTTGSUBTable { uint16_t LookupType; uint16_t LookupFlag; uint16_t SubTableCount; - struct TSubTableBase** SubTable; + std::unique_ptr<TSubTableBase* []> SubTable; private: TLookup(const TLookup&); TLookup& operator=(const TLookup&); }; struct TLookupList { - TLookupList() : LookupCount(0), Lookup(nullptr) {} - ~TLookupList() { delete[] Lookup; } + TLookupList(); + ~TLookupList(); int LookupCount; - struct TLookup* Lookup; + std::unique_ptr<TLookup[]> Lookup; private: TLookupList(const TLookupList&); @@ -314,7 +268,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); - void ParseCoverage(FT_Bytes raw, TCoverageFormatBase** rec); + TCoverageFormatBase* ParseCoverage(FT_Bytes raw); void ParseCoverageFormat1(FT_Bytes raw, TCoverageFormat1* rec); void ParseCoverageFormat2(FT_Bytes raw, TCoverageFormat2* rec); void ParseSingleSubst(FT_Bytes raw, TSubTableBase** rec); @@ -323,11 +277,11 @@ class CFX_CTTGSUBTable { bool GetVerticalGlyphSub(uint32_t glyphnum, uint32_t* vglyphnum, - struct TFeature* Feature) const; + TFeature* Feature) const; bool GetVerticalGlyphSub2(uint32_t glyphnum, uint32_t* vglyphnum, - struct TLookup* Lookup) const; - int GetCoverageIndex(struct TCoverageFormatBase* Coverage, uint32_t g) const; + TLookup* Lookup) const; + int GetCoverageIndex(TCoverageFormatBase* Coverage, uint32_t g) const; uint8_t GetUInt8(FT_Bytes& p) const; int16_t GetInt16(FT_Bytes& p) const; @@ -338,10 +292,10 @@ class CFX_CTTGSUBTable { std::map<uint32_t, uint32_t> m_featureMap; FX_BOOL m_bFeautureMapLoad; bool loaded; - struct tt_gsub_header header; - struct TScriptList ScriptList; - struct TFeatureList FeatureList; - struct TLookupList LookupList; + tt_gsub_header header; + TScriptList ScriptList; + TFeatureList FeatureList; + TLookupList LookupList; }; #endif // CORE_FPDFAPI_FPDF_FONT_TTGSUBTABLE_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_formobject.cpp b/core/fpdfapi/fpdf_page/cpdf_formobject.cpp index 567c156af0..dc93ed3c54 100644 --- a/core/fpdfapi/fpdf_page/cpdf_formobject.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_formobject.cpp @@ -8,11 +8,9 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" -CPDF_FormObject::CPDF_FormObject() : m_pForm(nullptr) {} +CPDF_FormObject::CPDF_FormObject() {} -CPDF_FormObject::~CPDF_FormObject() { - delete m_pForm; -} +CPDF_FormObject::~CPDF_FormObject() {} void CPDF_FormObject::Transform(const CFX_Matrix& matrix) { m_FormMatrix.Concat(matrix); @@ -35,7 +33,7 @@ CPDF_FormObject* CPDF_FormObject::Clone() const { CPDF_FormObject* obj = new CPDF_FormObject; obj->CopyData(this); - obj->m_pForm = m_pForm->Clone(); + obj->m_pForm.reset(m_pForm->Clone()); obj->m_FormMatrix = m_FormMatrix; return obj; } diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 0d16994bbe..1881244a0f 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -751,8 +751,8 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() { void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { std::unique_ptr<CPDF_FormObject> pFormObj(new CPDF_FormObject); - pFormObj->m_pForm = - new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources); + pFormObj->m_pForm.reset( + new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources)); pFormObj->m_FormMatrix = m_pCurStates->m_CTM; pFormObj->m_FormMatrix.Concat(m_mtContentToUser); CPDF_AllStates status; diff --git a/core/fpdfapi/fpdf_page/include/cpdf_formobject.h b/core/fpdfapi/fpdf_page/include/cpdf_formobject.h index 1a8db34e8f..03e117a132 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_formobject.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_formobject.h @@ -7,6 +7,8 @@ #ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_FORMOBJECT_H_ #define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_FORMOBJECT_H_ +#include <memory> + #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" #include "core/fxcrt/include/fx_coordinates.h" @@ -27,7 +29,7 @@ class CPDF_FormObject : public CPDF_PageObject { void CalcBoundingBox(); - CPDF_Form* m_pForm; + std::unique_ptr<CPDF_Form> m_pForm; CFX_Matrix m_FormMatrix; }; diff --git a/core/fpdfapi/fpdf_render/fpdf_render.cpp b/core/fpdfapi/fpdf_render/fpdf_render.cpp index 81a02cc6a7..3b4390ad6c 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render.cpp @@ -438,7 +438,7 @@ FX_BOOL CPDF_RenderStatus::ProcessForm(const CPDF_FormObject* pFormObj, FALSE); status.m_curBlend = m_curBlend; m_pDevice->SaveState(); - status.RenderObjectList(pFormObj->m_pForm, &matrix); + status.RenderObjectList(pFormObj->m_pForm.get(), &matrix); m_bStopped = status.m_bStopped; m_pDevice->RestoreState(false); #if defined _SKIA_SUPPORT_ |