1// Copyright 2013 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// A very simple commandline tool for decompressing woff2 format files to true
16// type font files.
17
18#include <string>
19
20
21#include "file.h"
22#include "./woff2_dec.h"
23
24int main(int argc, char **argv) {
25  using std::string;
26
27  if (argc != 2) {
28    fprintf(stderr, "One argument, the input filename, must be provided.\n");
29    return 1;
30  }
31
32  string filename(argv[1]);
33  string outfilename = filename.substr(0, filename.find_last_of(".")) + ".ttf";
34  fprintf(stdout, "Processing %s => %s\n",
35    filename.c_str(), outfilename.c_str());
36  string input = woff2::GetFileContent(filename);
37
38  size_t decompressed_size = woff2::ComputeWOFF2FinalSize(
39      reinterpret_cast<const uint8_t*>(input.data()), input.size());
40  string output(decompressed_size, 0);
41  const bool ok = woff2::ConvertWOFF2ToTTF(
42      reinterpret_cast<uint8_t*>(&output[0]), decompressed_size,
43      reinterpret_cast<const uint8_t*>(input.data()), input.size());
44
45  if (!ok) {
46    fprintf(stderr, "Decompression failed\n");
47    return 1;
48  }
49
50  woff2::SetFileContents(outfilename, output);
51
52  return 0;
53}
54
55