Clean up struct CFX_CTTGSUBTable::TFeatureRecord and TLookup
- Rename structs from TFoo to Foo.
- Remove unused fields.
- Rename remaining fields and instantiations to use names that follow
the style guide.
- Change struct parsing methods to return by value instead of by
out-parameter. Add move ctor to support this.
Change-Id: Iba222bec82cac6f9b140f68e7b349f6a9c37e963
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/107393
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cfx_cttgsubtable.cpp b/core/fpdfapi/font/cfx_cttgsubtable.cpp
index fa506d1..218f737 100644
--- a/core/fpdfapi/font/cfx_cttgsubtable.cpp
+++ b/core/fpdfapi/font/cfx_cttgsubtable.cpp
@@ -34,8 +34,9 @@
for (const auto& script : script_list_) {
for (const auto& record : script) {
for (uint16_t index : record) {
- if (IsVerticalFeatureTag(FeatureList[index].FeatureTag))
+ if (IsVerticalFeatureTag(feature_list_[index].feature_tag)) {
feature_set_.insert(index);
+ }
}
}
}
@@ -44,9 +45,10 @@
}
int i = 0;
- for (const TFeatureRecord& feature : FeatureList) {
- if (IsVerticalFeatureTag(feature.FeatureTag))
+ for (const FeatureRecord& feature : feature_list_) {
+ if (IsVerticalFeatureTag(feature.feature_tag)) {
feature_set_.insert(i);
+ }
++i;
}
}
@@ -66,7 +68,7 @@
uint32_t CFX_CTTGSUBTable::GetVerticalGlyph(uint32_t glyphnum) const {
for (uint32_t item : feature_set_) {
absl::optional<uint32_t> result =
- GetVerticalGlyphSub(FeatureList[item], glyphnum);
+ GetVerticalGlyphSub(feature_list_[item], glyphnum);
if (result.has_value())
return result.value();
}
@@ -74,15 +76,17 @@
}
absl::optional<uint32_t> CFX_CTTGSUBTable::GetVerticalGlyphSub(
- const TFeatureRecord& feature,
+ const FeatureRecord& feature,
uint32_t glyphnum) const {
- for (int index : feature.LookupListIndices) {
- if (!fxcrt::IndexInBounds(LookupList, index))
+ for (int index : feature.lookup_list_indices) {
+ if (!fxcrt::IndexInBounds(lookup_list_, index)) {
continue;
- if (LookupList[index].LookupType != 1)
+ }
+ if (lookup_list_[index].lookup_type != 1) {
continue;
+ }
absl::optional<uint32_t> result =
- GetVerticalGlyphSub2(LookupList[index], glyphnum);
+ GetVerticalGlyphSub2(lookup_list_[index], glyphnum);
if (result.has_value())
return result.value();
}
@@ -90,19 +94,19 @@
}
absl::optional<uint32_t> CFX_CTTGSUBTable::GetVerticalGlyphSub2(
- const TLookup& lookup,
+ const Lookup& lookup,
uint32_t glyphnum) const {
- for (const auto& subTable : lookup.SubTables) {
- switch (subTable->SubstFormat) {
+ for (const auto& sub_table : lookup.sub_tables) {
+ switch (sub_table->SubstFormat) {
case 1: {
- auto* tbl1 = static_cast<TSubTable1*>(subTable.get());
+ auto* tbl1 = static_cast<TSubTable1*>(sub_table.get());
if (GetCoverageIndex(tbl1->Coverage.get(), glyphnum) >= 0) {
return glyphnum + tbl1->DeltaGlyphID;
}
break;
}
case 2: {
- auto* tbl2 = static_cast<TSubTable2*>(subTable.get());
+ auto* tbl2 = static_cast<TSubTable2*>(sub_table.get());
int index = GetCoverageIndex(tbl2->Coverage.get(), glyphnum);
if (fxcrt::IndexInBounds(tbl2->Substitutes, index)) {
return tbl2->Substitutes[index];
@@ -217,38 +221,48 @@
void CFX_CTTGSUBTable::ParseFeatureList(FT_Bytes raw) {
FT_Bytes sp = raw;
- FeatureList = std::vector<TFeatureRecord>(GetUInt16(sp));
- for (auto& featureRec : FeatureList) {
- featureRec.FeatureTag = GetUInt32(sp);
- ParseFeature(&raw[GetUInt16(sp)], &featureRec);
+ feature_list_ = std::vector<FeatureRecord>(GetUInt16(sp));
+ for (auto& record : feature_list_) {
+ record.feature_tag = GetUInt32(sp);
+ record.lookup_list_indices =
+ ParseFeatureLookupListIndices(&raw[GetUInt16(sp)]);
}
}
-void CFX_CTTGSUBTable::ParseFeature(FT_Bytes raw, TFeatureRecord* rec) {
- FT_Bytes sp = raw;
- rec->FeatureParams = GetUInt16(sp);
- rec->LookupListIndices = DataVector<uint16_t>(GetUInt16(sp));
- for (auto& listIndex : rec->LookupListIndices)
- listIndex = GetUInt16(sp);
+DataVector<uint16_t> CFX_CTTGSUBTable::ParseFeatureLookupListIndices(
+ FT_Bytes raw) {
+ // Skip over "FeatureParams" field.
+ FT_Bytes sp = raw + 2;
+ DataVector<uint16_t> result(GetUInt16(sp));
+ for (auto& index : result) {
+ index = GetUInt16(sp);
+ }
+ return result;
}
void CFX_CTTGSUBTable::ParseLookupList(FT_Bytes raw) {
FT_Bytes sp = raw;
- LookupList = std::vector<TLookup>(GetUInt16(sp));
- for (auto& lookup : LookupList)
- ParseLookup(&raw[GetUInt16(sp)], &lookup);
+ lookup_list_ = std::vector<Lookup>(GetUInt16(sp));
+ for (auto& lookup : lookup_list_) {
+ lookup = ParseLookup(&raw[GetUInt16(sp)]);
+ }
}
-void CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw, TLookup* rec) {
+CFX_CTTGSUBTable::Lookup CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw) {
FT_Bytes sp = raw;
- rec->LookupType = GetUInt16(sp);
- rec->LookupFlag = GetUInt16(sp);
- rec->SubTables = std::vector<std::unique_ptr<TSubTableBase>>(GetUInt16(sp));
- if (rec->LookupType != 1)
- return;
+ CFX_CTTGSUBTable::Lookup result;
+ result.lookup_type = GetUInt16(sp);
+ // Skip over "LookupFlag" field.
+ sp += 2;
+ result.sub_tables = Lookup::SubTables(GetUInt16(sp));
+ if (result.lookup_type != 1) {
+ return result;
+ }
- for (auto& subTable : rec->SubTables)
- subTable = ParseSingleSubst(&raw[GetUInt16(sp)]);
+ for (auto& sub_table : result.sub_tables) {
+ sub_table = ParseSingleSubst(&raw[GetUInt16(sp)]);
+ }
+ return result;
}
std::unique_ptr<CFX_CTTGSUBTable::TCoverageFormatBase>
@@ -320,9 +334,9 @@
return rec;
}
-CFX_CTTGSUBTable::TFeatureRecord::TFeatureRecord() = default;
+CFX_CTTGSUBTable::FeatureRecord::FeatureRecord() = default;
-CFX_CTTGSUBTable::TFeatureRecord::~TFeatureRecord() = default;
+CFX_CTTGSUBTable::FeatureRecord::~FeatureRecord() = default;
CFX_CTTGSUBTable::TRangeRecord::TRangeRecord() = default;
@@ -351,6 +365,11 @@
CFX_CTTGSUBTable::TSubTable2::~TSubTable2() = default;
-CFX_CTTGSUBTable::TLookup::TLookup() = default;
+CFX_CTTGSUBTable::Lookup::Lookup() = default;
-CFX_CTTGSUBTable::TLookup::~TLookup() = default;
+CFX_CTTGSUBTable::Lookup::~Lookup() = default;
+
+CFX_CTTGSUBTable::Lookup::Lookup(Lookup&& that) noexcept = default;
+
+CFX_CTTGSUBTable::Lookup& CFX_CTTGSUBTable::Lookup::operator=(
+ Lookup&& that) noexcept = default;
diff --git a/core/fpdfapi/font/cfx_cttgsubtable.h b/core/fpdfapi/font/cfx_cttgsubtable.h
index 71ff1ff..f1cec76 100644
--- a/core/fpdfapi/font/cfx_cttgsubtable.h
+++ b/core/fpdfapi/font/cfx_cttgsubtable.h
@@ -28,13 +28,12 @@
using FeatureIndices = DataVector<uint16_t>;
using ScriptRecord = std::vector<FeatureIndices>;
- struct TFeatureRecord {
- TFeatureRecord();
- ~TFeatureRecord();
+ struct FeatureRecord {
+ FeatureRecord();
+ ~FeatureRecord();
- uint32_t FeatureTag = 0;
- uint16_t FeatureParams = 0;
- DataVector<uint16_t> LookupListIndices;
+ uint32_t feature_tag = 0;
+ DataVector<uint16_t> lookup_list_indices;
};
struct TRangeRecord {
@@ -96,13 +95,18 @@
DataVector<uint16_t> Substitutes;
};
- struct TLookup {
- TLookup();
- ~TLookup();
+ struct Lookup {
+ using SubTables = std::vector<std::unique_ptr<TSubTableBase>>;
- uint16_t LookupType = 0;
- uint16_t LookupFlag = 0;
- std::vector<std::unique_ptr<TSubTableBase>> SubTables;
+ Lookup();
+ Lookup(const Lookup& that) = delete;
+ Lookup& operator=(const Lookup& that) = delete;
+ Lookup(Lookup&& that) noexcept;
+ Lookup& operator=(Lookup&& that) noexcept;
+ ~Lookup();
+
+ uint16_t lookup_type = 0;
+ SubTables sub_tables;
};
bool LoadGSUBTable(FT_Bytes gsub);
@@ -111,9 +115,9 @@
ScriptRecord ParseScript(FT_Bytes raw);
FeatureIndices ParseLangSys(FT_Bytes raw);
void ParseFeatureList(FT_Bytes raw);
- void ParseFeature(FT_Bytes raw, TFeatureRecord* rec);
+ DataVector<uint16_t> ParseFeatureLookupListIndices(FT_Bytes raw);
void ParseLookupList(FT_Bytes raw);
- void ParseLookup(FT_Bytes raw, TLookup* rec);
+ Lookup ParseLookup(FT_Bytes raw);
std::unique_ptr<TCoverageFormatBase> ParseCoverage(FT_Bytes raw);
std::unique_ptr<TCoverageFormat1> ParseCoverageFormat1(FT_Bytes raw);
std::unique_ptr<TCoverageFormat2> ParseCoverageFormat2(FT_Bytes raw);
@@ -121,9 +125,9 @@
std::unique_ptr<TSubTable1> ParseSingleSubstFormat1(FT_Bytes raw);
std::unique_ptr<TSubTable2> ParseSingleSubstFormat2(FT_Bytes raw);
- absl::optional<uint32_t> GetVerticalGlyphSub(const TFeatureRecord& feature,
+ absl::optional<uint32_t> GetVerticalGlyphSub(const FeatureRecord& feature,
uint32_t glyphnum) const;
- absl::optional<uint32_t> GetVerticalGlyphSub2(const TLookup& lookup,
+ absl::optional<uint32_t> GetVerticalGlyphSub2(const Lookup& lookup,
uint32_t glyphnum) const;
int GetCoverageIndex(TCoverageFormatBase* Coverage, uint32_t g) const;
@@ -135,8 +139,8 @@
std::set<uint32_t> feature_set_;
std::vector<ScriptRecord> script_list_;
- std::vector<TFeatureRecord> FeatureList;
- std::vector<TLookup> LookupList;
+ std::vector<FeatureRecord> feature_list_;
+ std::vector<Lookup> lookup_list_;
};
#endif // CORE_FPDFAPI_FONT_CFX_CTTGSUBTABLE_H_