Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(736)

Unified Diff: src/gdef.cc

Issue 658573004: Updating to new OTS repo from https://github.com/khaledhosny/ots.git (Closed) Base URL: https://chromium.googlesource.com/external/ots@master
Patch Set: Adding Colored Emoji changes from external/git repo Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« .gitmodules ('K') | « src/gasp.cc ('k') | src/glyf.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gdef.cc
diff --git a/src/gdef.cc b/src/gdef.cc
old mode 100644
new mode 100755
index f7de0f0d28116d4d57b54a260ba1abf8f9c43792..523d3848e4d11cccc2650fc2024cbf0db7607d7d
--- a/src/gdef.cc
+++ b/src/gdef.cc
@@ -15,6 +15,8 @@
// GDEF - The Glyph Definition Table
// http://www.microsoft.com/typography/otspec/gdef.htm
+#define TABLE_NAME "GDEF"
+
namespace {
// The maximum class value in class definition tables.
@@ -28,7 +30,7 @@ const uint16_t kMaxCaretValueFormat = 2;
bool ParseGlyphClassDefTable(ots::OpenTypeFile *file, const uint8_t *data,
size_t length, const uint16_t num_glyphs) {
- return ots::ParseClassDefTable(data, length, num_glyphs,
+ return ots::ParseClassDefTable(file, data, length, num_glyphs,
kMaxGlyphClassDefValue);
}
@@ -40,38 +42,37 @@ bool ParseAttachListTable(ots::OpenTypeFile *file, const uint8_t *data,
uint16_t glyph_count = 0;
if (!subtable.ReadU16(&offset_coverage) ||
!subtable.ReadU16(&glyph_count)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to read gdef header");
}
const unsigned attach_points_end =
2 * static_cast<unsigned>(glyph_count) + 4;
if (attach_points_end > std::numeric_limits<uint16_t>::max()) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad glyph count in gdef");
}
if (offset_coverage == 0 || offset_coverage >= length ||
offset_coverage < attach_points_end) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad coverage offset %d", offset_coverage);
}
if (glyph_count > num_glyphs) {
- OTS_WARNING("bad glyph count: %u", glyph_count);
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad glyph count %u", glyph_count);
}
std::vector<uint16_t> attach_points;
attach_points.resize(glyph_count);
for (unsigned i = 0; i < glyph_count; ++i) {
if (!subtable.ReadU16(&attach_points[i])) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Can't read attachment point %d", i);
}
if (attach_points[i] >= length ||
attach_points[i] < attach_points_end) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad attachment point %d of %d", i, attach_points[i]);
}
}
// Parse coverage table
- if (!ots::ParseCoverageTable(data + offset_coverage,
+ if (!ots::ParseCoverageTable(file, data + offset_coverage,
length - offset_coverage, num_glyphs)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad coverage table");
}
// Parse attach point table
@@ -79,22 +80,21 @@ bool ParseAttachListTable(ots::OpenTypeFile *file, const uint8_t *data,
subtable.set_offset(attach_points[i]);
uint16_t point_count = 0;
if (!subtable.ReadU16(&point_count)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Can't read point count %d", i);
}
if (point_count == 0) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("zero point count %d", i);
}
uint16_t last_point_index = 0;
uint16_t point_index = 0;
for (unsigned j = 0; j < point_count; ++j) {
if (!subtable.ReadU16(&point_index)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Can't read point index %d in point %d", j, i);
}
// Contour point indeces are in increasing numerical order
if (last_point_index != 0 && last_point_index >= point_index) {
- OTS_WARNING("bad contour indeces: %u >= %u",
+ return OTS_FAILURE_MSG("bad contour indeces: %u >= %u",
last_point_index, point_index);
- return OTS_FAILURE();
}
last_point_index = point_index;
}
@@ -109,37 +109,36 @@ bool ParseLigCaretListTable(ots::OpenTypeFile *file, const uint8_t *data,
uint16_t lig_glyph_count = 0;
if (!subtable.ReadU16(&offset_coverage) ||
!subtable.ReadU16(&lig_glyph_count)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Can't read caret structure");
}
const unsigned lig_glyphs_end =
2 * static_cast<unsigned>(lig_glyph_count) + 4;
if (lig_glyphs_end > std::numeric_limits<uint16_t>::max()) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad caret structure");
}
if (offset_coverage == 0 || offset_coverage >= length ||
offset_coverage < lig_glyphs_end) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad caret coverate offset %d", offset_coverage);
}
if (lig_glyph_count > num_glyphs) {
- OTS_WARNING("bad ligature glyph count: %u", lig_glyph_count);
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("bad ligature glyph count: %u", lig_glyph_count);
}
std::vector<uint16_t> lig_glyphs;
lig_glyphs.resize(lig_glyph_count);
for (unsigned i = 0; i < lig_glyph_count; ++i) {
if (!subtable.ReadU16(&lig_glyphs[i])) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Can't read ligature glyph location %d", i);
}
if (lig_glyphs[i] >= length || lig_glyphs[i] < lig_glyphs_end) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad ligature glyph location %d in glyph %d", lig_glyphs[i], i);
}
}
// Parse coverage table
- if (!ots::ParseCoverageTable(data + offset_coverage,
+ if (!ots::ParseCoverageTable(file, data + offset_coverage,
length - offset_coverage, num_glyphs)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Can't parse caret coverage table");
}
// Parse ligature glyph table
@@ -147,51 +146,41 @@ bool ParseLigCaretListTable(ots::OpenTypeFile *file, const uint8_t *data,
subtable.set_offset(lig_glyphs[i]);
uint16_t caret_count = 0;
if (!subtable.ReadU16(&caret_count)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Can't read caret count for glyph %d", i);
}
if (caret_count == 0) {
- OTS_WARNING("bad caret value count: %u", caret_count);
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("bad caret value count: %u", caret_count);
}
- std::vector<uint16_t> caret_values;
- caret_values.resize(caret_count);
- uint16_t last_offset_caret = 0;
- unsigned caret_values_end = 2 * static_cast<unsigned>(caret_count) + 2;
+ std::vector<uint16_t> caret_value_offsets;
+ caret_value_offsets.resize(caret_count);
+ unsigned caret_value_offsets_end = 2 * static_cast<unsigned>(caret_count) + 2;
for (unsigned j = 0; j < caret_count; ++j) {
- if (!subtable.ReadU16(&caret_values[j])) {
- return OTS_FAILURE();
- }
- if (caret_values[j] >= length || caret_values[j] < caret_values_end) {
- return OTS_FAILURE();
+ if (!subtable.ReadU16(&caret_value_offsets[j])) {
+ return OTS_FAILURE_MSG("Can't read caret offset %d for glyph %d", j, i);
}
- // Caret offsets are in increasing coordinate order
- if (last_offset_caret != 0 && last_offset_caret >= caret_values[j]) {
- OTS_WARNING("offset isn't in increasing coordinate order: %u >= %u",
- last_offset_caret, caret_values[j]);
- return OTS_FAILURE();
+ if (caret_value_offsets[j] >= length || caret_value_offsets[j] < caret_value_offsets_end) {
+ return OTS_FAILURE_MSG("Bad caret offset %d for caret %d glyph %d", caret_value_offsets[j], j, i);
}
- last_offset_caret = caret_values[j];
}
// Parse caret values table
for (unsigned j = 0; j < caret_count; ++j) {
- subtable.set_offset(lig_glyphs[i] + caret_values[j]);
+ subtable.set_offset(lig_glyphs[i] + caret_value_offsets[j]);
uint16_t caret_format = 0;
if (!subtable.ReadU16(&caret_format)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Can't read caret values table %d in glyph %d", j, i);
}
// TODO(bashi): We only support caret value format 1 and 2 for now
// because there are no fonts which contain caret value format 3
// as far as we investigated.
if (caret_format == 0 || caret_format > kMaxCaretValueFormat) {
- OTS_WARNING("bad caret value format: %u", caret_format);
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("bad caret value format: %u", caret_format);
}
// CaretValueFormats contain a 2-byte field which could be
// arbitrary value.
if (!subtable.Skip(2)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad caret value table structure %d in glyph %d", j, i);
}
}
}
@@ -200,7 +189,7 @@ bool ParseLigCaretListTable(ots::OpenTypeFile *file, const uint8_t *data,
bool ParseMarkAttachClassDefTable(ots::OpenTypeFile *file, const uint8_t *data,
size_t length, const uint16_t num_glyphs) {
- return ots::ParseClassDefTable(data, length, num_glyphs, kMaxClassDefValue);
+ return ots::ParseClassDefTable(file, data, length, num_glyphs, kMaxClassDefValue);
}
bool ParseMarkGlyphSetsDefTable(ots::OpenTypeFile *file, const uint8_t *data,
@@ -210,29 +199,28 @@ bool ParseMarkGlyphSetsDefTable(ots::OpenTypeFile *file, const uint8_t *data,
uint16_t mark_set_count = 0;
if (!subtable.ReadU16(&format) ||
!subtable.ReadU16(&mark_set_count)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Can' read mark glyph table structure");
}
if (format != 1) {
- OTS_WARNING("bad mark glyph set table format: %u", format);
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("bad mark glyph set table format: %u", format);
}
const unsigned mark_sets_end = 2 * static_cast<unsigned>(mark_set_count) + 4;
if (mark_sets_end > std::numeric_limits<uint16_t>::max()) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad mark_set %d", mark_sets_end);
}
for (unsigned i = 0; i < mark_set_count; ++i) {
uint32_t offset_coverage = 0;
if (!subtable.ReadU32(&offset_coverage)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Can't read covrage location for mark set %d", i);
}
if (offset_coverage >= length ||
offset_coverage < mark_sets_end) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Bad coverage location %d for mark set %d", offset_coverage, i);
}
- if (!ots::ParseCoverageTable(data + offset_coverage,
+ if (!ots::ParseCoverageTable(file, data + offset_coverage,
length - offset_coverage, num_glyphs)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to parse coverage table for mark set %d", i);
}
}
file->gdef->num_mark_glyph_sets = mark_set_count;
@@ -241,8 +229,12 @@ bool ParseMarkGlyphSetsDefTable(ots::OpenTypeFile *file, const uint8_t *data,
} // namespace
-#define DROP_THIS_TABLE \
- do { file->gdef->data = 0; file->gdef->length = 0; } while (0)
+#define DROP_THIS_TABLE(msg_) \
+ do { \
+ file->gdef->data = 0; \
+ file->gdef->length = 0; \
+ OTS_FAILURE_MSG(msg_ ", table discarded"); \
+ } while (0)
namespace ots {
@@ -250,7 +242,7 @@ bool ots_gdef_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
// Grab the number of glyphs in the file from the maxp table to check
// GlyphIDs in GDEF table.
if (!file->maxp) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("No maxp table in font, needed by GDEF");
}
const uint16_t num_glyphs = file->maxp->num_glyphs;
@@ -261,11 +253,11 @@ bool ots_gdef_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
uint32_t version = 0;
if (!table.ReadU32(&version)) {
- return OTS_FAILURE();
+ DROP_THIS_TABLE("Incomplete table");
+ return true;
}
if (version < 0x00010000 || version == 0x00010001) {
- OTS_WARNING("bad GDEF version");
- DROP_THIS_TABLE;
+ DROP_THIS_TABLE("Bad version");
return true;
}
@@ -281,12 +273,14 @@ bool ots_gdef_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
!table.ReadU16(&offset_attach_list) ||
!table.ReadU16(&offset_lig_caret_list) ||
!table.ReadU16(&offset_mark_attach_class_def)) {
- return OTS_FAILURE();
+ DROP_THIS_TABLE("Incomplete table");
+ return true;
}
uint16_t offset_mark_glyph_sets_def = 0;
if (gdef->version_2) {
if (!table.ReadU16(&offset_mark_glyph_sets_def)) {
- return OTS_FAILURE();
+ DROP_THIS_TABLE("Incomplete table");
+ return true;
}
}
@@ -298,12 +292,13 @@ bool ots_gdef_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
if (offset_glyph_class_def) {
if (offset_glyph_class_def >= length ||
offset_glyph_class_def < gdef_header_end) {
- return OTS_FAILURE();
+ DROP_THIS_TABLE("Invalid offset to glyph classes");
+ return true;
}
if (!ParseGlyphClassDefTable(file, data + offset_glyph_class_def,
length - offset_glyph_class_def,
num_glyphs)) {
- DROP_THIS_TABLE;
+ DROP_THIS_TABLE("Invalid glyph classes");
return true;
}
gdef->has_glyph_class_def = true;
@@ -312,12 +307,13 @@ bool ots_gdef_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
if (offset_attach_list) {
if (offset_attach_list >= length ||
offset_attach_list < gdef_header_end) {
- return OTS_FAILURE();
+ DROP_THIS_TABLE("Invalid offset to attachment list");
+ return true;
}
if (!ParseAttachListTable(file, data + offset_attach_list,
length - offset_attach_list,
num_glyphs)) {
- DROP_THIS_TABLE;
+ DROP_THIS_TABLE("Invalid attachment list");
return true;
}
}
@@ -325,12 +321,13 @@ bool ots_gdef_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
if (offset_lig_caret_list) {
if (offset_lig_caret_list >= length ||
offset_lig_caret_list < gdef_header_end) {
- return OTS_FAILURE();
+ DROP_THIS_TABLE("Invalid offset to ligature caret list");
+ return true;
}
if (!ParseLigCaretListTable(file, data + offset_lig_caret_list,
length - offset_lig_caret_list,
num_glyphs)) {
- DROP_THIS_TABLE;
+ DROP_THIS_TABLE("Invalid ligature caret list");
return true;
}
}
@@ -338,13 +335,13 @@ bool ots_gdef_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
if (offset_mark_attach_class_def) {
if (offset_mark_attach_class_def >= length ||
offset_mark_attach_class_def < gdef_header_end) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Invalid offset to mark attachment list");
}
if (!ParseMarkAttachClassDefTable(file,
data + offset_mark_attach_class_def,
length - offset_mark_attach_class_def,
num_glyphs)) {
- DROP_THIS_TABLE;
+ DROP_THIS_TABLE("Invalid mark attachment list");
return true;
}
gdef->has_mark_attachment_class_def = true;
@@ -353,13 +350,13 @@ bool ots_gdef_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
if (offset_mark_glyph_sets_def) {
if (offset_mark_glyph_sets_def >= length ||
offset_mark_glyph_sets_def < gdef_header_end) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("invalid offset to mark glyph sets");
}
if (!ParseMarkGlyphSetsDefTable(file,
data + offset_mark_glyph_sets_def,
length - offset_mark_glyph_sets_def,
num_glyphs)) {
- DROP_THIS_TABLE;
+ DROP_THIS_TABLE("Invalid mark glyph sets");
return true;
}
gdef->has_mark_glyph_sets_def = true;
@@ -370,16 +367,12 @@ bool ots_gdef_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
}
bool ots_gdef_should_serialise(OpenTypeFile *file) {
- const bool needed_tables_dropped =
- (file->gsub && file->gsub->data == NULL) ||
- (file->gpos && file->gpos->data == NULL);
- return file->gdef != NULL && file->gdef->data != NULL &&
- !needed_tables_dropped;
+ return file->gdef != NULL && file->gdef->data != NULL;
}
bool ots_gdef_serialise(OTSStream *out, OpenTypeFile *file) {
if (!out->Write(file->gdef->data, file->gdef->length)) {
- return OTS_FAILURE();
+ return OTS_FAILURE_MSG("Failed to write GDEF table");
}
return true;
@@ -391,3 +384,5 @@ void ots_gdef_free(OpenTypeFile *file) {
} // namespace ots
+#undef TABLE_NAME
+#undef DROP_THIS_TABLE
« .gitmodules ('K') | « src/gasp.cc ('k') | src/glyf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698