// Copyright (c) 2011-2017 The OTS Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.
// Check existence of adjustment fields. for (unsigned i = 0; i < 4; ++i) { if ((value_format >> i) & 0x1) { // Just read the field since these fileds could take an arbitrary values. if (!subtable->Skip(2)) { return OTS_FAILURE_MSG("Failed to read value reacord component");
}
}
}
// Check existence of offsets to device table. for (unsigned i = 0; i < 4; ++i) { if ((value_format >> (i + 4)) & 0x1) {
uint16_t offset = 0; if (!subtable->ReadU16(&offset)) { return OTS_FAILURE_MSG("Failed to read value record offset");
} if (offset) { // TODO(bashi): Is it possible that device tables locate before // this record? No fonts contain such offset AKAIF. if (offset >= length) { return OTS_FAILURE_MSG("Value record offset too high %d >= %ld", offset, length);
} if (!ots::ParseDeviceTable(font, data + offset, length - offset)) { return OTS_FAILURE_MSG("Failed to parse device table in value record");
}
}
}
} returntrue;
}
uint16_t format = 0; // Read format and skip 2 2-byte fields that could be arbitrary values. if (!subtable.ReadU16(&format) ||
!subtable.Skip(4)) { return OTS_FAILURE_MSG("Faled to read anchor table");
}
if (format == 0 || format > kMaxAnchorFormat) { return OTS_FAILURE_MSG("Bad Anchor table format %d", format);
}
// Format 2 and 3 has additional fields. if (format == 2) { // Format 2 provides an index to a glyph contour point, which will take // arbitrary value.
uint16_t anchor_point = 0; if (!subtable.ReadU16(&anchor_point)) { return OTS_FAILURE_MSG("Failed to read anchor point in format 2 Anchor Table");
}
} elseif (format == 3) {
uint16_t offset_x_device = 0;
uint16_t offset_y_device = 0; if (!subtable.ReadU16(&offset_x_device) ||
!subtable.ReadU16(&offset_y_device)) { return OTS_FAILURE_MSG("Failed to read device table offsets in format 3 anchor table");
} constunsigned format_end = static_cast<unsigned>(10); if (offset_x_device) { if (offset_x_device < format_end || offset_x_device >= length) { return OTS_FAILURE_MSG("Bad x device table offset %d", offset_x_device);
} if (!ots::ParseDeviceTable(font, data + offset_x_device,
length - offset_x_device)) { return OTS_FAILURE_MSG("Failed to parse device table in anchor table");
}
} if (offset_y_device) { if (offset_y_device < format_end || offset_y_device >= length) { return OTS_FAILURE_MSG("Bad y device table offset %d", offset_y_device);
} if (!ots::ParseDeviceTable(font, data + offset_y_device,
length - offset_y_device)) { return OTS_FAILURE_MSG("Failed to parse device table in anchor table");
}
}
} returntrue;
}
uint16_t mark_count = 0; if (!subtable.ReadU16(&mark_count)) { return OTS_FAILURE_MSG("Can't read mark table length");
}
// MarkRecord consists of 4-bytes. constunsigned mark_records_end = 4 * static_cast<unsigned>(mark_count) + 2; if (mark_records_end > std::numeric_limits<uint16_t>::max()) { return OTS_FAILURE_MSG("Bad mark table length");
} for (unsigned i = 0; i < mark_count; ++i) {
uint16_t class_value = 0;
uint16_t offset_mark_anchor = 0; if (!subtable.ReadU16(&class_value) ||
!subtable.ReadU16(&offset_mark_anchor)) { return OTS_FAILURE_MSG("Can't read mark table %d", i);
} // |class_value| may take arbitrary values including 0 here so we don't // check the value. if (offset_mark_anchor < mark_records_end ||
offset_mark_anchor >= length) { return OTS_FAILURE_MSG("Bad mark anchor offset %d for mark table %d", offset_mark_anchor, i);
} if (!ParseAnchorTable(font, data + offset_mark_anchor,
length - offset_mark_anchor)) { return OTS_FAILURE_MSG("Faled to parse anchor table for mark table %d", i);
}
}
uint16_t value_count = 0; if (!subtable.ReadU16(&value_count)) { return OTS_FAILURE_MSG("Failed to read pair set table structure");
} for (unsigned i = 0; i < value_count; ++i) { // Check pair value record.
uint16_t glyph_id = 0; if (!subtable.ReadU16(&glyph_id)) { return OTS_FAILURE_MSG("Failed to read glyph in pair value record %d", i);
} if (glyph_id >= num_glyphs) { return OTS_FAILURE_MSG("glyph id %d too high >= %d", glyph_id, num_glyphs);
} if (!ParseValueRecord(font, &subtable, value_format1)) { return OTS_FAILURE_MSG("Failed to parse value record in format 1 pair set table");
} if (!ParseValueRecord(font, &subtable, value_format2)) { return OTS_FAILURE_MSG("Failed to parse value record in format 2 pair set table");
}
} returntrue;
}
// Check the validity of class definition offsets. if (offset_class_def1 < subtable.offset() + value_records_size ||
offset_class_def2 < subtable.offset() + value_records_size ||
offset_class_def1 >= length || offset_class_def2 >= length) { return OTS_FAILURE_MSG("Bad ParsePairPosFormat2 class definition offsets %d or %d", offset_class_def1, offset_class_def2);
}
// Check class 1 records. if (value_record1_size || value_record2_size) { for (unsigned i = 0; i < class1_count; ++i) { // Check class 2 records. for (unsigned j = 0; j < class2_count; ++j) { if (value_format1 && value_record2_size &&
!ParseValueRecord(font, &subtable, value_format1)) { return OTS_FAILURE_MSG("Failed to parse value record 1 %d and %d", j, i);
} if (value_format2 && value_record2_size &&
!ParseValueRecord(font, &subtable, value_format2)) { return OTS_FAILURE_MSG("Falied to parse value record 2 %d and %d", j, i);
}
}
}
}
// Check class definition tables. if (!ots::ParseClassDefTable(font, data + offset_class_def1,
length - offset_class_def1,
num_glyphs, ots::kMaxClassDefValue)) { return OTS_FAILURE_MSG("Failed to parse class definition table 1");
} if (!ots::ParseClassDefTable(font, data + offset_class_def2,
length - offset_class_def2,
num_glyphs, ots::kMaxClassDefValue)) { return OTS_FAILURE_MSG("Failed to parse class definition table 2");
}
constunsigned anchor_array_end = 2 * static_cast<unsigned>(record_count) * static_cast<unsigned>(class_count) + 2; if (anchor_array_end > std::numeric_limits<uint16_t>::max()) { return OTS_FAILURE_MSG("Bad end of anchor array %d", anchor_array_end);
} for (unsigned i = 0; i < record_count; ++i) { for (unsigned j = 0; j < class_count; ++j) {
uint16_t offset_record = 0; if (!subtable.ReadU16(&offset_record)) { return OTS_FAILURE_MSG("Can't read anchor array record offset for class %d and record %d", j, i);
} // |offset_record| could be NULL. if (offset_record) { if (offset_record < anchor_array_end || offset_record >= length) { return OTS_FAILURE_MSG("Bad record offset %d in class %d, record %d", offset_record, j, i);
} if (!ParseAnchorTable(font, data + offset_record,
length - offset_record)) { return OTS_FAILURE_MSG("Failed to parse anchor table for class %d, record %d", j, i);
}
}
}
} returntrue;
}
uint16_t format = 0;
uint16_t offset_coverage = 0;
uint16_t value_format = 0; if (!subtable.ReadU16(&format) ||
!subtable.ReadU16(&offset_coverage) ||
!subtable.ReadU16(&value_format)) { return Error("Can't read single adjustment information");
}
if (format == 1) { // Format 1 exactly one value record. if (!ParseValueRecord(font, &subtable, value_format)) { return Error("Failed to parse format 1 single adjustment table");
}
} elseif (format == 2) {
uint16_t value_count = 0; if (!subtable.ReadU16(&value_count)) { return Error("Failed to parse format 2 single adjustment table");
} for (unsigned i = 0; i < value_count; ++i) { if (!ParseValueRecord(font, &subtable, value_format)) { return Error("Failed to parse value record %d in format 2 single adjustment table", i);
}
}
} else { return Error("Bad format %d in single adjustment table", format);
}
if (offset_coverage < subtable.offset() || offset_coverage >= length) { return Error("Bad coverage offset %d in single adjustment table", offset_coverage);
}
if (!ots::ParseCoverageTable(font, data + offset_coverage,
length - offset_coverage,
maxp->num_glyphs)) { return Error("Failed to parse coverage table in single adjustment table");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.