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 "hhea.h" | 5 #include "hhea.h" |
6 | 6 |
7 #include "head.h" | 7 #include "head.h" |
8 #include "maxp.h" | 8 #include "maxp.h" |
9 | 9 |
10 // hhea - Horizontal Header | 10 // hhea - Horizontal Header |
11 // http://www.microsoft.com/opentype/otspec/hhea.htm | 11 // http://www.microsoft.com/typography/otspec/hhea.htm |
| 12 |
| 13 #define TABLE_NAME "hhea" |
12 | 14 |
13 namespace ots { | 15 namespace ots { |
14 | 16 |
15 bool ots_hhea_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { | 17 bool ots_hhea_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
16 Buffer table(data, length); | 18 Buffer table(data, length); |
17 OpenTypeHHEA *hhea = new OpenTypeHHEA; | 19 OpenTypeHHEA *hhea = new OpenTypeHHEA; |
18 file->hhea = hhea; | 20 file->hhea = hhea; |
19 | 21 |
20 if (!table.ReadU32(&hhea->header.version)) { | 22 if (!table.ReadU32(&hhea->header.version)) { |
21 return OTS_FAILURE(); | 23 return OTS_FAILURE_MSG("Failed to read hhea version"); |
22 } | 24 } |
23 if (hhea->header.version >> 16 != 1) { | 25 if (hhea->header.version >> 16 != 1) { |
24 return OTS_FAILURE(); | 26 return OTS_FAILURE_MSG("Bad hhea version of %d", hhea->header.version); |
25 } | 27 } |
26 | 28 |
27 if (!ParseMetricsHeader(file, &table, &hhea->header)) { | 29 if (!ParseMetricsHeader(file, &table, &hhea->header)) { |
28 return OTS_FAILURE(); | 30 return OTS_FAILURE_MSG("Failed to parse horizontal metrics"); |
29 } | 31 } |
30 | 32 |
31 return true; | 33 return true; |
32 } | 34 } |
33 | 35 |
34 bool ots_hhea_should_serialise(OpenTypeFile *file) { | 36 bool ots_hhea_should_serialise(OpenTypeFile *file) { |
35 return file->hhea != NULL; | 37 return file->hhea != NULL; |
36 } | 38 } |
37 | 39 |
38 bool ots_hhea_serialise(OTSStream *out, OpenTypeFile *file) { | 40 bool ots_hhea_serialise(OTSStream *out, OpenTypeFile *file) { |
39 if (!SerialiseMetricsHeader(out, &file->hhea->header)) { | 41 if (!SerialiseMetricsHeader(file, out, &file->hhea->header)) { |
40 return OTS_FAILURE(); | 42 return OTS_FAILURE_MSG("Failed to serialise horizontal metrics"); |
41 } | 43 } |
42 return true; | 44 return true; |
43 } | 45 } |
44 | 46 |
45 void ots_hhea_free(OpenTypeFile *file) { | 47 void ots_hhea_free(OpenTypeFile *file) { |
46 delete file->hhea; | 48 delete file->hhea; |
47 } | 49 } |
48 | 50 |
49 } // namespace ots | 51 } // namespace ots |
| 52 |
| 53 #undef TABLE_NAME |
OLD | NEW |