summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-01-30 09:56:43 -0800
committerChromium commit bot <commit-bot@chromium.org>2017-01-30 18:16:45 +0000
commit4ada364e183e05479bc45d2ce41700ae18b7f6a3 (patch)
tree435adbe6e6bdb202f150588793aad6afd3d02c4a
parent5535ac7897358d9b5f2f7eb508f4aa44791e501f (diff)
downloadpdfium-4ada364e183e05479bc45d2ce41700ae18b7f6a3.tar.xz
Cleanup memory allocations in ttgsubtable.cpp
Rename array members to plurals. Use std::vectors rather than native arrays and counts. Use std::set instead of map of key to itself. Use unique_ptr inside vector to clean subtables. Mark non-existent constructors() = delete. Change-Id: Ifde189157e8affb5de654a44fac8b9358de7079b Reviewed-on: https://pdfium-review.googlesource.com/2452 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fpdfapi/font/ttgsubtable.cpp278
-rw-r--r--core/fpdfapi/font/ttgsubtable.h126
2 files changed, 169 insertions, 235 deletions
diff --git a/core/fpdfapi/font/ttgsubtable.cpp b/core/fpdfapi/font/ttgsubtable.cpp
index c037746c1e..51e8e9cc20 100644
--- a/core/fpdfapi/font/ttgsubtable.cpp
+++ b/core/fpdfapi/font/ttgsubtable.cpp
@@ -7,6 +7,7 @@
#include "core/fpdfapi/font/ttgsubtable.h"
#include "core/fxge/fx_freetype.h"
+#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
CFX_GlyphMap::CFX_GlyphMap() {}
@@ -93,33 +94,29 @@ bool CFX_CTTGSUBTable::GetVerticalGlyph(uint32_t glyphnum,
(uint8_t)'t',
};
if (!m_bFeautureMapLoad) {
- for (int i = 0; i < ScriptList.ScriptCount; i++) {
- 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)) {
- m_featureMap[index] = index;
- }
+ for (const auto& script : ScriptList.ScriptRecords) {
+ for (const auto& record : script.Script.LangSysRecords) {
+ for (const auto& index : record.LangSys.FeatureIndices) {
+ if (FeatureList.FeatureRecords[index].FeatureTag == tag[0] ||
+ FeatureList.FeatureRecords[index].FeatureTag == tag[1]) {
+ m_featureSet.insert(index);
}
}
}
}
- if (m_featureMap.empty()) {
- for (int i = 0; i < FeatureList.FeatureCount; i++) {
- if (FeatureList.FeatureRecord[i].FeatureTag == tag[0] ||
- FeatureList.FeatureRecord[i].FeatureTag == tag[1]) {
- m_featureMap[i] = i;
- }
+ if (m_featureSet.empty()) {
+ int i = 0;
+ for (const auto& feature : FeatureList.FeatureRecords) {
+ if (feature.FeatureTag == tag[0] || feature.FeatureTag == tag[1])
+ m_featureSet.insert(i);
+ ++i;
}
}
m_bFeautureMapLoad = true;
}
- for (const auto& pair : m_featureMap) {
+ for (const auto& item : m_featureSet) {
if (GetVerticalGlyphSub(glyphnum, vglyphnum,
- &FeatureList.FeatureRecord[pair.second].Feature)) {
+ &FeatureList.FeatureRecords[item].Feature)) {
return true;
}
}
@@ -128,17 +125,14 @@ bool CFX_CTTGSUBTable::GetVerticalGlyph(uint32_t glyphnum,
bool CFX_CTTGSUBTable::GetVerticalGlyphSub(uint32_t glyphnum,
uint32_t* vglyphnum,
- TFeature* Feature) const {
- for (int i = 0; i < Feature->LookupCount; i++) {
- int index = Feature->LookupListIndex[i];
- if (index < 0 || LookupList.LookupCount < index) {
+ TFeature* Feature) {
+ for (int index : Feature->LookupListIndices) {
+ if (index < 0 || index >= pdfium::CollectionSize<int>(LookupList.Lookups))
continue;
- }
- if (LookupList.Lookup[index].LookupType == 1) {
- if (GetVerticalGlyphSub2(glyphnum, vglyphnum,
- &LookupList.Lookup[index])) {
- return true;
- }
+
+ if (LookupList.Lookups[index].LookupType == 1 &&
+ GetVerticalGlyphSub2(glyphnum, vglyphnum, &LookupList.Lookups[index])) {
+ return true;
}
}
return false;
@@ -146,11 +140,11 @@ bool CFX_CTTGSUBTable::GetVerticalGlyphSub(uint32_t glyphnum,
bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(uint32_t glyphnum,
uint32_t* vglyphnum,
- TLookup* Lookup) const {
- for (int i = 0; i < Lookup->SubTableCount; i++) {
- switch (Lookup->SubTable[i]->SubstFormat) {
+ TLookup* Lookup) {
+ for (const auto& subTable : Lookup->SubTables) {
+ switch (subTable->SubstFormat) {
case 1: {
- TSingleSubstFormat1* tbl1 = (TSingleSubstFormat1*)Lookup->SubTable[i];
+ auto tbl1 = static_cast<TSingleSubstFormat1*>(subTable.get());
if (GetCoverageIndex(tbl1->Coverage.get(), glyphnum) >= 0) {
*vglyphnum = glyphnum + tbl1->DeltaGlyphID;
return true;
@@ -158,11 +152,11 @@ bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(uint32_t glyphnum,
break;
}
case 2: {
- TSingleSubstFormat2* tbl2 = (TSingleSubstFormat2*)Lookup->SubTable[i];
- int index = -1;
- index = GetCoverageIndex(tbl2->Coverage.get(), glyphnum);
- if (0 <= index && index < tbl2->GlyphCount) {
- *vglyphnum = tbl2->Substitute[index];
+ auto tbl2 = static_cast<TSingleSubstFormat2*>(subTable.get());
+ int index = GetCoverageIndex(tbl2->Coverage.get(), glyphnum);
+ if (index >= 0 &&
+ index < pdfium::CollectionSize<int>(tbl2->Substitutes)) {
+ *vglyphnum = tbl2->Substitutes[index];
return true;
}
break;
@@ -174,29 +168,28 @@ bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(uint32_t glyphnum,
int CFX_CTTGSUBTable::GetCoverageIndex(TCoverageFormatBase* Coverage,
uint32_t g) const {
- int i = 0;
- if (!Coverage) {
+ if (!Coverage)
return -1;
- }
+
switch (Coverage->CoverageFormat) {
case 1: {
+ int i = 0;
TCoverageFormat1* c1 = (TCoverageFormat1*)Coverage;
- for (i = 0; i < c1->GlyphCount; i++) {
- if ((uint32_t)c1->GlyphArray[i] == g) {
+ for (const auto& glyph : c1->GlyphArray) {
+ if (static_cast<uint32_t>(glyph) == g)
return i;
- }
+ ++i;
}
return -1;
}
case 2: {
TCoverageFormat2* c2 = (TCoverageFormat2*)Coverage;
- for (i = 0; i < c2->RangeCount; i++) {
- uint32_t s = c2->RangeRecord[i].Start;
- uint32_t e = c2->RangeRecord[i].End;
- uint32_t si = c2->RangeRecord[i].StartCoverageIndex;
- if (s <= g && g <= e) {
+ for (const auto& rangeRec : c2->RangeRecords) {
+ uint32_t s = rangeRec.Start;
+ uint32_t e = rangeRec.End;
+ uint32_t si = rangeRec.StartCoverageIndex;
+ if (s <= g && g <= e)
return si + g - s;
- }
}
return -1;
}
@@ -244,33 +237,21 @@ bool CFX_CTTGSUBTable::Parse(FT_Bytes scriptlist,
}
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.reset(new TScriptRecord[rec->ScriptCount]);
- for (i = 0; i < rec->ScriptCount; i++) {
- rec->ScriptRecord[i].ScriptTag = GetUInt32(sp);
- uint16_t offset = GetUInt16(sp);
- ParseScript(&raw[offset], &rec->ScriptRecord[i].Script);
+ rec->ScriptRecords = std::vector<TScriptRecord>(GetUInt16(sp));
+ for (auto& scriptRec : rec->ScriptRecords) {
+ scriptRec.ScriptTag = GetUInt32(sp);
+ ParseScript(&raw[GetUInt16(sp)], &scriptRec.Script);
}
}
void CFX_CTTGSUBTable::ParseScript(FT_Bytes raw, TScript* rec) {
- int i;
FT_Bytes sp = raw;
rec->DefaultLangSys = GetUInt16(sp);
- rec->LangSysCount = GetUInt16(sp);
- if (rec->LangSysCount <= 0) {
- return;
- }
- 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);
- ParseLangSys(&raw[offset], &rec->LangSysRecord[i].LangSys);
+ rec->LangSysRecords = std::vector<TLangSysRecord>(GetUInt16(sp));
+ for (auto& sysRecord : rec->LangSysRecords) {
+ sysRecord.LangSysTag = GetUInt32(sp);
+ ParseLangSys(&raw[GetUInt16(sp)], &sysRecord.LangSys);
}
}
@@ -278,81 +259,45 @@ void CFX_CTTGSUBTable::ParseLangSys(FT_Bytes raw, TLangSys* rec) {
FT_Bytes sp = raw;
rec->LookupOrder = GetUInt16(sp);
rec->ReqFeatureIndex = GetUInt16(sp);
- rec->FeatureCount = GetUInt16(sp);
- if (rec->FeatureCount <= 0) {
- return;
- }
- 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);
- }
+ rec->FeatureIndices = std::vector<uint16_t>(GetUInt16(sp));
+ for (auto& element : rec->FeatureIndices)
+ element = GetUInt16(sp);
}
void CFX_CTTGSUBTable::ParseFeatureList(FT_Bytes raw, TFeatureList* rec) {
- int i;
FT_Bytes sp = raw;
- rec->FeatureCount = GetUInt16(sp);
- if (rec->FeatureCount <= 0) {
- return;
- }
- 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);
- ParseFeature(&raw[offset], &rec->FeatureRecord[i].Feature);
+ rec->FeatureRecords = std::vector<TFeatureRecord>(GetUInt16(sp));
+ for (auto& featureRec : rec->FeatureRecords) {
+ featureRec.FeatureTag = GetUInt32(sp);
+ ParseFeature(&raw[GetUInt16(sp)], &featureRec.Feature);
}
}
void CFX_CTTGSUBTable::ParseFeature(FT_Bytes raw, TFeature* rec) {
- int i;
FT_Bytes sp = raw;
rec->FeatureParams = GetUInt16(sp);
- rec->LookupCount = GetUInt16(sp);
- if (rec->LookupCount <= 0) {
- return;
- }
- rec->LookupListIndex.reset(new uint16_t[rec->LookupCount]);
- for (i = 0; i < rec->LookupCount; i++) {
- rec->LookupListIndex[i] = GetUInt16(sp);
- }
+ rec->LookupListIndices = std::vector<uint16_t>(GetUInt16(sp));
+ for (auto& listIndex : rec->LookupListIndices)
+ listIndex = GetUInt16(sp);
}
void CFX_CTTGSUBTable::ParseLookupList(FT_Bytes raw, TLookupList* rec) {
- int i;
FT_Bytes sp = raw;
- rec->LookupCount = GetUInt16(sp);
- if (rec->LookupCount <= 0) {
- return;
- }
- 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]);
- }
+ rec->Lookups = std::vector<TLookup>(GetUInt16(sp));
+ for (auto& lookup : rec->Lookups)
+ ParseLookup(&raw[GetUInt16(sp)], &lookup);
}
void CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw, TLookup* rec) {
- int i;
FT_Bytes sp = raw;
rec->LookupType = GetUInt16(sp);
rec->LookupFlag = GetUInt16(sp);
- rec->SubTableCount = GetUInt16(sp);
- if (rec->SubTableCount <= 0) {
- return;
- }
- rec->SubTable.reset(new TSubTableBase*[rec->SubTableCount]);
- for (i = 0; i < rec->SubTableCount; i++) {
- rec->SubTable[i] = nullptr;
- }
- if (rec->LookupType != 1) {
+ rec->SubTables = std::vector<std::unique_ptr<TSubTableBase>>(GetUInt16(sp));
+ if (rec->LookupType != 1)
return;
- }
- for (i = 0; i < rec->SubTableCount; i++) {
- uint16_t offset = GetUInt16(sp);
- ParseSingleSubst(&raw[offset], &rec->SubTable[i]);
- }
+
+ for (auto& subTable : rec->SubTables)
+ ParseSingleSubst(&raw[GetUInt16(sp)], &subTable);
}
CFX_CTTGSUBTable::TCoverageFormatBase* CFX_CTTGSUBTable::ParseCoverage(
@@ -372,47 +317,39 @@ CFX_CTTGSUBTable::TCoverageFormatBase* CFX_CTTGSUBTable::ParseCoverage(
void CFX_CTTGSUBTable::ParseCoverageFormat1(FT_Bytes raw,
TCoverageFormat1* rec) {
- int i;
FT_Bytes sp = raw;
- GetUInt16(sp);
- rec->GlyphCount = GetUInt16(sp);
- if (rec->GlyphCount <= 0) {
- return;
- }
- rec->GlyphArray.reset(new uint16_t[rec->GlyphCount]);
- for (i = 0; i < rec->GlyphCount; i++) {
- rec->GlyphArray[i] = GetUInt16(sp);
- }
+ (void)GetUInt16(sp);
+ rec->GlyphArray = std::vector<uint16_t>(GetUInt16(sp));
+ for (auto& glyph : rec->GlyphArray)
+ glyph = GetUInt16(sp);
}
void CFX_CTTGSUBTable::ParseCoverageFormat2(FT_Bytes raw,
TCoverageFormat2* rec) {
- int i;
FT_Bytes sp = raw;
- GetUInt16(sp);
- rec->RangeCount = GetUInt16(sp);
- if (rec->RangeCount <= 0) {
- return;
- }
- 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);
- rec->RangeRecord[i].StartCoverageIndex = GetUInt16(sp);
+ (void)GetUInt16(sp);
+ rec->RangeRecords = std::vector<TRangeRecord>(GetUInt16(sp));
+ for (auto& rangeRec : rec->RangeRecords) {
+ rangeRec.Start = GetUInt16(sp);
+ rangeRec.End = GetUInt16(sp);
+ rangeRec.StartCoverageIndex = GetUInt16(sp);
}
}
-void CFX_CTTGSUBTable::ParseSingleSubst(FT_Bytes raw, TSubTableBase** rec) {
+void CFX_CTTGSUBTable::ParseSingleSubst(FT_Bytes raw,
+ std::unique_ptr<TSubTableBase>* rec) {
FT_Bytes sp = raw;
uint16_t Format = GetUInt16(sp);
switch (Format) {
case 1:
- *rec = new TSingleSubstFormat1();
- ParseSingleSubstFormat1(raw, (TSingleSubstFormat1*)*rec);
+ *rec = pdfium::MakeUnique<TSingleSubstFormat1>();
+ ParseSingleSubstFormat1(raw,
+ static_cast<TSingleSubstFormat1*>(rec->get()));
break;
case 2:
- *rec = new TSingleSubstFormat2();
- ParseSingleSubstFormat2(raw, (TSingleSubstFormat2*)*rec);
+ *rec = pdfium::MakeUnique<TSingleSubstFormat2>();
+ ParseSingleSubstFormat2(raw,
+ static_cast<TSingleSubstFormat2*>(rec->get()));
break;
}
}
@@ -428,23 +365,17 @@ void CFX_CTTGSUBTable::ParseSingleSubstFormat1(FT_Bytes raw,
void CFX_CTTGSUBTable::ParseSingleSubstFormat2(FT_Bytes raw,
TSingleSubstFormat2* rec) {
- int i;
FT_Bytes sp = raw;
- GetUInt16(sp);
+ (void)GetUInt16(sp);
uint16_t offset = GetUInt16(sp);
rec->Coverage.reset(ParseCoverage(&raw[offset]));
- rec->GlyphCount = GetUInt16(sp);
- if (rec->GlyphCount <= 0) {
- return;
- }
- rec->Substitute.reset(new uint16_t[rec->GlyphCount]);
- for (i = 0; i < rec->GlyphCount; i++) {
- rec->Substitute[i] = GetUInt16(sp);
- }
+ rec->Substitutes = std::vector<uint16_t>(GetUInt16(sp));
+ for (auto& substitute : rec->Substitutes)
+ substitute = GetUInt16(sp);
}
CFX_CTTGSUBTable::TCoverageFormat1::TCoverageFormat1()
- : TCoverageFormatBase(1), GlyphCount(0) {}
+ : TCoverageFormatBase(1) {}
CFX_CTTGSUBTable::TCoverageFormat1::~TCoverageFormat1() {}
@@ -452,7 +383,7 @@ CFX_CTTGSUBTable::TRangeRecord::TRangeRecord()
: Start(0), End(0), StartCoverageIndex(0) {}
CFX_CTTGSUBTable::TCoverageFormat2::TCoverageFormat2()
- : TCoverageFormatBase(2), RangeCount(0) {}
+ : TCoverageFormatBase(2) {}
CFX_CTTGSUBTable::TCoverageFormat2::~TCoverageFormat2() {}
@@ -462,41 +393,34 @@ CFX_CTTGSUBTable::TSingleSubstFormat1::TSingleSubstFormat1()
CFX_CTTGSUBTable::TSingleSubstFormat1::~TSingleSubstFormat1() {}
CFX_CTTGSUBTable::TSingleSubstFormat2::TSingleSubstFormat2()
- : TSubTableBase(2), GlyphCount(0) {}
+ : TSubTableBase(2) {}
CFX_CTTGSUBTable::TSingleSubstFormat2::~TSingleSubstFormat2() {}
-CFX_CTTGSUBTable::TLookup::TLookup()
- : LookupType(0), LookupFlag(0), SubTableCount(0) {}
+CFX_CTTGSUBTable::TLookup::TLookup() : LookupType(0), LookupFlag(0) {}
-CFX_CTTGSUBTable::TLookup::~TLookup() {
- if (SubTable) {
- for (int i = 0; i < SubTableCount; ++i)
- delete SubTable[i];
- }
-}
+CFX_CTTGSUBTable::TLookup::~TLookup() {}
-CFX_CTTGSUBTable::TScript::TScript() : DefaultLangSys(0), LangSysCount(0) {}
+CFX_CTTGSUBTable::TScript::TScript() : DefaultLangSys(0) {}
CFX_CTTGSUBTable::TScript::~TScript() {}
-CFX_CTTGSUBTable::TScriptList::TScriptList() : ScriptCount(0) {}
+CFX_CTTGSUBTable::TScriptList::TScriptList() {}
CFX_CTTGSUBTable::TScriptList::~TScriptList() {}
-CFX_CTTGSUBTable::TFeature::TFeature() : FeatureParams(0), LookupCount(0) {}
+CFX_CTTGSUBTable::TFeature::TFeature() : FeatureParams(0) {}
CFX_CTTGSUBTable::TFeature::~TFeature() {}
-CFX_CTTGSUBTable::TFeatureList::TFeatureList() : FeatureCount(0) {}
+CFX_CTTGSUBTable::TFeatureList::TFeatureList() {}
CFX_CTTGSUBTable::TFeatureList::~TFeatureList() {}
-CFX_CTTGSUBTable::TLookupList::TLookupList() : LookupCount(0) {}
+CFX_CTTGSUBTable::TLookupList::TLookupList() {}
CFX_CTTGSUBTable::TLookupList::~TLookupList() {}
-CFX_CTTGSUBTable::TLangSys::TLangSys()
- : LookupOrder(0), ReqFeatureIndex(0), FeatureCount(0) {}
+CFX_CTTGSUBTable::TLangSys::TLangSys() : LookupOrder(0), ReqFeatureIndex(0) {}
CFX_CTTGSUBTable::TLangSys::~TLangSys() {}
diff --git a/core/fpdfapi/font/ttgsubtable.h b/core/fpdfapi/font/ttgsubtable.h
index e0e4bbbd05..f927269540 100644
--- a/core/fpdfapi/font/ttgsubtable.h
+++ b/core/fpdfapi/font/ttgsubtable.h
@@ -9,8 +9,9 @@
#include <stdint.h>
-#include <map>
#include <memory>
+#include <set>
+#include <vector>
#include "core/fxcrt/fx_basic.h"
#include "core/fxge/fx_font.h"
@@ -45,19 +46,20 @@ class CFX_CTTGSUBTable {
uint16_t FeatureList;
uint16_t LookupList;
};
+
struct TLangSys {
TLangSys();
~TLangSys();
uint16_t LookupOrder;
uint16_t ReqFeatureIndex;
- uint16_t FeatureCount;
- std::unique_ptr<uint16_t[]> FeatureIndex;
+ std::vector<uint16_t> FeatureIndices;
private:
- TLangSys(const TLangSys&);
- TLangSys& operator=(const TLangSys&);
+ TLangSys(const TLangSys&) = delete;
+ TLangSys& operator=(const TLangSys&) = delete;
};
+
struct TLangSysRecord {
TLangSysRecord() : LangSysTag(0) {}
@@ -65,21 +67,22 @@ class CFX_CTTGSUBTable {
TLangSys LangSys;
private:
- TLangSysRecord(const TLangSysRecord&);
- TLangSysRecord& operator=(const TLangSysRecord&);
+ TLangSysRecord(const TLangSysRecord&) = delete;
+ TLangSysRecord& operator=(const TLangSysRecord&) = delete;
};
+
struct TScript {
TScript();
~TScript();
uint16_t DefaultLangSys;
- uint16_t LangSysCount;
- std::unique_ptr<TLangSysRecord[]> LangSysRecord;
+ std::vector<TLangSysRecord> LangSysRecords;
private:
- TScript(const TScript&);
- TScript& operator=(const TScript&);
+ TScript(const TScript&) = delete;
+ TScript& operator=(const TScript&) = delete;
};
+
struct TScriptRecord {
TScriptRecord() : ScriptTag(0) {}
@@ -87,32 +90,33 @@ class CFX_CTTGSUBTable {
TScript Script;
private:
- TScriptRecord(const TScriptRecord&);
- TScriptRecord& operator=(const TScriptRecord&);
+ TScriptRecord(const TScriptRecord&) = delete;
+ TScriptRecord& operator=(const TScriptRecord&) = delete;
};
+
struct TScriptList {
TScriptList();
~TScriptList();
- uint16_t ScriptCount;
- std::unique_ptr<TScriptRecord[]> ScriptRecord;
+ std::vector<TScriptRecord> ScriptRecords;
private:
- TScriptList(const TScriptList&);
- TScriptList& operator=(const TScriptList&);
+ TScriptList(const TScriptList&) = delete;
+ TScriptList& operator=(const TScriptList&) = delete;
};
+
struct TFeature {
TFeature();
~TFeature();
uint16_t FeatureParams;
- int LookupCount;
- std::unique_ptr<uint16_t[]> LookupListIndex;
+ std::vector<uint16_t> LookupListIndices;
private:
- TFeature(const TFeature&);
- TFeature& operator=(const TFeature&);
+ TFeature(const TFeature&) = delete;
+ TFeature& operator=(const TFeature&) = delete;
};
+
struct TFeatureRecord {
TFeatureRecord() : FeatureTag(0) {}
@@ -120,20 +124,21 @@ class CFX_CTTGSUBTable {
TFeature Feature;
private:
- TFeatureRecord(const TFeatureRecord&);
- TFeatureRecord& operator=(const TFeatureRecord&);
+ TFeatureRecord(const TFeatureRecord&) = delete;
+ TFeatureRecord& operator=(const TFeatureRecord&) = delete;
};
+
struct TFeatureList {
TFeatureList();
~TFeatureList();
- int FeatureCount;
- std::unique_ptr<TFeatureRecord[]> FeatureRecord;
+ std::vector<TFeatureRecord> FeatureRecords;
private:
- TFeatureList(const TFeatureList&);
- TFeatureList& operator=(const TFeatureList&);
+ TFeatureList(const TFeatureList&) = delete;
+ TFeatureList& operator=(const TFeatureList&) = delete;
};
+
enum TLookupFlag {
LOOKUPFLAG_RightToLeft = 0x0001,
LOOKUPFLAG_IgnoreBaseGlyphs = 0x0002,
@@ -142,6 +147,7 @@ class CFX_CTTGSUBTable {
LOOKUPFLAG_Reserved = 0x00F0,
LOOKUPFLAG_MarkAttachmentType = 0xFF00,
};
+
struct TCoverageFormatBase {
TCoverageFormatBase() : CoverageFormat(0) {}
explicit TCoverageFormatBase(uint16_t format) : CoverageFormat(format) {}
@@ -154,17 +160,18 @@ class CFX_CTTGSUBTable {
TCoverageFormatBase(const TCoverageFormatBase&);
TCoverageFormatBase& operator=(const TCoverageFormatBase&);
};
+
struct TCoverageFormat1 : public TCoverageFormatBase {
TCoverageFormat1();
~TCoverageFormat1() override;
- uint16_t GlyphCount;
- std::unique_ptr<uint16_t[]> GlyphArray;
+ std::vector<uint16_t> GlyphArray;
private:
- TCoverageFormat1(const TCoverageFormat1&);
- TCoverageFormat1& operator=(const TCoverageFormat1&);
+ TCoverageFormat1(const TCoverageFormat1&) = delete;
+ TCoverageFormat1& operator=(const TCoverageFormat1&) = delete;
};
+
struct TRangeRecord {
TRangeRecord();
@@ -177,19 +184,20 @@ class CFX_CTTGSUBTable {
uint16_t StartCoverageIndex;
private:
- TRangeRecord(const TRangeRecord&);
+ TRangeRecord(const TRangeRecord&) = delete;
};
+
struct TCoverageFormat2 : public TCoverageFormatBase {
TCoverageFormat2();
~TCoverageFormat2() override;
- uint16_t RangeCount;
- std::unique_ptr<TRangeRecord[]> RangeRecord;
+ std::vector<TRangeRecord> RangeRecords;
private:
- TCoverageFormat2(const TCoverageFormat2&);
- TCoverageFormat2& operator=(const TCoverageFormat2&);
+ TCoverageFormat2(const TCoverageFormat2&) = delete;
+ TCoverageFormat2& operator=(const TCoverageFormat2&) = delete;
};
+
struct TDevice {
TDevice() : StartSize(0), EndSize(0), DeltaFormat(0) {}
@@ -198,9 +206,10 @@ class CFX_CTTGSUBTable {
uint16_t DeltaFormat;
private:
- TDevice(const TDevice&);
- TDevice& operator=(const TDevice&);
+ TDevice(const TDevice&) = delete;
+ TDevice& operator=(const TDevice&) = delete;
};
+
struct TSubTableBase {
TSubTableBase() : SubstFormat(0) {}
explicit TSubTableBase(uint16_t format) : SubstFormat(format) {}
@@ -209,9 +218,10 @@ class CFX_CTTGSUBTable {
uint16_t SubstFormat;
private:
- TSubTableBase(const TSubTableBase&);
- TSubTableBase& operator=(const TSubTableBase&);
+ TSubTableBase(const TSubTableBase&) = delete;
+ TSubTableBase& operator=(const TSubTableBase&) = delete;
};
+
struct TSingleSubstFormat1 : public TSubTableBase {
TSingleSubstFormat1();
~TSingleSubstFormat1() override;
@@ -220,44 +230,44 @@ class CFX_CTTGSUBTable {
int16_t DeltaGlyphID;
private:
- TSingleSubstFormat1(const TSingleSubstFormat1&);
- TSingleSubstFormat1& operator=(const TSingleSubstFormat1&);
+ TSingleSubstFormat1(const TSingleSubstFormat1&) = delete;
+ TSingleSubstFormat1& operator=(const TSingleSubstFormat1&) = delete;
};
+
struct TSingleSubstFormat2 : public TSubTableBase {
TSingleSubstFormat2();
~TSingleSubstFormat2() override;
std::unique_ptr<TCoverageFormatBase> Coverage;
- uint16_t GlyphCount;
- std::unique_ptr<uint16_t[]> Substitute;
+ std::vector<uint16_t> Substitutes;
private:
- TSingleSubstFormat2(const TSingleSubstFormat2&);
- TSingleSubstFormat2& operator=(const TSingleSubstFormat2&);
+ TSingleSubstFormat2(const TSingleSubstFormat2&) = delete;
+ TSingleSubstFormat2& operator=(const TSingleSubstFormat2&) = delete;
};
+
struct TLookup {
TLookup();
~TLookup();
uint16_t LookupType;
uint16_t LookupFlag;
- uint16_t SubTableCount;
- std::unique_ptr<TSubTableBase* []> SubTable;
+ std::vector<std::unique_ptr<TSubTableBase>> SubTables;
private:
- TLookup(const TLookup&);
- TLookup& operator=(const TLookup&);
+ TLookup(const TLookup&) = delete;
+ TLookup& operator=(const TLookup&) = delete;
};
+
struct TLookupList {
TLookupList();
~TLookupList();
- int LookupCount;
- std::unique_ptr<TLookup[]> Lookup;
+ std::vector<TLookup> Lookups;
private:
- TLookupList(const TLookupList&);
- TLookupList& operator=(const TLookupList&);
+ TLookupList(const TLookupList&) = delete;
+ TLookupList& operator=(const TLookupList&) = delete;
};
bool Parse(FT_Bytes scriptlist, FT_Bytes featurelist, FT_Bytes lookuplist);
@@ -271,16 +281,16 @@ class CFX_CTTGSUBTable {
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);
+ void ParseSingleSubst(FT_Bytes raw, std::unique_ptr<TSubTableBase>* rec);
void ParseSingleSubstFormat1(FT_Bytes raw, TSingleSubstFormat1* rec);
void ParseSingleSubstFormat2(FT_Bytes raw, TSingleSubstFormat2* rec);
bool GetVerticalGlyphSub(uint32_t glyphnum,
uint32_t* vglyphnum,
- TFeature* Feature) const;
+ TFeature* Feature);
bool GetVerticalGlyphSub2(uint32_t glyphnum,
uint32_t* vglyphnum,
- TLookup* Lookup) const;
+ TLookup* Lookup);
int GetCoverageIndex(TCoverageFormatBase* Coverage, uint32_t g) const;
uint8_t GetUInt8(FT_Bytes& p) const;
@@ -289,7 +299,7 @@ class CFX_CTTGSUBTable {
int32_t GetInt32(FT_Bytes& p) const;
uint32_t GetUInt32(FT_Bytes& p) const;
- std::map<uint32_t, uint32_t> m_featureMap;
+ std::set<uint32_t> m_featureSet;
bool m_bFeautureMapLoad;
bool loaded;
tt_gsub_header header;