From 14f4cb67ec78b716bf72b19c43800a11f6af949a Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Thu, 28 Jan 2016 11:34:31 -0800 Subject: [PATCH 1/2] Tweaks requested by @fred-wang to help Mozilla build --- src/woff2_dec.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/woff2_dec.cc b/src/woff2_dec.cc index fff4aaa..85d307e 100644 --- a/src/woff2_dec.cc +++ b/src/woff2_dec.cc @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "./buffer.h" @@ -1317,7 +1316,7 @@ bool ConvertWOFF2ToTTF(uint8_t* result, size_t result_length, transform_length) > result_length)) { return FONT_COMPRESSION_FAILURE(); } - transform_buf = src_by_dest.at(table->dst_offset); + transform_buf = src_by_dest[table->dst_offset]; src_by_dest.erase(table->dst_offset); std::memcpy(result + table->dst_offset, transform_buf, transform_length); } From bdf886a06b5a2107cae5a17694ce36b64947b98f Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Thu, 28 Jan 2016 11:36:18 -0800 Subject: [PATCH 2/2] Allow WOFF2Params to specify no transformations at all --- src/woff2_compress.cc | 3 ++- src/woff2_enc.cc | 14 +++++++++++++- src/woff2_enc.h | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/woff2_compress.cc b/src/woff2_compress.cc index 057566f..ec41ad5 100644 --- a/src/woff2_compress.cc +++ b/src/woff2_compress.cc @@ -39,8 +39,9 @@ int main(int argc, char **argv) { string output(output_size, 0); uint8_t* output_data = reinterpret_cast(&output[0]); + woff2::WOFF2Params params; if (!woff2::ConvertTTFToWOFF2(input_data, input.size(), - output_data, &output_size)) { + output_data, &output_size, params)) { fprintf(stderr, "Compression failed.\n"); return 1; } diff --git a/src/woff2_enc.cc b/src/woff2_enc.cc index 3729ae0..5255aa5 100644 --- a/src/woff2_enc.cc +++ b/src/woff2_enc.cc @@ -249,8 +249,20 @@ bool ConvertTTFToWOFF2(const uint8_t *data, size_t length, return FONT_COMPRESSION_FAILURE(); } - if (!TransformFontCollection(&font_collection)) { + if (params.allow_transforms && !TransformFontCollection(&font_collection)) { return FONT_COMPRESSION_FAILURE(); + } else { + // glyf/loca use 11 to flag "not transformed" + for (auto& font : font_collection.fonts) { + Font::Table* glyf_table = font.FindTable(kGlyfTableTag); + Font::Table* loca_table = font.FindTable(kLocaTableTag); + if (glyf_table) { + glyf_table->flag_byte |= 0xc0; + } + if (loca_table) { + loca_table->flag_byte |= 0xc0; + } + } } // Although the compressed size of each table in the final woff2 file won't diff --git a/src/woff2_enc.h b/src/woff2_enc.h index a1caf3f..3ac8c3a 100644 --- a/src/woff2_enc.h +++ b/src/woff2_enc.h @@ -27,10 +27,12 @@ using std::string; namespace woff2 { struct WOFF2Params { - WOFF2Params() : extended_metadata(""), brotli_quality(11) {} + WOFF2Params() : extended_metadata(""), brotli_quality(11), + allow_transforms(true) {} string extended_metadata; int brotli_quality; + bool allow_transforms; }; // Returns an upper bound on the size of the compressed file.