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 #include "ots.h" | 5 #include "ots.h" |
6 | 6 |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <zlib.h> | 8 #include <zlib.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <cstdlib> | 11 #include <cstdlib> |
12 #include <cstring> | 12 #include <cstring> |
13 #include <limits> | 13 #include <limits> |
14 #include <map> | 14 #include <map> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "woff2.h" | 17 #include "woff2.h" |
18 | 18 |
19 // The OpenType Font File | 19 // The OpenType Font File |
20 // http://www.microsoft.com/typography/otspec/cmap.htm | 20 // http://www.microsoft.com/typography/otspec/cmap.htm |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Generate a message with or without a table tag, when 'header' is the OpenType
File pointer | 24 // Generate a message with or without a table tag, when 'header' is the OpenType
File pointer |
25 #define OTS_FAILURE_MSG_TAG(msg_,tag_) OTS_FAILURE_MSG_TAG_(header, msg_, tag_) | 25 #define OTS_FAILURE_MSG_TAG(msg_,tag_) OTS_FAILURE_MSG_TAG_(header, msg_, tag_) |
26 #define OTS_FAILURE_MSG_HDR(msg_) OTS_FAILURE_MSG_(header, msg_) | 26 #define OTS_FAILURE_MSG_HDR(msg_) OTS_FAILURE_MSG_(header, msg_) |
27 #define OTS_WARNING_MSG_HDR(msg_) OTS_WARNING_MSG_(header, msg_) | |
28 | 27 |
29 | 28 |
30 struct OpenTypeTable { | 29 struct OpenTypeTable { |
31 uint32_t tag; | 30 uint32_t tag; |
32 uint32_t chksum; | 31 uint32_t chksum; |
33 uint32_t offset; | 32 uint32_t offset; |
34 uint32_t length; | 33 uint32_t length; |
35 uint32_t uncompressed_length; | 34 uint32_t uncompressed_length; |
36 }; | 35 }; |
37 | 36 |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 465 |
467 uint32_t uncompressed_sum = 0; | 466 uint32_t uncompressed_sum = 0; |
468 | 467 |
469 for (unsigned i = 0; i < header->num_tables; ++i) { | 468 for (unsigned i = 0; i < header->num_tables; ++i) { |
470 // the tables must be sorted by tag (when taken as big-endian numbers). | 469 // the tables must be sorted by tag (when taken as big-endian numbers). |
471 // This also remove the possibility of duplicate tables. | 470 // This also remove the possibility of duplicate tables. |
472 if (i) { | 471 if (i) { |
473 const uint32_t this_tag = ntohl(tables[i].tag); | 472 const uint32_t this_tag = ntohl(tables[i].tag); |
474 const uint32_t prev_tag = ntohl(tables[i - 1].tag); | 473 const uint32_t prev_tag = ntohl(tables[i - 1].tag); |
475 if (this_tag <= prev_tag) { | 474 if (this_tag <= prev_tag) { |
476 OTS_WARNING_MSG_HDR("Table directory is not correctly ordered"); | 475 return OTS_FAILURE_MSG_HDR("table directory not correctly ordered"); |
477 } | 476 } |
478 } | 477 } |
479 | 478 |
480 // all tag names must be built from printable ASCII characters | 479 // all tag names must be built from printable ASCII characters |
481 if (!CheckTag(tables[i].tag)) { | 480 if (!CheckTag(tables[i].tag)) { |
482 return OTS_FAILURE_MSG_TAG("invalid table tag", &tables[i].tag); | 481 return OTS_FAILURE_MSG_TAG("invalid table tag", &tables[i].tag); |
483 } | 482 } |
484 | 483 |
485 // tables must be 4-byte aligned | 484 // tables must be 4-byte aligned |
486 if (tables[i].offset & 3) { | 485 if (tables[i].offset & 3) { |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 result = ProcessTTF(&header, output, data, length); | 811 result = ProcessTTF(&header, output, data, length); |
813 } | 812 } |
814 | 813 |
815 for (unsigned i = 0; ; ++i) { | 814 for (unsigned i = 0; ; ++i) { |
816 if (table_parsers[i].parse == NULL) break; | 815 if (table_parsers[i].parse == NULL) break; |
817 table_parsers[i].free(&header); | 816 table_parsers[i].free(&header); |
818 } | 817 } |
819 return result; | 818 return result; |
820 } | 819 } |
821 | 820 |
| 821 // For backward compatibility |
| 822 bool Process(OTSStream *output, const uint8_t *data, size_t length) { |
| 823 static OTSContext context; |
| 824 return context.Process(output, data, length); |
| 825 } |
| 826 |
822 } // namespace ots | 827 } // namespace ots |
OLD | NEW |