OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "cff.h" | 5 #include "cff.h" |
6 | 6 |
7 #include <cstring> | 7 #include <cstring> |
8 #include <utility> // std::pair | 8 #include <utility> // std::pair |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 if (type == DICT_DATA_TOPLEVEL) { | 465 if (type == DICT_DATA_TOPLEVEL) { |
466 out_cff->char_strings_array.push_back(new ots::CFFIndex); | 466 out_cff->char_strings_array.push_back(new ots::CFFIndex); |
467 } | 467 } |
468 size_t dict_length = index.offsets[i] - index.offsets[i - 1]; | 468 size_t dict_length = index.offsets[i] - index.offsets[i - 1]; |
469 ots::Buffer table(data + index.offsets[i - 1], dict_length); | 469 ots::Buffer table(data + index.offsets[i - 1], dict_length); |
470 | 470 |
471 std::vector<std::pair<uint32_t, DICT_OPERAND_TYPE> > operands; | 471 std::vector<std::pair<uint32_t, DICT_OPERAND_TYPE> > operands; |
472 | 472 |
473 FONT_FORMAT font_format = FORMAT_UNKNOWN; | 473 FONT_FORMAT font_format = FORMAT_UNKNOWN; |
474 bool have_ros = false; | 474 bool have_ros = false; |
475 size_t glyphs = 0; | 475 uint16_t glyphs = 0; |
476 size_t charset_offset = 0; | 476 size_t charset_offset = 0; |
477 | 477 |
478 while (table.offset() < dict_length) { | 478 while (table.offset() < dict_length) { |
479 if (!ParseDictDataReadNext(&table, &operands)) { | 479 if (!ParseDictDataReadNext(&table, &operands)) { |
480 return OTS_FAILURE(); | 480 return OTS_FAILURE(); |
481 } | 481 } |
482 if (operands.empty()) { | 482 if (operands.empty()) { |
483 return OTS_FAILURE(); | 483 return OTS_FAILURE(); |
484 } | 484 } |
485 if (operands.size() > 48) { | 485 if (operands.size() > 48) { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 } | 685 } |
686 | 686 |
687 // parse FDSelect data structure | 687 // parse FDSelect data structure |
688 ots::Buffer table(data, table_length); | 688 ots::Buffer table(data, table_length); |
689 table.set_offset(operands.back().first); | 689 table.set_offset(operands.back().first); |
690 uint8_t format = 0; | 690 uint8_t format = 0; |
691 if (!table.ReadU8(&format)) { | 691 if (!table.ReadU8(&format)) { |
692 return OTS_FAILURE(); | 692 return OTS_FAILURE(); |
693 } | 693 } |
694 if (format == 0) { | 694 if (format == 0) { |
695 for (size_t j = 0; j < glyphs; ++j) { | 695 for (uint16_t j = 0; j < glyphs; ++j) { |
696 uint8_t fd_index = 0; | 696 uint8_t fd_index = 0; |
697 if (!table.ReadU8(&fd_index)) { | 697 if (!table.ReadU8(&fd_index)) { |
698 return OTS_FAILURE(); | 698 return OTS_FAILURE(); |
699 } | 699 } |
700 (out_cff->fd_select)[j] = fd_index; | 700 (out_cff->fd_select)[j] = fd_index; |
701 } | 701 } |
702 } else if (format == 3) { | 702 } else if (format == 3) { |
703 uint16_t n_ranges = 0; | 703 uint16_t n_ranges = 0; |
704 if (!table.ReadU16(&n_ranges)) { | 704 if (!table.ReadU16(&n_ranges)) { |
705 return OTS_FAILURE(); | 705 return OTS_FAILURE(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 // parse "13. Charsets" | 829 // parse "13. Charsets" |
830 if (charset_offset) { | 830 if (charset_offset) { |
831 ots::Buffer table(data, table_length); | 831 ots::Buffer table(data, table_length); |
832 table.set_offset(charset_offset); | 832 table.set_offset(charset_offset); |
833 uint8_t format = 0; | 833 uint8_t format = 0; |
834 if (!table.ReadU8(&format)) { | 834 if (!table.ReadU8(&format)) { |
835 return OTS_FAILURE(); | 835 return OTS_FAILURE(); |
836 } | 836 } |
837 switch (format) { | 837 switch (format) { |
838 case 0: | 838 case 0: |
839 for (unsigned j = 1 /* .notdef is omitted */; j < glyphs; ++j) { | 839 for (uint16_t j = 1 /* .notdef is omitted */; j < glyphs; ++j) { |
840 uint16_t sid = 0; | 840 uint16_t sid = 0; |
841 if (!table.ReadU16(&sid)) { | 841 if (!table.ReadU16(&sid)) { |
842 return OTS_FAILURE(); | 842 return OTS_FAILURE(); |
843 } | 843 } |
844 if (!have_ros && (sid > sid_max)) { | 844 if (!have_ros && (sid > sid_max)) { |
845 return OTS_FAILURE(); | 845 return OTS_FAILURE(); |
846 } | 846 } |
847 // TODO(yusukes): check CIDs when have_ros is true. | 847 // TODO(yusukes): check CIDs when have_ros is true. |
848 } | 848 } |
849 break; | 849 break; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 } | 1019 } |
1020 for (size_t i = 0; i < file->cff->local_subrs_per_font.size(); ++i) { | 1020 for (size_t i = 0; i < file->cff->local_subrs_per_font.size(); ++i) { |
1021 delete (file->cff->local_subrs_per_font)[i]; | 1021 delete (file->cff->local_subrs_per_font)[i]; |
1022 } | 1022 } |
1023 delete file->cff->local_subrs; | 1023 delete file->cff->local_subrs; |
1024 delete file->cff; | 1024 delete file->cff; |
1025 } | 1025 } |
1026 } | 1026 } |
1027 | 1027 |
1028 } // namespace ots | 1028 } // namespace ots |
OLD | NEW |