Roll src/third_party/WebKit 3529d49:06e8485 (svn 202554:202555)
[chromium-blink-merge.git] / third_party / woff2 / src / woff2_decompress.cc
blob7668c4e824a7ce4a23088374db0447669c93ac9d
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.
15 // A very simple commandline tool for decompressing woff2 format files to true
16 // type font files.
18 #include <string>
21 #include "file.h"
22 #include "./woff2_dec.h"
24 int main(int argc, char **argv) {
25 using std::string;
27 if (argc != 2) {
28 fprintf(stderr, "One argument, the input filename, must be provided.\n");
29 return 1;
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);
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());
45 if (!ok) {
46 fprintf(stderr, "Decompression failed\n");
47 return 1;
50 woff2::SetFileContents(outfilename, output);
52 return 0;