Specification updates: known table tags, reserved flag bits, always preprocess
This commit is contained in:
+46
-17
@@ -772,7 +772,7 @@ bool ReadLongDirectory(ots::Buffer* file, std::vector<Table>* tables,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t known_tags[29] = {
|
const uint32_t known_tags[63] = {
|
||||||
TAG('c', 'm', 'a', 'p'), // 0
|
TAG('c', 'm', 'a', 'p'), // 0
|
||||||
TAG('h', 'e', 'a', 'd'), // 1
|
TAG('h', 'e', 'a', 'd'), // 1
|
||||||
TAG('h', 'h', 'e', 'a'), // 2
|
TAG('h', 'h', 'e', 'a'), // 2
|
||||||
@@ -802,13 +802,47 @@ const uint32_t known_tags[29] = {
|
|||||||
TAG('G', 'D', 'E', 'F'), // 26
|
TAG('G', 'D', 'E', 'F'), // 26
|
||||||
TAG('G', 'P', 'O', 'S'), // 27
|
TAG('G', 'P', 'O', 'S'), // 27
|
||||||
TAG('G', 'S', 'U', 'B'), // 28
|
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) {
|
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;
|
if (tag == known_tags[i]) return i;
|
||||||
}
|
}
|
||||||
return 31;
|
return 63;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadShortDirectory(ots::Buffer* file, std::vector<Table>* tables,
|
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();
|
return OTS_FAILURE();
|
||||||
}
|
}
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
if ((flag_byte & 0x1f) == 0x1f) {
|
if ((flag_byte & 0x3f) == 0x3f) {
|
||||||
if (!file->ReadU32(&tag)) {
|
if (!file->ReadU32(&tag)) {
|
||||||
return OTS_FAILURE();
|
return OTS_FAILURE();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((flag_byte & 0x1f) >= (sizeof(known_tags) / sizeof(known_tags[0]))) {
|
tag = known_tags[flag_byte & 0x3f];
|
||||||
return OTS_FAILURE();
|
|
||||||
}
|
}
|
||||||
tag = known_tags[flag_byte & 0x1f];
|
// Bits 6 and 7 are reserved and must be 0.
|
||||||
}
|
if ((flag_byte & 0xC0) != 0) {
|
||||||
// Bits 5 and 6 are reserved and must be 0.
|
|
||||||
if ((flag_byte & 0x60) != 0) {
|
|
||||||
return OTS_FAILURE();
|
return OTS_FAILURE();
|
||||||
}
|
}
|
||||||
uint32_t flags = kCompressionTypeBrotli;
|
uint32_t flags = kCompressionTypeBrotli;
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
flags |= kWoff2FlagsContinueStream;
|
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;
|
flags |= kWoff2FlagsTransform;
|
||||||
}
|
}
|
||||||
uint32_t dst_length;
|
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) {
|
void StoreTableEntry(const Table& table, size_t* offset, uint8_t* dst) {
|
||||||
uint8_t flag_byte = KnownTableIndex(table.tag);
|
uint8_t flag_byte = KnownTableIndex(table.tag);
|
||||||
if ((table.flags & kWoff2FlagsTransform) != 0) {
|
|
||||||
flag_byte |= 0x80;
|
|
||||||
}
|
|
||||||
dst[(*offset)++] = flag_byte;
|
dst[(*offset)++] = flag_byte;
|
||||||
if ((flag_byte & 0x1f) == 0x1f) {
|
if ((flag_byte & 0x3f) == 0x3f) {
|
||||||
StoreU32(table.tag, offset, dst);
|
StoreU32(table.tag, offset, dst);
|
||||||
}
|
}
|
||||||
StoreBase128(table.src_length, offset, dst);
|
StoreBase128(table.src_length, offset, dst);
|
||||||
if ((flag_byte & 0x80) != 0) {
|
if ((table.flags & kWoff2FlagsTransform) != 0) {
|
||||||
StoreBase128(table.transform_length, offset, dst);
|
StoreBase128(table.transform_length, offset, dst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1123,7 +1153,6 @@ size_t MaxWOFF2CompressedSize(const uint8_t* data, size_t length) {
|
|||||||
|
|
||||||
bool ConvertTTFToWOFF2(const uint8_t *data, size_t length,
|
bool ConvertTTFToWOFF2(const uint8_t *data, size_t length,
|
||||||
uint8_t *result, size_t *result_length) {
|
uint8_t *result, size_t *result_length) {
|
||||||
|
|
||||||
Woff2ConvertOptions options;
|
Woff2ConvertOptions options;
|
||||||
|
|
||||||
Font font;
|
Font font;
|
||||||
|
|||||||
@@ -43,8 +43,6 @@ size_t MaxWOFF2CompressedSize(const uint8_t* data, size_t length);
|
|||||||
bool ConvertTTFToWOFF2(const uint8_t *data, size_t length,
|
bool ConvertTTFToWOFF2(const uint8_t *data, size_t length,
|
||||||
uint8_t *result, size_t *result_length);
|
uint8_t *result, size_t *result_length);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace woff2
|
} // namespace woff2
|
||||||
|
|
||||||
#endif // WOFF2_WOFF2_H_
|
#endif // WOFF2_WOFF2_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user