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 "post.h" | 5 #include "post.h" |
6 | 6 |
7 #include "maxp.h" | 7 #include "maxp.h" |
8 | 8 |
9 // post - PostScript | 9 // post - PostScript |
10 // http://www.microsoft.com/opentype/otspec/post.htm | 10 // http://www.microsoft.com/opentype/otspec/post.htm |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 !out->WriteU32(0) || | 139 !out->WriteU32(0) || |
140 !out->WriteU32(0) || | 140 !out->WriteU32(0) || |
141 !out->WriteU32(0)) { | 141 !out->WriteU32(0)) { |
142 return OTS_FAILURE(); | 142 return OTS_FAILURE(); |
143 } | 143 } |
144 | 144 |
145 if (post->version != 0x00020000) { | 145 if (post->version != 0x00020000) { |
146 return true; // v1.0 and v3.0 does not have glyph names. | 146 return true; // v1.0 and v3.0 does not have glyph names. |
147 } | 147 } |
148 | 148 |
149 if (!out->WriteU16(post->glyph_name_index.size())) { | 149 const uint16_t num_indexes = |
| 150 static_cast<uint16_t>(post->glyph_name_index.size()); |
| 151 if (num_indexes != post->glyph_name_index.size() || |
| 152 !out->WriteU16(num_indexes)) { |
150 return OTS_FAILURE(); | 153 return OTS_FAILURE(); |
151 } | 154 } |
152 | 155 |
153 for (unsigned i = 0; i < post->glyph_name_index.size(); ++i) { | 156 for (uint16_t i = 0; i < num_indexes; ++i) { |
154 if (!out->WriteU16(post->glyph_name_index[i])) { | 157 if (!out->WriteU16(post->glyph_name_index[i])) { |
155 return OTS_FAILURE(); | 158 return OTS_FAILURE(); |
156 } | 159 } |
157 } | 160 } |
158 | 161 |
159 // Now we just have to write out the strings in the correct order | 162 // Now we just have to write out the strings in the correct order |
160 for (unsigned i = 0; i < post->names.size(); ++i) { | 163 for (unsigned i = 0; i < post->names.size(); ++i) { |
161 const std::string& s = post->names[i]; | 164 const std::string& s = post->names[i]; |
162 const uint8_t string_length = s.size(); | 165 const uint8_t string_length = static_cast<uint8_t>(s.size()); |
163 if (!out->Write(&string_length, 1)) { | 166 if (string_length != s.size() || |
| 167 !out->Write(&string_length, 1)) { |
164 return OTS_FAILURE(); | 168 return OTS_FAILURE(); |
165 } | 169 } |
166 // Some ttf fonts (e.g., frank.ttf on Windows Vista) have zero-length name. | 170 // Some ttf fonts (e.g., frank.ttf on Windows Vista) have zero-length name. |
167 // We allow them. | 171 // We allow them. |
168 if (string_length > 0 && !out->Write(s.data(), string_length)) { | 172 if (string_length > 0 && !out->Write(s.data(), string_length)) { |
169 return OTS_FAILURE(); | 173 return OTS_FAILURE(); |
170 } | 174 } |
171 } | 175 } |
172 | 176 |
173 return true; | 177 return true; |
174 } | 178 } |
175 | 179 |
176 void ots_post_free(OpenTypeFile *file) { | 180 void ots_post_free(OpenTypeFile *file) { |
177 delete file->post; | 181 delete file->post; |
178 } | 182 } |
179 | 183 |
180 } // namespace ots | 184 } // namespace ots |
OLD | NEW |