diff options
author | David Kuettel <kuettel@google.com> | 2014-04-29 17:47:03 -0700 |
---|---|---|
committer | David Kuettel <kuettel@google.com> | 2014-04-29 17:47:03 -0700 |
commit | 47c5016d7f20363602601aa2624229482b5c2e50 (patch) | |
tree | cf0bd80342be4cd8cf2a1e78a70ddfb0066bfb36 | |
parent | 05b3775ecbd31f3a8a4f9ff5a3afe72a926db447 (diff) | |
download | src-47c5016d7f20363602601aa2624229482b5c2e50.tar.gz |
Specification updates: known table tags, reserved flag bits, always preprocess
-rw-r--r-- | woff2/woff2.cc | 65 | ||||
-rw-r--r-- | woff2/woff2.h | 2 |
2 files changed, 47 insertions, 20 deletions
diff --git a/woff2/woff2.cc b/woff2/woff2.cc index 5468280..9c3e34e 100644 --- a/woff2/woff2.cc +++ b/woff2/woff2.cc @@ -772,7 +772,7 @@ bool ReadLongDirectory(ots::Buffer* file, std::vector<Table>* tables, return true; } -const uint32_t known_tags[29] = { +const uint32_t known_tags[63] = { TAG('c', 'm', 'a', 'p'), // 0 TAG('h', 'e', 'a', 'd'), // 1 TAG('h', 'h', 'e', 'a'), // 2 @@ -802,13 +802,47 @@ const uint32_t known_tags[29] = { TAG('G', 'D', 'E', 'F'), // 26 TAG('G', 'P', 'O', 'S'), // 27 TAG('G', 'S', 'U', 'B'), // 28 + TAG('E', 'B', 'S', 'C'), // 29 + TAG('J', 'S', 'T', 'F'), // 30 + TAG('M', 'A', 'T', 'H'), // 31 + TAG('C', 'B', 'D', 'T'), // 32 + TAG('C', 'B', 'L', 'C'), // 33 + TAG('C', 'O', 'L', 'R'), // 34 + TAG('C', 'P', 'A', 'L'), // 35 + TAG('S', 'V', 'G', ' '), // 36 + TAG('s', 'b', 'i', 'x'), // 37 + TAG('a', 'c', 'n', 't'), // 38 + TAG('a', 'v', 'a', 'r'), // 39 + TAG('b', 'd', 'a', 't'), // 40 + TAG('b', 'l', 'o', 'c'), // 41 + TAG('b', 's', 'l', 'n'), // 42 + TAG('c', 'v', 'a', 'r'), // 43 + TAG('f', 'd', 's', 'c'), // 44 + TAG('f', 'e', 'a', 't'), // 45 + TAG('f', 'm', 't', 'x'), // 46 + TAG('f', 'v', 'a', 'r'), // 47 + TAG('g', 'v', 'a', 'r'), // 48 + TAG('h', 's', 't', 'y'), // 49 + TAG('j', 'u', 's', 't'), // 50 + TAG('l', 'c', 'a', 'r'), // 51 + TAG('m', 'o', 'r', 't'), // 52 + TAG('m', 'o', 'r', 'x'), // 53 + TAG('o', 'p', 'b', 'd'), // 54 + TAG('p', 'r', 'o', 'p'), // 55 + TAG('t', 'r', 'a', 'k'), // 56 + TAG('Z', 'a', 'p', 'f'), // 57 + TAG('S', 'i', 'l', 'f'), // 58 + TAG('G', 'l', 'a', 't'), // 59 + TAG('G', 'l', 'o', 'c'), // 60 + TAG('F', 'e', 'a', 't'), // 61 + TAG('S', 'i', 'l', 'l'), // 62 }; int KnownTableIndex(uint32_t tag) { - for (int i = 0; i < 29; ++i) { + for (int i = 0; i < 63; ++i) { if (tag == known_tags[i]) return i; } - return 31; + return 63; } bool ReadShortDirectory(ots::Buffer* file, std::vector<Table>* tables, @@ -820,25 +854,24 @@ bool ReadShortDirectory(ots::Buffer* file, std::vector<Table>* tables, return OTS_FAILURE(); } uint32_t tag; - if ((flag_byte & 0x1f) == 0x1f) { + if ((flag_byte & 0x3f) == 0x3f) { if (!file->ReadU32(&tag)) { return OTS_FAILURE(); } } else { - if ((flag_byte & 0x1f) >= (sizeof(known_tags) / sizeof(known_tags[0]))) { - return OTS_FAILURE(); - } - tag = known_tags[flag_byte & 0x1f]; + tag = known_tags[flag_byte & 0x3f]; } - // Bits 5 and 6 are reserved and must be 0. - if ((flag_byte & 0x60) != 0) { + // Bits 6 and 7 are reserved and must be 0. + if ((flag_byte & 0xC0) != 0) { return OTS_FAILURE(); } uint32_t flags = kCompressionTypeBrotli; if (i > 0) { flags |= kWoff2FlagsContinueStream; } - if ((flag_byte & 0x80) != 0) { + // Always transform the glyf and loca tables + if (tag == TAG('g', 'l', 'y', 'f') || + tag == TAG('l', 'o', 'c', 'a')) { flags |= kWoff2FlagsTransform; } uint32_t dst_length; @@ -1043,15 +1076,12 @@ bool ConvertWOFF2ToTTF(uint8_t* result, size_t result_length, void StoreTableEntry(const Table& table, size_t* offset, uint8_t* dst) { uint8_t flag_byte = KnownTableIndex(table.tag); - if ((table.flags & kWoff2FlagsTransform) != 0) { - flag_byte |= 0x80; - } dst[(*offset)++] = flag_byte; - if ((flag_byte & 0x1f) == 0x1f) { + if ((flag_byte & 0x3f) == 0x3f) { StoreU32(table.tag, offset, dst); } StoreBase128(table.src_length, offset, dst); - if ((flag_byte & 0x80) != 0) { + if ((table.flags & kWoff2FlagsTransform) != 0) { StoreBase128(table.transform_length, offset, dst); } } @@ -1060,7 +1090,7 @@ size_t TableEntrySize(const Table& table) { size_t size = KnownTableIndex(table.tag) < 31 ? 1 : 5; size += Base128Size(table.src_length); if ((table.flags & kWoff2FlagsTransform) != 0) { - size += Base128Size(table.transform_length); + size += Base128Size(table.transform_length); } return size; } @@ -1123,7 +1153,6 @@ size_t MaxWOFF2CompressedSize(const uint8_t* data, size_t length) { bool ConvertTTFToWOFF2(const uint8_t *data, size_t length, uint8_t *result, size_t *result_length) { - Woff2ConvertOptions options; Font font; diff --git a/woff2/woff2.h b/woff2/woff2.h index 2e4ee25..6b198fb 100644 --- a/woff2/woff2.h +++ b/woff2/woff2.h @@ -43,8 +43,6 @@ size_t MaxWOFF2CompressedSize(const uint8_t* data, size_t length); bool ConvertTTFToWOFF2(const uint8_t *data, size_t length, uint8_t *result, size_t *result_length); - - } // namespace woff2 #endif // WOFF2_WOFF2_H_ |