Index: src/ltsh.cc |
diff --git a/src/ltsh.cc b/src/ltsh.cc |
old mode 100644 |
new mode 100755 |
index 16700daa7ab33cd2120648af5d051e48b9a223a9..9532b4b34179e20ce22a2c4c6b3cfe24ae1c7c54 |
--- a/src/ltsh.cc |
+++ b/src/ltsh.cc |
@@ -9,8 +9,15 @@ |
// LTSH - Linear Threshold |
// http://www.microsoft.com/typography/otspec/ltsh.htm |
-#define DROP_THIS_TABLE \ |
- do { delete file->ltsh; file->ltsh = 0; } while (0) |
+#define TABLE_NAME "LTSH" |
+ |
+#define DROP_THIS_TABLE(...) \ |
+ do { \ |
+ delete file->ltsh; \ |
+ file->ltsh = 0; \ |
+ OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \ |
+ OTS_FAILURE_MSG("Table discarded"); \ |
+ } while (0) |
namespace ots { |
@@ -18,7 +25,7 @@ bool ots_ltsh_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
Buffer table(data, length); |
if (!file->maxp) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Missing maxp table from font needed by ltsh"); |
} |
OpenTypeLTSH *ltsh = new OpenTypeLTSH; |
@@ -27,18 +34,16 @@ bool ots_ltsh_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
uint16_t num_glyphs = 0; |
if (!table.ReadU16(<sh->version) || |
!table.ReadU16(&num_glyphs)) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Failed to read ltsh header"); |
} |
if (ltsh->version != 0) { |
- OTS_WARNING("bad version: %u", ltsh->version); |
- DROP_THIS_TABLE; |
+ DROP_THIS_TABLE("bad version: %u", ltsh->version); |
return true; |
} |
if (num_glyphs != file->maxp->num_glyphs) { |
- OTS_WARNING("bad num_glyphs: %u", num_glyphs); |
- DROP_THIS_TABLE; |
+ DROP_THIS_TABLE("bad num_glyphs: %u", num_glyphs); |
return true; |
} |
@@ -46,7 +51,7 @@ bool ots_ltsh_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
for (unsigned i = 0; i < num_glyphs; ++i) { |
uint8_t pel = 0; |
if (!table.ReadU8(&pel)) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Failed to read pixels for glyph %d", i); |
} |
ltsh->ypels.push_back(pel); |
} |
@@ -61,15 +66,16 @@ bool ots_ltsh_should_serialise(OpenTypeFile *file) { |
bool ots_ltsh_serialise(OTSStream *out, OpenTypeFile *file) { |
const OpenTypeLTSH *ltsh = file->ltsh; |
+ |
const uint16_t num_ypels = static_cast<uint16_t>(ltsh->ypels.size()); |
if (num_ypels != ltsh->ypels.size() || |
!out->WriteU16(ltsh->version) || |
!out->WriteU16(num_ypels)) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Failed to write pels size"); |
} |
for (uint16_t i = 0; i < num_ypels; ++i) { |
if (!out->Write(&(ltsh->ypels[i]), 1)) { |
- return OTS_FAILURE(); |
+ return OTS_FAILURE_MSG("Failed to write pixel size for glyph %d", i); |
} |
} |
@@ -81,3 +87,6 @@ void ots_ltsh_free(OpenTypeFile *file) { |
} |
} // namespace ots |
+ |
+#undef TABLE_NAME |
+#undef DROP_THIS_TABLE |