| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // A very simple driver program while sanitises the file given as argv[1] and | 5 // A very simple driver program while sanitises the file given as argv[1] and |
| 6 // writes the sanitised version to stdout. | 6 // writes the sanitised version to stdout. |
| 7 | 7 |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #if defined(_WIN32) | 10 #if defined(_WIN32) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 std::fprintf(stderr, "Usage: %s ttf_file > dest_ttf_file\n", argv0); | 31 std::fprintf(stderr, "Usage: %s ttf_file > dest_ttf_file\n", argv0); |
| 32 return 1; | 32 return 1; |
| 33 } | 33 } |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 int main(int argc, char **argv) { | 37 int main(int argc, char **argv) { |
| 38 if (argc != 2) return Usage(argv[0]); | 38 if (argc != 2) return Usage(argv[0]); |
| 39 if (::isatty(1)) return Usage(argv[0]); | 39 if (::isatty(1)) return Usage(argv[0]); |
| 40 | 40 |
| 41 ots::EnableWOFF2(); |
| 42 |
| 41 const int fd = ::open(argv[1], O_RDONLY | ADDITIONAL_OPEN_FLAGS); | 43 const int fd = ::open(argv[1], O_RDONLY | ADDITIONAL_OPEN_FLAGS); |
| 42 if (fd < 0) { | 44 if (fd < 0) { |
| 43 ::perror("open"); | 45 ::perror("open"); |
| 44 return 1; | 46 return 1; |
| 45 } | 47 } |
| 46 | 48 |
| 47 struct stat st; | 49 struct stat st; |
| 48 ::fstat(fd, &st); | 50 ::fstat(fd, &st); |
| 49 | 51 |
| 50 uint8_t *data = new uint8_t[st.st_size]; | 52 uint8_t *data = new uint8_t[st.st_size]; |
| 51 if (::read(fd, data, st.st_size) != st.st_size) { | 53 if (::read(fd, data, st.st_size) != st.st_size) { |
| 52 ::perror("read"); | 54 ::perror("read"); |
| 53 return 1; | 55 return 1; |
| 54 } | 56 } |
| 55 ::close(fd); | 57 ::close(fd); |
| 56 | 58 |
| 57 ots::FILEStream output(stdout); | 59 ots::FILEStream output(stdout); |
| 58 #if defined(_WIN32) | 60 #if defined(_WIN32) |
| 59 ::setmode(fileno(stdout), O_BINARY); | 61 ::setmode(fileno(stdout), O_BINARY); |
| 60 #endif | 62 #endif |
| 61 const bool result = ots::Process(&output, data, st.st_size); | 63 const bool result = ots::Process(&output, data, st.st_size); |
| 62 | 64 |
| 63 if (!result) { | 65 if (!result) { |
| 64 std::fprintf(stderr, "Failed to sanitise file!\n"); | 66 std::fprintf(stderr, "Failed to sanitise file!\n"); |
| 65 } | 67 } |
| 66 return !result; | 68 return !result; |
| 67 } | 69 } |
| OLD | NEW |