| 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_) |
| 27 | 28 |
| 28 | 29 |
| 29 struct OpenTypeTable { | 30 struct OpenTypeTable { |
| 30 uint32_t tag; | 31 uint32_t tag; |
| 31 uint32_t chksum; | 32 uint32_t chksum; |
| 32 uint32_t offset; | 33 uint32_t offset; |
| 33 uint32_t length; | 34 uint32_t length; |
| 34 uint32_t uncompressed_length; | 35 uint32_t uncompressed_length; |
| 35 }; | 36 }; |
| 36 | 37 |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 466 |
| 466 uint32_t uncompressed_sum = 0; | 467 uint32_t uncompressed_sum = 0; |
| 467 | 468 |
| 468 for (unsigned i = 0; i < header->num_tables; ++i) { | 469 for (unsigned i = 0; i < header->num_tables; ++i) { |
| 469 // the tables must be sorted by tag (when taken as big-endian numbers). | 470 // the tables must be sorted by tag (when taken as big-endian numbers). |
| 470 // This also remove the possibility of duplicate tables. | 471 // This also remove the possibility of duplicate tables. |
| 471 if (i) { | 472 if (i) { |
| 472 const uint32_t this_tag = ntohl(tables[i].tag); | 473 const uint32_t this_tag = ntohl(tables[i].tag); |
| 473 const uint32_t prev_tag = ntohl(tables[i - 1].tag); | 474 const uint32_t prev_tag = ntohl(tables[i - 1].tag); |
| 474 if (this_tag <= prev_tag) { | 475 if (this_tag <= prev_tag) { |
| 475 return OTS_FAILURE_MSG_HDR("table directory not correctly ordered"); | 476 OTS_WARNING_MSG_HDR("Table directory is not correctly ordered"); |
| 476 } | 477 } |
| 477 } | 478 } |
| 478 | 479 |
| 479 // all tag names must be built from printable ASCII characters | 480 // all tag names must be built from printable ASCII characters |
| 480 if (!CheckTag(tables[i].tag)) { | 481 if (!CheckTag(tables[i].tag)) { |
| 481 return OTS_FAILURE_MSG_TAG("invalid table tag", &tables[i].tag); | 482 return OTS_FAILURE_MSG_TAG("invalid table tag", &tables[i].tag); |
| 482 } | 483 } |
| 483 | 484 |
| 484 // tables must be 4-byte aligned | 485 // tables must be 4-byte aligned |
| 485 if (tables[i].offset & 3) { | 486 if (tables[i].offset & 3) { |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 result = ProcessTTF(&header, output, data, length); | 812 result = ProcessTTF(&header, output, data, length); |
| 812 } | 813 } |
| 813 | 814 |
| 814 for (unsigned i = 0; ; ++i) { | 815 for (unsigned i = 0; ; ++i) { |
| 815 if (table_parsers[i].parse == NULL) break; | 816 if (table_parsers[i].parse == NULL) break; |
| 816 table_parsers[i].free(&header); | 817 table_parsers[i].free(&header); |
| 817 } | 818 } |
| 818 return result; | 819 return result; |
| 819 } | 820 } |
| 820 | 821 |
| 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 | |
| 827 } // namespace ots | 822 } // namespace ots |
| OLD | NEW |