Backed out 7 changesets (bug 1839993) for causing build bustages on DecoderTemplate...
[gecko.git] / modules / woff2 / src / woff2_decompress.cc
blob47394781ad3d507f7d20da75ed97108eb9ca84a3
1 /* Copyright 2013 Google Inc. All Rights Reserved.
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
7 /* A very simple commandline tool for decompressing woff2 format files to true
8 type font files. */
10 #include <string>
12 #include "./file.h"
13 #include <woff2/decode.h>
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;
22 std::string filename(argv[1]);
23 std::string outfilename = filename.substr(0, filename.find_last_of(".")) + ".ttf";
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);
34 const bool ok = woff2::ConvertWOFF2ToTTF(raw_input, input.size(), &out);
36 if (ok) {
37 woff2::SetFileContents(outfilename, output.begin(),
38 output.begin() + out.Size());
40 return ok ? 0 : 1;