| 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 "maxp.h" | 5 #include "maxp.h" |
| 6 | 6 |
| 7 // maxp - Maximum Profile | 7 // maxp - Maximum Profile |
| 8 // http://www.microsoft.com/typography/otspec/maxp.htm | 8 // http://www.microsoft.com/typography/otspec/maxp.htm |
| 9 | 9 |
| 10 #define TABLE_NAME "maxp" | 10 #define TABLE_NAME "maxp" |
| 11 | 11 |
| 12 namespace ots { | 12 namespace ots { |
| 13 | 13 |
| 14 bool ots_maxp_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { | 14 bool ots_maxp_parse(Font *font, const uint8_t *data, size_t length) { |
| 15 Buffer table(data, length); | 15 Buffer table(data, length); |
| 16 | 16 |
| 17 OpenTypeMAXP *maxp = new OpenTypeMAXP; | 17 OpenTypeMAXP *maxp = new OpenTypeMAXP; |
| 18 file->maxp = maxp; | 18 font->maxp = maxp; |
| 19 | 19 |
| 20 uint32_t version = 0; | 20 uint32_t version = 0; |
| 21 if (!table.ReadU32(&version)) { | 21 if (!table.ReadU32(&version)) { |
| 22 return OTS_FAILURE_MSG("Failed to read version of maxp table"); | 22 return OTS_FAILURE_MSG("Failed to read version of maxp table"); |
| 23 } | 23 } |
| 24 | 24 |
| 25 if (version >> 16 > 1) { | 25 if (version >> 16 > 1) { |
| 26 return OTS_FAILURE_MSG("Bad maxp version %d", version); | 26 return OTS_FAILURE_MSG("Bad maxp version %d", version); |
| 27 } | 27 } |
| 28 | 28 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 if ((maxp->max_zones != 1) && (maxp->max_zones != 2)) { | 65 if ((maxp->max_zones != 1) && (maxp->max_zones != 2)) { |
| 66 return OTS_FAILURE_MSG("Bad max zones %d in maxp", maxp->max_zones); | 66 return OTS_FAILURE_MSG("Bad max zones %d in maxp", maxp->max_zones); |
| 67 } | 67 } |
| 68 } else { | 68 } else { |
| 69 maxp->version_1 = false; | 69 maxp->version_1 = false; |
| 70 } | 70 } |
| 71 | 71 |
| 72 return true; | 72 return true; |
| 73 } | 73 } |
| 74 | 74 |
| 75 bool ots_maxp_should_serialise(OpenTypeFile *file) { | 75 bool ots_maxp_should_serialise(Font *font) { |
| 76 return file->maxp != NULL; | 76 return font->maxp != NULL; |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool ots_maxp_serialise(OTSStream *out, OpenTypeFile *file) { | 79 bool ots_maxp_serialise(OTSStream *out, Font *font) { |
| 80 const OpenTypeMAXP *maxp = file->maxp; | 80 const OpenTypeMAXP *maxp = font->maxp; |
| 81 | 81 |
| 82 if (!out->WriteU32(maxp->version_1 ? 0x00010000 : 0x00005000) || | 82 if (!out->WriteU32(maxp->version_1 ? 0x00010000 : 0x00005000) || |
| 83 !out->WriteU16(maxp->num_glyphs)) { | 83 !out->WriteU16(maxp->num_glyphs)) { |
| 84 return OTS_FAILURE_MSG("Failed to write maxp version or number of glyphs"); | 84 return OTS_FAILURE_MSG("Failed to write maxp version or number of glyphs"); |
| 85 } | 85 } |
| 86 | 86 |
| 87 if (!maxp->version_1) return true; | 87 if (!maxp->version_1) return true; |
| 88 | 88 |
| 89 if (!out->WriteU16(maxp->max_points) || | 89 if (!out->WriteU16(maxp->max_points) || |
| 90 !out->WriteU16(maxp->max_contours) || | 90 !out->WriteU16(maxp->max_contours) || |
| (...skipping 13 matching lines...) Expand all Loading... |
| 104 } | 104 } |
| 105 | 105 |
| 106 if (!out->WriteU16(maxp->max_c_components) || | 106 if (!out->WriteU16(maxp->max_c_components) || |
| 107 !out->WriteU16(maxp->max_c_depth)) { | 107 !out->WriteU16(maxp->max_c_depth)) { |
| 108 return OTS_FAILURE_MSG("Failed to write yet more maxp"); | 108 return OTS_FAILURE_MSG("Failed to write yet more maxp"); |
| 109 } | 109 } |
| 110 | 110 |
| 111 return true; | 111 return true; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void ots_maxp_free(OpenTypeFile *file) { | 114 void ots_maxp_reuse(Font *font, Font *other) { |
| 115 delete file->maxp; | 115 font->maxp = other->maxp; |
| 116 font->maxp_reused = true; |
| 117 } |
| 118 |
| 119 void ots_maxp_free(Font *font) { |
| 120 delete font->maxp; |
| 116 } | 121 } |
| 117 | 122 |
| 118 } // namespace ots | 123 } // namespace ots |
| 119 | 124 |
| 120 #undef TABLE_NAME | 125 #undef TABLE_NAME |
| OLD | NEW |