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