Index: src/name.cc |
diff --git a/src/name.cc b/src/name.cc |
old mode 100644 |
new mode 100755 |
index 77c26cf088f2f6c1eebecdaa58e2a28d4614fd16..2ea10dc8e67d2ffb93fbbf5d6f45e9bc05c5c82b |
--- a/src/name.cc |
+++ b/src/name.cc |
@@ -10,7 +10,9 @@ |
#include "cff.h" |
// name - Naming Table |
-// http://www.microsoft.com/opentype/otspec/name.htm |
+// http://www.microsoft.com/typography/otspec/name.htm |
+ |
+#define TABLE_NAME "name" |
namespace { |
@@ -64,17 +66,17 @@ bool ots_name_parse(OpenTypeFile* file, const uint8_t* data, size_t length) { |
uint16_t format = 0; |
if (!table.ReadU16(&format) || format > 1) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Failed to read name table format or bad format %d", format); |
} |
uint16_t count = 0; |
if (!table.ReadU16(&count)) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Failed to read name count"); |
} |
uint16_t string_offset = 0; |
if (!table.ReadU16(&string_offset) || string_offset > length) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Failed to read strings offset"); |
} |
const char* string_base = reinterpret_cast<const char*>(data) + |
string_offset; |
@@ -88,14 +90,14 @@ bool ots_name_parse(OpenTypeFile* file, const uint8_t* data, size_t length) { |
// are invalid name records, but it's not clear that is necessary. |
for (unsigned i = 0; i < count; ++i) { |
NameRecord rec; |
- uint16_t name_length, name_offset; |
+ uint16_t name_length, name_offset = 0; |
if (!table.ReadU16(&rec.platform_id) || |
!table.ReadU16(&rec.encoding_id) || |
!table.ReadU16(&rec.language_id) || |
!table.ReadU16(&rec.name_id) || |
!table.ReadU16(&name_length) || |
!table.ReadU16(&name_offset)) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Failed to read name entry %d", i); |
} |
// check platform & encoding, discard names with unknown values |
switch (rec.platform_id) { |
@@ -166,18 +168,18 @@ bool ots_name_parse(OpenTypeFile* file, const uint8_t* data, size_t length) { |
// extended name table format with language tags |
uint16_t lang_tag_count; |
if (!table.ReadU16(&lang_tag_count)) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Failed to read language tag count"); |
} |
for (unsigned i = 0; i < lang_tag_count; ++i) { |
uint16_t tag_length = 0; |
uint16_t tag_offset = 0; |
if (!table.ReadU16(&tag_length) || !table.ReadU16(&tag_offset)) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Faile to read tag length or offset"); |
} |
const unsigned tag_end = static_cast<unsigned>(string_offset) + |
tag_offset + tag_length; |
if (tag_end > length) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("bad end of tag %d > %ld for name entry %d", tag_end, length, i); |
} |
std::string tag(string_base + tag_offset, tag_length); |
name->lang_tags.push_back(tag); |
@@ -187,7 +189,7 @@ bool ots_name_parse(OpenTypeFile* file, const uint8_t* data, size_t length) { |
if (table.offset() > string_offset) { |
// the string storage apparently overlapped the name/tag records; |
// consider this font to be badly broken |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Bad table offset %ld > %d", table.offset(), string_offset); |
} |
// check existence of required name strings (synthesize if necessary) |
@@ -280,12 +282,12 @@ bool ots_name_serialise(OTSStream* out, OpenTypeFile* file) { |
string_offset += 2 + lang_tag_count * 4; |
} |
if (string_offset > 0xffff) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Bad string offset %ld", string_offset); |
} |
if (!out->WriteU16(format) || |
!out->WriteU16(name_count) || |
!out->WriteU16(static_cast<uint16_t>(string_offset))) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Failed to write name header"); |
} |
std::string string_data; |
@@ -300,14 +302,14 @@ bool ots_name_serialise(OTSStream* out, OpenTypeFile* file) { |
!out->WriteU16(rec.name_id) || |
!out->WriteU16(static_cast<uint16_t>(rec.text.size())) || |
!out->WriteU16(static_cast<uint16_t>(string_data.size())) ) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Faile to write name entry"); |
} |
string_data.append(rec.text); |
} |
if (format == 1) { |
if (!out->WriteU16(lang_tag_count)) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Faile to write language tag count"); |
} |
for (std::vector<std::string>::const_iterator tag_iter = |
name->lang_tags.begin(); |
@@ -316,14 +318,14 @@ bool ots_name_serialise(OTSStream* out, OpenTypeFile* file) { |
std::numeric_limits<uint16_t>::max() || |
!out->WriteU16(static_cast<uint16_t>(tag_iter->size())) || |
!out->WriteU16(static_cast<uint16_t>(string_data.size()))) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Failed to write string"); |
} |
string_data.append(*tag_iter); |
} |
} |
if (!out->Write(string_data.data(), string_data.size())) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Faile to write string data"); |
} |
return true; |
@@ -334,3 +336,5 @@ void ots_name_free(OpenTypeFile* file) { |
} |
} // namespace |
+ |
+#undef TABLE_NAME |