Index: third_party/woff2/src/woff2_enc.cc |
diff --git a/third_party/woff2/src/woff2_enc.cc b/third_party/woff2/src/woff2_enc.cc |
index 39e2ddc61d5a44e2c3962725d11b12314d396a04..bc5238f0dcf3688995b2eaea8f0b5d5e0ddb68fe 100644 |
--- a/third_party/woff2/src/woff2_enc.cc |
+++ b/third_party/woff2/src/woff2_enc.cc |
@@ -23,7 +23,7 @@ |
#include <string> |
#include <vector> |
-#include "./compressor.h" |
+#include "./brotli/encode.h" |
#include "./buffer.h" |
#include "./font.h" |
#include "./normalize.h" |
@@ -47,16 +47,11 @@ using std::vector; |
const size_t kWoff2HeaderSize = 48; |
const size_t kWoff2EntrySize = 20; |
- |
-bool Compress(const uint8_t* data, const size_t len, |
- uint8_t* result, uint32_t* result_len, |
- brotli::BrotliParams::Mode mode, int quality) { |
+bool Compress(const uint8_t* data, const size_t len, uint8_t* result, |
+ uint32_t* result_len, BrotliEncoderMode mode, int quality) { |
size_t compressed_len = *result_len; |
- brotli::BrotliParams params; |
- params.mode = mode; |
- params.quality = quality; |
- if (brotli::BrotliCompressBuffer(params, len, data, &compressed_len, result) |
- == 0) { |
+ if (BrotliEncoderCompress(quality, BROTLI_DEFAULT_WINDOW, mode, len, data, |
+ &compressed_len, result) == 0) { |
return false; |
} |
*result_len = compressed_len; |
@@ -67,14 +62,14 @@ bool Woff2Compress(const uint8_t* data, const size_t len, |
uint8_t* result, uint32_t* result_len, |
int quality) { |
return Compress(data, len, result, result_len, |
- brotli::BrotliParams::MODE_FONT, quality); |
+ BROTLI_MODE_FONT, quality); |
} |
bool TextCompress(const uint8_t* data, const size_t len, |
uint8_t* result, uint32_t* result_len, |
int quality) { |
return Compress(data, len, result, result_len, |
- brotli::BrotliParams::MODE_TEXT, quality); |
+ BROTLI_MODE_TEXT, quality); |
} |
int KnownTableIndex(uint32_t tag) { |
@@ -121,7 +116,7 @@ size_t ComputeWoff2Length(const FontCollection& font_collection, |
} |
// for collections only, collection tables |
- if (font_collection.fonts.size() > 1) { |
+ if (font_collection.flavor == kTtcFontFlavor) { |
size += 4; // UInt32 Version of TTC Header |
size += Size255UShort(font_collection.fonts.size()); // 255UInt16 numFonts |
@@ -161,7 +156,7 @@ size_t ComputeUncompressedLength(const Font& font) { |
} |
size_t ComputeUncompressedLength(const FontCollection& font_collection) { |
- if (font_collection.fonts.size() == 1) { |
+ if (font_collection.flavor != kTtcFontFlavor) { |
return ComputeUncompressedLength(font_collection.fonts[0]); |
} |
size_t size = CollectionHeaderSize(font_collection.header_version, |
@@ -372,13 +367,12 @@ bool ConvertTTFToWOFF2(const uint8_t *data, size_t length, |
} |
*result_length = woff2_length; |
- const Font& first_font = font_collection.fonts[0]; |
size_t offset = 0; |
// start of woff2 header (http://www.w3.org/TR/WOFF2/#woff20Header) |
StoreU32(kWoff2Signature, &offset, result); |
- if (font_collection.fonts.size() == 1) { |
- StoreU32(first_font.flavor, &offset, result); |
+ if (font_collection.flavor != kTtcFontFlavor) { |
+ StoreU32(font_collection.fonts[0].flavor, &offset, result); |
} else { |
StoreU32(kTtcFontFlavor, &offset, result); |
} |
@@ -389,9 +383,9 @@ bool ConvertTTFToWOFF2(const uint8_t *data, size_t length, |
StoreU32(ComputeUncompressedLength(font_collection), &offset, result); |
StoreU32(total_compressed_length, &offset, result); // totalCompressedSize |
- // TODO(user): is always taking this from the first tables head OK? |
- // font revision |
- StoreBytes(first_font.FindTable(kHeadTableTag)->data + 4, 4, &offset, result); |
+ // Let's just all be v1.0 |
+ Store16(1, &offset, result); // majorVersion |
+ Store16(0, &offset, result); // minorVersion |
if (compressed_metadata_buf_length > 0) { |
StoreU32(woff2_length - compressed_metadata_buf_length, |
&offset, result); // metaOffset |
@@ -413,7 +407,7 @@ bool ConvertTTFToWOFF2(const uint8_t *data, size_t length, |
} |
// for collections only, collection table directory |
- if (font_collection.fonts.size() > 1) { |
+ if (font_collection.flavor == kTtcFontFlavor) { |
StoreU32(font_collection.header_version, &offset, result); |
Store255UShort(font_collection.fonts.size(), &offset, result); |
for (const Font& font : font_collection.fonts) { |