| Index: src/hdmx.cc
|
| diff --git a/src/hdmx.cc b/src/hdmx.cc
|
| old mode 100644
|
| new mode 100755
|
| index 570fab1682b2d38cb8623240f3b4beeee273bd5d..0e37724974354838f13968ac58a501d9f1937cc8
|
| --- a/src/hdmx.cc
|
| +++ b/src/hdmx.cc
|
| @@ -7,10 +7,17 @@
|
| #include "maxp.h"
|
|
|
| // hdmx - Horizontal Device Metrics
|
| -// http://www.microsoft.com/opentype/otspec/hdmx.htm
|
| +// http://www.microsoft.com/typography/otspec/hdmx.htm
|
|
|
| -#define DROP_THIS_TABLE \
|
| - do { delete file->hdmx; file->hdmx = 0; } while (0)
|
| +#define TABLE_NAME "hdmx"
|
| +
|
| +#define DROP_THIS_TABLE(...) \
|
| + do { \
|
| + delete file->hdmx; \
|
| + file->hdmx = 0; \
|
| + OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
|
| + OTS_FAILURE_MSG("Table discarded"); \
|
| + } while (0)
|
|
|
| namespace ots {
|
|
|
| @@ -20,14 +27,13 @@ bool ots_hdmx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
|
| OpenTypeHDMX * const hdmx = file->hdmx;
|
|
|
| if (!file->head || !file->maxp) {
|
| - return OTS_FAILURE();
|
| + return OTS_FAILURE_MSG("Missing maxp or head tables in font, needed by hdmx");
|
| }
|
|
|
| if ((file->head->flags & 0x14) == 0) {
|
| // http://www.microsoft.com/typography/otspec/recom.htm
|
| - OTS_WARNING("the table should not be present when bit 2 and 4 of the "
|
| - "head->flags are not set");
|
| - DROP_THIS_TABLE;
|
| + DROP_THIS_TABLE("the table should not be present when bit 2 and 4 of the "
|
| + "head->flags are not set");
|
| return true;
|
| }
|
|
|
| @@ -35,28 +41,25 @@ bool ots_hdmx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
|
| if (!table.ReadU16(&hdmx->version) ||
|
| !table.ReadS16(&num_recs) ||
|
| !table.ReadS32(&hdmx->size_device_record)) {
|
| - return OTS_FAILURE();
|
| + return OTS_FAILURE_MSG("Failed to read hdmx header");
|
| }
|
| if (hdmx->version != 0) {
|
| - OTS_WARNING("bad version: %u", hdmx->version);
|
| - DROP_THIS_TABLE;
|
| + DROP_THIS_TABLE("bad version: %u", hdmx->version);
|
| return true;
|
| }
|
| if (num_recs <= 0) {
|
| - OTS_WARNING("bad num_recs: %d", num_recs);
|
| - DROP_THIS_TABLE;
|
| + DROP_THIS_TABLE("bad num_recs: %d", num_recs);
|
| return true;
|
| }
|
| const int32_t actual_size_device_record = file->maxp->num_glyphs + 2;
|
| if (hdmx->size_device_record < actual_size_device_record) {
|
| - OTS_WARNING("bad hdmx->size_device_record: %d", hdmx->size_device_record);
|
| - DROP_THIS_TABLE;
|
| + DROP_THIS_TABLE("bad hdmx->size_device_record: %d", hdmx->size_device_record);
|
| return true;
|
| }
|
|
|
| hdmx->pad_len = hdmx->size_device_record - actual_size_device_record;
|
| if (hdmx->pad_len > 3) {
|
| - return OTS_FAILURE();
|
| + return OTS_FAILURE_MSG("Bad padding %d", hdmx->pad_len);
|
| }
|
|
|
| uint8_t last_pixel_size = 0;
|
| @@ -66,12 +69,11 @@ bool ots_hdmx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
|
|
|
| if (!table.ReadU8(&rec.pixel_size) ||
|
| !table.ReadU8(&rec.max_width)) {
|
| - return OTS_FAILURE();
|
| + return OTS_FAILURE_MSG("Failed to read hdmx record %d", i);
|
| }
|
| if ((i != 0) &&
|
| (rec.pixel_size <= last_pixel_size)) {
|
| - OTS_WARNING("records are not sorted");
|
| - DROP_THIS_TABLE;
|
| + DROP_THIS_TABLE("records are not sorted");
|
| return true;
|
| }
|
| last_pixel_size = rec.pixel_size;
|
| @@ -80,14 +82,14 @@ bool ots_hdmx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
|
| for (unsigned j = 0; j < file->maxp->num_glyphs; ++j) {
|
| uint8_t width;
|
| if (!table.ReadU8(&width)) {
|
| - return OTS_FAILURE();
|
| + return OTS_FAILURE_MSG("Failed to read glyph width %d in record %d", j, i);
|
| }
|
| rec.widths.push_back(width);
|
| }
|
|
|
| if ((hdmx->pad_len > 0) &&
|
| !table.Skip(hdmx->pad_len)) {
|
| - return OTS_FAILURE();
|
| + return OTS_FAILURE_MSG("Failed to skip padding %d", hdmx->pad_len);
|
| }
|
|
|
| hdmx->records.push_back(rec);
|
| @@ -111,7 +113,7 @@ bool ots_hdmx_serialise(OTSStream *out, OpenTypeFile *file) {
|
| !out->WriteU16(hdmx->version) ||
|
| !out->WriteS16(num_recs) ||
|
| !out->WriteS32(hdmx->size_device_record)) {
|
| - return OTS_FAILURE();
|
| + return OTS_FAILURE_MSG("Failed to write hdmx header");
|
| }
|
|
|
| for (int16_t i = 0; i < num_recs; ++i) {
|
| @@ -119,11 +121,11 @@ bool ots_hdmx_serialise(OTSStream *out, OpenTypeFile *file) {
|
| if (!out->Write(&rec.pixel_size, 1) ||
|
| !out->Write(&rec.max_width, 1) ||
|
| !out->Write(&rec.widths[0], rec.widths.size())) {
|
| - return OTS_FAILURE();
|
| + return OTS_FAILURE_MSG("Failed to write hdmx record %d", i);
|
| }
|
| if ((hdmx->pad_len > 0) &&
|
| !out->Write((const uint8_t *)"\x00\x00\x00", hdmx->pad_len)) {
|
| - return OTS_FAILURE();
|
| + return OTS_FAILURE_MSG("Failed to write hdmx padding of length %d", hdmx->pad_len);
|
| }
|
| }
|
|
|
| @@ -135,3 +137,6 @@ void ots_hdmx_free(OpenTypeFile *file) {
|
| }
|
|
|
| } // namespace ots
|
| +
|
| +#undef TABLE_NAME
|
| +#undef DROP_THIS_TABLE
|
|
|