Avoid using FT_Bytes in CFX_CTTGSUBTable
This class does not interact with FreeType, so just use const uint8_t*.
Change-Id: I7f22aca7a3ca9e3f3c89d93dc9875270a9ee989e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/107451
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 79de426..da3ce76 100644
--- a/core/fpdfapi/font/cfx_cttgsubtable.cpp
+++ b/core/fpdfapi/font/cfx_cttgsubtable.cpp
@@ -27,7 +27,7 @@
} // namespace
-CFX_CTTGSUBTable::CFX_CTTGSUBTable(FT_Bytes gsub) {
+CFX_CTTGSUBTable::CFX_CTTGSUBTable(const uint8_t* gsub) {
if (!LoadGSUBTable(gsub))
return;
@@ -55,7 +55,7 @@
CFX_CTTGSUBTable::~CFX_CTTGSUBTable() = default;
-bool CFX_CTTGSUBTable::LoadGSUBTable(FT_Bytes gsub) {
+bool CFX_CTTGSUBTable::LoadGSUBTable(const uint8_t* gsub) {
if (FXSYS_UINT32_GET_MSBFIRST(gsub) != 0x00010000)
return false;
@@ -146,46 +146,46 @@
return -1;
}
-uint8_t CFX_CTTGSUBTable::GetUInt8(FT_Bytes& p) const {
+uint8_t CFX_CTTGSUBTable::GetUInt8(const uint8_t*& p) const {
uint8_t ret = p[0];
p += 1;
return ret;
}
-int16_t CFX_CTTGSUBTable::GetInt16(FT_Bytes& p) const {
+int16_t CFX_CTTGSUBTable::GetInt16(const uint8_t*& p) const {
uint16_t ret = FXSYS_UINT16_GET_MSBFIRST(p);
p += 2;
return *reinterpret_cast<int16_t*>(&ret);
}
-uint16_t CFX_CTTGSUBTable::GetUInt16(FT_Bytes& p) const {
+uint16_t CFX_CTTGSUBTable::GetUInt16(const uint8_t*& p) const {
uint16_t ret = FXSYS_UINT16_GET_MSBFIRST(p);
p += 2;
return ret;
}
-int32_t CFX_CTTGSUBTable::GetInt32(FT_Bytes& p) const {
+int32_t CFX_CTTGSUBTable::GetInt32(const uint8_t*& p) const {
uint32_t ret = FXSYS_UINT32_GET_MSBFIRST(p);
p += 4;
return *reinterpret_cast<int32_t*>(&ret);
}
-uint32_t CFX_CTTGSUBTable::GetUInt32(FT_Bytes& p) const {
+uint32_t CFX_CTTGSUBTable::GetUInt32(const uint8_t*& p) const {
uint32_t ret = FXSYS_UINT32_GET_MSBFIRST(p);
p += 4;
return ret;
}
-void CFX_CTTGSUBTable::Parse(FT_Bytes scriptlist,
- FT_Bytes featurelist,
- FT_Bytes lookuplist) {
+void CFX_CTTGSUBTable::Parse(const uint8_t* scriptlist,
+ const uint8_t* featurelist,
+ const uint8_t* lookuplist) {
ParseScriptList(scriptlist);
ParseFeatureList(featurelist);
ParseLookupList(lookuplist);
}
-void CFX_CTTGSUBTable::ParseScriptList(FT_Bytes raw) {
- FT_Bytes sp = raw;
+void CFX_CTTGSUBTable::ParseScriptList(const uint8_t* raw) {
+ const uint8_t* sp = raw;
script_list_ = std::vector<ScriptRecord>(GetUInt16(sp));
for (auto& script : script_list_) {
// Skip over "ScriptTag" field.
@@ -194,9 +194,10 @@
}
}
-CFX_CTTGSUBTable::ScriptRecord CFX_CTTGSUBTable::ParseScript(FT_Bytes raw) {
+CFX_CTTGSUBTable::ScriptRecord CFX_CTTGSUBTable::ParseScript(
+ const uint8_t* raw) {
// Skip over "DefaultLangSys" field.
- FT_Bytes sp = raw + 2;
+ const uint8_t* sp = raw + 2;
ScriptRecord result(GetUInt16(sp));
for (auto& record : result) {
// Skip over "LangSysTag" field.
@@ -206,9 +207,10 @@
return result;
}
-CFX_CTTGSUBTable::FeatureIndices CFX_CTTGSUBTable::ParseLangSys(FT_Bytes raw) {
+CFX_CTTGSUBTable::FeatureIndices CFX_CTTGSUBTable::ParseLangSys(
+ const uint8_t* raw) {
// Skip over "LookupOrder" and "ReqFeatureIndex" fields.
- FT_Bytes sp = raw + 4;
+ const uint8_t* sp = raw + 4;
FeatureIndices result(GetUInt16(sp));
for (auto& element : result) {
element = GetUInt16(sp);
@@ -216,8 +218,8 @@
return result;
}
-void CFX_CTTGSUBTable::ParseFeatureList(FT_Bytes raw) {
- FT_Bytes sp = raw;
+void CFX_CTTGSUBTable::ParseFeatureList(const uint8_t* raw) {
+ const uint8_t* sp = raw;
feature_list_ = std::vector<FeatureRecord>(GetUInt16(sp));
for (auto& record : feature_list_) {
record.feature_tag = GetUInt32(sp);
@@ -227,9 +229,9 @@
}
DataVector<uint16_t> CFX_CTTGSUBTable::ParseFeatureLookupListIndices(
- FT_Bytes raw) {
+ const uint8_t* raw) {
// Skip over "FeatureParams" field.
- FT_Bytes sp = raw + 2;
+ const uint8_t* sp = raw + 2;
DataVector<uint16_t> result(GetUInt16(sp));
for (auto& index : result) {
index = GetUInt16(sp);
@@ -237,16 +239,16 @@
return result;
}
-void CFX_CTTGSUBTable::ParseLookupList(FT_Bytes raw) {
- FT_Bytes sp = raw;
+void CFX_CTTGSUBTable::ParseLookupList(const uint8_t* raw) {
+ const uint8_t* sp = raw;
lookup_list_ = std::vector<Lookup>(GetUInt16(sp));
for (auto& lookup : lookup_list_) {
lookup = ParseLookup(&raw[GetUInt16(sp)]);
}
}
-CFX_CTTGSUBTable::Lookup CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw) {
- FT_Bytes sp = raw;
+CFX_CTTGSUBTable::Lookup CFX_CTTGSUBTable::ParseLookup(const uint8_t* raw) {
+ const uint8_t* sp = raw;
CFX_CTTGSUBTable::Lookup result;
result.lookup_type = GetUInt16(sp);
// Skip over "LookupFlag" field.
@@ -262,8 +264,9 @@
return result;
}
-CFX_CTTGSUBTable::CoverageFormat CFX_CTTGSUBTable::ParseCoverage(FT_Bytes raw) {
- FT_Bytes sp = raw;
+CFX_CTTGSUBTable::CoverageFormat CFX_CTTGSUBTable::ParseCoverage(
+ const uint8_t* raw) {
+ const uint8_t* sp = raw;
uint16_t format = GetUInt16(sp);
if (format != 1 && format != 2) {
return absl::monostate();
@@ -286,8 +289,9 @@
return range_records;
}
-CFX_CTTGSUBTable::SubTable CFX_CTTGSUBTable::ParseSingleSubst(FT_Bytes raw) {
- FT_Bytes sp = raw;
+CFX_CTTGSUBTable::SubTable CFX_CTTGSUBTable::ParseSingleSubst(
+ const uint8_t* raw) {
+ const uint8_t* sp = raw;
uint16_t format = GetUInt16(sp);
SubTable rec;
if (format != 1 && format != 2) {
diff --git a/core/fpdfapi/font/cfx_cttgsubtable.h b/core/fpdfapi/font/cfx_cttgsubtable.h
index ebae880..de55f73 100644
--- a/core/fpdfapi/font/cfx_cttgsubtable.h
+++ b/core/fpdfapi/font/cfx_cttgsubtable.h
@@ -19,7 +19,7 @@
class CFX_CTTGSUBTable {
public:
- explicit CFX_CTTGSUBTable(FT_Bytes gsub);
+ explicit CFX_CTTGSUBTable(const uint8_t* gsub);
~CFX_CTTGSUBTable();
uint32_t GetVerticalGlyph(uint32_t glyphnum) const;
@@ -77,17 +77,19 @@
SubTables sub_tables;
};
- bool LoadGSUBTable(FT_Bytes gsub);
- void Parse(FT_Bytes scriptlist, FT_Bytes featurelist, FT_Bytes lookuplist);
- void ParseScriptList(FT_Bytes raw);
- ScriptRecord ParseScript(FT_Bytes raw);
- FeatureIndices ParseLangSys(FT_Bytes raw);
- void ParseFeatureList(FT_Bytes raw);
- DataVector<uint16_t> ParseFeatureLookupListIndices(FT_Bytes raw);
- void ParseLookupList(FT_Bytes raw);
- Lookup ParseLookup(FT_Bytes raw);
- CoverageFormat ParseCoverage(FT_Bytes raw);
- SubTable ParseSingleSubst(FT_Bytes raw);
+ bool LoadGSUBTable(const uint8_t* gsub);
+ void Parse(const uint8_t* scriptlist,
+ const uint8_t* featurelist,
+ const uint8_t* lookuplist);
+ void ParseScriptList(const uint8_t* raw);
+ ScriptRecord ParseScript(const uint8_t* raw);
+ FeatureIndices ParseLangSys(const uint8_t* raw);
+ void ParseFeatureList(const uint8_t* raw);
+ DataVector<uint16_t> ParseFeatureLookupListIndices(const uint8_t* raw);
+ void ParseLookupList(const uint8_t* raw);
+ Lookup ParseLookup(const uint8_t* raw);
+ CoverageFormat ParseCoverage(const uint8_t* raw);
+ SubTable ParseSingleSubst(const uint8_t* raw);
absl::optional<uint32_t> GetVerticalGlyphSub(const FeatureRecord& feature,
uint32_t glyphnum) const;
@@ -95,11 +97,11 @@
uint32_t glyphnum) const;
int GetCoverageIndex(const CoverageFormat& coverage, uint32_t g) const;
- uint8_t GetUInt8(FT_Bytes& p) const;
- int16_t GetInt16(FT_Bytes& p) const;
- uint16_t GetUInt16(FT_Bytes& p) const;
- int32_t GetInt32(FT_Bytes& p) const;
- uint32_t GetUInt32(FT_Bytes& p) const;
+ uint8_t GetUInt8(const uint8_t*& p) const;
+ int16_t GetInt16(const uint8_t*& p) const;
+ uint16_t GetUInt16(const uint8_t*& p) const;
+ int32_t GetInt32(const uint8_t*& p) const;
+ uint32_t GetUInt32(const uint8_t*& p) const;
std::set<uint32_t> feature_set_;
std::vector<ScriptRecord> script_list_;