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 "cmap.h" | 5 #include "cmap.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // The last range must end at 0xffff | 207 // The last range must end at 0xffff |
208 if (ranges[segcount - 1].end_range != 0xffff) { | 208 if (ranges[segcount - 1].end_range != 0xffff) { |
209 return OTS_FAILURE(); | 209 return OTS_FAILURE(); |
210 } | 210 } |
211 | 211 |
212 // A format 4 CMAP subtable is complex. To be safe we simulate a lookup of | 212 // A format 4 CMAP subtable is complex. To be safe we simulate a lookup of |
213 // each code-point defined in the table and make sure that they are all valid | 213 // each code-point defined in the table and make sure that they are all valid |
214 // glyphs and that we don't access anything out-of-bounds. | 214 // glyphs and that we don't access anything out-of-bounds. |
215 for (unsigned i = 0; i < segcount; ++i) { | 215 for (unsigned i = 0; i < segcount; ++i) { |
216 for (unsigned cp = ranges[i].start_range; cp <= ranges[i].end_range; ++cp) { | 216 for (unsigned cp = ranges[i].start_range; cp <= ranges[i].end_range; ++cp) { |
217 const uint16_t code_point = cp; | 217 const uint16_t code_point = static_cast<uint16_t>(cp); |
218 if (ranges[i].id_range_offset == 0) { | 218 if (ranges[i].id_range_offset == 0) { |
219 // this is explictly allowed to overflow in the spec | 219 // this is explictly allowed to overflow in the spec |
220 const uint16_t glyph = code_point + ranges[i].id_delta; | 220 const uint16_t glyph = code_point + ranges[i].id_delta; |
221 if (glyph >= num_glyphs) { | 221 if (glyph >= num_glyphs) { |
222 return OTS_FAILURE(); | 222 return OTS_FAILURE(); |
223 } | 223 } |
224 } else { | 224 } else { |
225 const uint16_t range_delta = code_point - ranges[i].start_range; | 225 const uint16_t range_delta = code_point - ranges[i].start_range; |
226 // this might seem odd, but it's true. The offset is relative to the | 226 // this might seem odd, but it's true. The offset is relative to the |
227 // location of the offset value itself. | 227 // location of the offset value itself. |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 bool ots_cmap_serialise(OTSStream *out, OpenTypeFile *file) { | 831 bool ots_cmap_serialise(OTSStream *out, OpenTypeFile *file) { |
832 const bool have_034 = file->cmap->subtable_0_3_4_data != NULL; | 832 const bool have_034 = file->cmap->subtable_0_3_4_data != NULL; |
833 const bool have_0514 = file->cmap->subtable_0_5_14.size() != 0; | 833 const bool have_0514 = file->cmap->subtable_0_5_14.size() != 0; |
834 const bool have_100 = file->cmap->subtable_1_0_0.size() != 0; | 834 const bool have_100 = file->cmap->subtable_1_0_0.size() != 0; |
835 const bool have_304 = file->cmap->subtable_3_0_4_data != NULL; | 835 const bool have_304 = file->cmap->subtable_3_0_4_data != NULL; |
836 // MS Symbol and MS Unicode tables should not co-exist. | 836 // MS Symbol and MS Unicode tables should not co-exist. |
837 // See the comment above in 0-0-4 parser. | 837 // See the comment above in 0-0-4 parser. |
838 const bool have_314 = (!have_304) && file->cmap->subtable_3_1_4_data; | 838 const bool have_314 = (!have_304) && file->cmap->subtable_3_1_4_data; |
839 const bool have_31012 = file->cmap->subtable_3_10_12.size() != 0; | 839 const bool have_31012 = file->cmap->subtable_3_10_12.size() != 0; |
840 const bool have_31013 = file->cmap->subtable_3_10_13.size() != 0; | 840 const bool have_31013 = file->cmap->subtable_3_10_13.size() != 0; |
841 const unsigned num_subtables = static_cast<unsigned>(have_034) + | 841 const uint16_t num_subtables = static_cast<uint16_t>(have_034) + |
842 static_cast<unsigned>(have_0514) + | 842 static_cast<uint16_t>(have_0514) + |
843 static_cast<unsigned>(have_100) + | 843 static_cast<uint16_t>(have_100) + |
844 static_cast<unsigned>(have_304) + | 844 static_cast<uint16_t>(have_304) + |
845 static_cast<unsigned>(have_314) + | 845 static_cast<uint16_t>(have_314) + |
846 static_cast<unsigned>(have_31012) + | 846 static_cast<uint16_t>(have_31012) + |
847 static_cast<unsigned>(have_31013); | 847 static_cast<uint16_t>(have_31013); |
848 const off_t table_start = out->Tell(); | 848 const off_t table_start = out->Tell(); |
849 | 849 |
850 // Some fonts don't have 3-0-4 MS Symbol nor 3-1-4 Unicode BMP tables | 850 // Some fonts don't have 3-0-4 MS Symbol nor 3-1-4 Unicode BMP tables |
851 // (e.g., old fonts for Mac). We don't support them except for color bitmap | 851 // (e.g., old fonts for Mac). We don't support them except for color bitmap |
852 // fonts. | 852 // fonts. |
853 if (!have_304 && !have_314 && !have_034) { | 853 if (!have_304 && !have_314 && !have_034) { |
854 if (!(file->cbdt && file->cblc)) { | 854 if (!(file->cbdt && file->cblc)) { |
855 return OTS_FAILURE(); | 855 return OTS_FAILURE(); |
856 } | 856 } |
857 } | 857 } |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 out->RestoreChecksum(saved_checksum); | 1070 out->RestoreChecksum(saved_checksum); |
1071 | 1071 |
1072 return true; | 1072 return true; |
1073 } | 1073 } |
1074 | 1074 |
1075 void ots_cmap_free(OpenTypeFile *file) { | 1075 void ots_cmap_free(OpenTypeFile *file) { |
1076 delete file->cmap; | 1076 delete file->cmap; |
1077 } | 1077 } |
1078 | 1078 |
1079 } // namespace ots | 1079 } // namespace ots |
OLD | NEW |