Allow WOFF2Params to specify no transformations at all

This commit is contained in:
Rod Sheeter
2016-01-28 11:36:18 -08:00
parent 14f4cb67ec
commit bdf886a06b
3 changed files with 18 additions and 3 deletions
+2 -1
View File
@@ -39,8 +39,9 @@ int main(int argc, char **argv) {
string output(output_size, 0); string output(output_size, 0);
uint8_t* output_data = reinterpret_cast<uint8_t*>(&output[0]); uint8_t* output_data = reinterpret_cast<uint8_t*>(&output[0]);
woff2::WOFF2Params params;
if (!woff2::ConvertTTFToWOFF2(input_data, input.size(), if (!woff2::ConvertTTFToWOFF2(input_data, input.size(),
output_data, &output_size)) { output_data, &output_size, params)) {
fprintf(stderr, "Compression failed.\n"); fprintf(stderr, "Compression failed.\n");
return 1; return 1;
} }
+13 -1
View File
@@ -249,8 +249,20 @@ bool ConvertTTFToWOFF2(const uint8_t *data, size_t length,
return FONT_COMPRESSION_FAILURE(); return FONT_COMPRESSION_FAILURE();
} }
if (!TransformFontCollection(&font_collection)) { if (params.allow_transforms && !TransformFontCollection(&font_collection)) {
return FONT_COMPRESSION_FAILURE(); 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 // Although the compressed size of each table in the final woff2 file won't
+3 -1
View File
@@ -27,10 +27,12 @@ using std::string;
namespace woff2 { namespace woff2 {
struct WOFF2Params { struct WOFF2Params {
WOFF2Params() : extended_metadata(""), brotli_quality(11) {} WOFF2Params() : extended_metadata(""), brotli_quality(11),
allow_transforms(true) {}
string extended_metadata; string extended_metadata;
int brotli_quality; int brotli_quality;
bool allow_transforms;
}; };
// Returns an upper bound on the size of the compressed file. // Returns an upper bound on the size of the compressed file.