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 "vorg.h" | 5 #include "vorg.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 // VORG - Vertical Origin Table | 9 // VORG - Vertical Origin Table |
10 // http://www.microsoft.com/opentype/otspec/vorg.htm | 10 // http://www.microsoft.com/opentype/otspec/vorg.htm |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 return true; | 64 return true; |
65 } | 65 } |
66 | 66 |
67 bool ots_vorg_should_serialise(OpenTypeFile *file) { | 67 bool ots_vorg_should_serialise(OpenTypeFile *file) { |
68 if (!file->cff) return false; // this table is not for fonts with TT glyphs. | 68 if (!file->cff) return false; // this table is not for fonts with TT glyphs. |
69 return file->vorg != NULL; | 69 return file->vorg != NULL; |
70 } | 70 } |
71 | 71 |
72 bool ots_vorg_serialise(OTSStream *out, OpenTypeFile *file) { | 72 bool ots_vorg_serialise(OTSStream *out, OpenTypeFile *file) { |
73 OpenTypeVORG * const vorg = file->vorg; | 73 OpenTypeVORG * const vorg = file->vorg; |
74 | 74 |
75 if (!out->WriteU16(vorg->major_version) || | 75 const uint16_t num_metrics = static_cast<uint16_t>(vorg->metrics.size()); |
| 76 if (num_metrics != vorg->metrics.size() || |
| 77 !out->WriteU16(vorg->major_version) || |
76 !out->WriteU16(vorg->minor_version) || | 78 !out->WriteU16(vorg->minor_version) || |
77 !out->WriteS16(vorg->default_vert_origin_y) || | 79 !out->WriteS16(vorg->default_vert_origin_y) || |
78 !out->WriteU16(vorg->metrics.size())) { | 80 !out->WriteU16(num_metrics)) { |
79 return OTS_FAILURE(); | 81 return OTS_FAILURE(); |
80 } | 82 } |
81 | 83 |
82 for (unsigned i = 0; i < vorg->metrics.size(); ++i) { | 84 for (uint16_t i = 0; i < num_metrics; ++i) { |
83 const OpenTypeVORGMetrics& rec = vorg->metrics[i]; | 85 const OpenTypeVORGMetrics& rec = vorg->metrics[i]; |
84 if (!out->WriteU16(rec.glyph_index) || | 86 if (!out->WriteU16(rec.glyph_index) || |
85 !out->WriteS16(rec.vert_origin_y)) { | 87 !out->WriteS16(rec.vert_origin_y)) { |
86 return OTS_FAILURE(); | 88 return OTS_FAILURE(); |
87 } | 89 } |
88 } | 90 } |
89 | 91 |
90 return true; | 92 return true; |
91 } | 93 } |
92 | 94 |
93 void ots_vorg_free(OpenTypeFile *file) { | 95 void ots_vorg_free(OpenTypeFile *file) { |
94 delete file->vorg; | 96 delete file->vorg; |
95 } | 97 } |
96 | 98 |
97 } // namespace ots | 99 } // namespace ots |
OLD | NEW |