Merge pull request #43 from google/hmtx

Tweaks requested by @fred-wang; null transform support
This commit is contained in:
rsheeter
2016-01-28 11:38:36 -08:00
4 changed files with 19 additions and 5 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;
} }
+1 -2
View File
@@ -24,7 +24,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
#include <unordered_set>
#include <memory> #include <memory>
#include "./buffer.h" #include "./buffer.h"
@@ -1317,7 +1316,7 @@ bool ConvertWOFF2ToTTF(uint8_t* result, size_t result_length,
transform_length) > result_length)) { transform_length) > result_length)) {
return FONT_COMPRESSION_FAILURE(); 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); src_by_dest.erase(table->dst_offset);
std::memcpy(result + table->dst_offset, transform_buf, transform_length); std::memcpy(result + table->dst_offset, transform_buf, transform_length);
} }
+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.