woff2_decompress.cc (1202B)
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 if (argc != 2) { 18 fprintf(stderr, "One argument, the input filename, must be provided.\n"); 19 return 1; 20 } 21 22 std::string filename(argv[1]); 23 std::string outfilename = filename.substr(0, filename.find_last_of(".")) + ".ttf"; 24 25 // Note: update woff2_dec_fuzzer_new_entry.cc if this pattern changes. 26 std::string input = woff2::GetFileContent(filename); 27 const uint8_t* raw_input = reinterpret_cast<const uint8_t*>(input.data()); 28 std::string output( 29 std::min(woff2::ComputeWOFF2FinalSize(raw_input, input.size()), 30 woff2::kDefaultMaxSize), 31 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 }