| 1 |
/* Copyright 2013 Google Inc. All Rights Reserved. |
| 2 |
|
| 3 |
Distributed under MIT license. |
| 4 |
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
| 5 |
*/ |
| 6 |
|
| 7 |
/* A commandline tool for compressing ttf format files to woff2. */ |
| 8 |
|
| 9 |
#include <string> |
| 10 |
|
| 11 |
#include "file.h" |
| 12 |
#include <woff2/encode.h> |
| 13 |
|
| 14 |
|
| 15 |
int main(int argc, char **argv) { |
| 16 |
using std::string; |
| 17 |
|
| 18 |
if (argc != 2) { |
| 19 |
fprintf(stderr, "One argument, the input filename, must be provided.\n"); |
| 20 |
return 1; |
| 21 |
} |
| 22 |
|
| 23 |
string filename(argv[1]); |
| 24 |
string outfilename = filename.substr(0, filename.find_last_of(".")) + ".woff2"; |
| 25 |
fprintf(stdout, "Processing %s => %s\n", |
| 26 |
filename.c_str(), outfilename.c_str()); |
| 27 |
string input = woff2::GetFileContent(filename); |
| 28 |
|
| 29 |
const uint8_t* input_data = reinterpret_cast<const uint8_t*>(input.data()); |
| 30 |
size_t output_size = woff2::MaxWOFF2CompressedSize(input_data, input.size()); |
| 31 |
string output(output_size, 0); |
| 32 |
uint8_t* output_data = reinterpret_cast<uint8_t*>(&output[0]); |
| 33 |
|
| 34 |
woff2::WOFF2Params params; |
| 35 |
if (!woff2::ConvertTTFToWOFF2(input_data, input.size(), |
| 36 |
output_data, &output_size, params)) { |
| 37 |
fprintf(stderr, "Compression failed.\n"); |
| 38 |
return 1; |
| 39 |
} |
| 40 |
output.resize(output_size); |
| 41 |
|
| 42 |
woff2::SetFileContents(outfilename, output.begin(), output.end()); |
| 43 |
|
| 44 |
return 0; |
| 45 |
} |