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
3 // found in the LICENSE file.
5 // A very simple driver program while sanitises the file given as argv[1] and
6 // writes the sanitised version to stdout.
14 #endif // defined(_WIN32)
20 #include "file-stream.h"
21 #include "opentype-sanitiser.h"
24 #define ADDITIONAL_OPEN_FLAGS O_BINARY
26 #define ADDITIONAL_OPEN_FLAGS 0
31 int Usage(const char *argv0
) {
32 std::fprintf(stderr
, "Usage: %s ttf_file [dest_ttf_file]\n", argv0
);
36 class Context
: public ots::OTSContext
{
38 virtual void Message(int level
, const char *format
, ...) {
42 std::fprintf(stderr
, "ERROR: ");
44 std::fprintf(stderr
, "WARNING: ");
46 std::vfprintf(stderr
, format
, va
);
47 std::fprintf(stderr
, "\n");
51 virtual ots::TableAction
GetTableAction(uint32_t tag
) {
52 #define TAG(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
54 case TAG('S','i','l','f'):
55 case TAG('S','i','l','l'):
56 case TAG('G','l','o','c'):
57 case TAG('G','l','a','t'):
58 case TAG('F','e','a','t'):
59 return ots::TABLE_ACTION_PASSTHRU
;
61 return ots::TABLE_ACTION_DEFAULT
;
69 int main(int argc
, char **argv
) {
70 if (argc
< 2 || argc
> 3) return Usage(argv
[0]);
72 const int fd
= ::open(argv
[1], O_RDONLY
| ADDITIONAL_OPEN_FLAGS
);
81 uint8_t *data
= new uint8_t[st
.st_size
];
82 if (::read(fd
, data
, st
.st_size
) != st
.st_size
) {
92 out
= fopen(argv
[2], "wb");
94 ots::FILEStream
output(out
);
95 const bool result
= context
.Process(&output
, data
, st
.st_size
);
98 std::fprintf(stderr
, "Failed to sanitise file!\n");