| 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 very simple commandline tool for decompressing woff2 format files to true |
| 8 |
type font files. */ |
| 9 |
|
| 10 |
#include <string> |
| 11 |
|
| 12 |
#include "./file.h" |
| 13 |
#include <woff2/decode.h> |
| 14 |
|
| 15 |
|
| 16 |
int main(int argc, char **argv) { |
| 17 |
using std::string; |
| 18 |
|
| 19 |
if (argc != 2) { |
| 20 |
fprintf(stderr, "One argument, the input filename, must be provided.\n"); |
| 21 |
return 1; |
| 22 |
} |
| 23 |
|
| 24 |
string filename(argv[1]); |
| 25 |
string outfilename = filename.substr(0, filename.find_last_of(".")) + ".ttf"; |
| 26 |
|
| 27 |
// Note: update woff2_dec_fuzzer_new_entry.cc if this pattern changes. |
| 28 |
string input = woff2::GetFileContent(filename); |
| 29 |
const uint8_t* raw_input = reinterpret_cast<const uint8_t*>(input.data()); |
| 30 |
string output(std::min(woff2::ComputeWOFF2FinalSize(raw_input, input.size()), |
| 31 |
woff2::kDefaultMaxSize), 0); |
| 32 |
woff2::WOFF2StringOut out(&output); |
| 33 |
|
| 34 |
const bool ok = woff2::ConvertWOFF2ToTTF(raw_input, input.size(), &out); |
| 35 |
|
| 36 |
if (ok) { |
| 37 |
woff2::SetFileContents(outfilename, output.begin(), |
| 38 |
output.begin() + out.Size()); |
| 39 |
} |
| 40 |
return ok ? 0 : 1; |
| 41 |
} |