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 "hmtx.h" | 5 #include "hmtx.h" |
6 | 6 |
7 #include "hhea.h" | 7 #include "hhea.h" |
8 #include "maxp.h" | 8 #include "maxp.h" |
9 | 9 |
10 // hmtx - Horizontal Metrics | 10 // hmtx - Horizontal Metrics |
11 // http://www.microsoft.com/opentype/otspec/hmtx.htm | 11 // http://www.microsoft.com/typography/otspec/hmtx.htm |
| 12 |
| 13 #define TABLE_NAME "hmtx" |
12 | 14 |
13 namespace ots { | 15 namespace ots { |
14 | 16 |
15 bool ots_hmtx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { | 17 bool ots_hmtx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
16 Buffer table(data, length); | 18 Buffer table(data, length); |
17 OpenTypeHMTX *hmtx = new OpenTypeHMTX; | 19 OpenTypeHMTX *hmtx = new OpenTypeHMTX; |
18 file->hmtx = hmtx; | 20 file->hmtx = hmtx; |
19 | 21 |
20 if (!file->hhea || !file->maxp) { | 22 if (!file->hhea || !file->maxp) { |
21 return OTS_FAILURE(); | 23 return OTS_FAILURE_MSG("Missing hhea or maxp tables in font, needed by hmtx"
); |
22 } | 24 } |
23 | 25 |
24 if (!ParseMetricsTable(&table, file->maxp->num_glyphs, | 26 if (!ParseMetricsTable(file, &table, file->maxp->num_glyphs, |
25 &file->hhea->header, &hmtx->metrics)) { | 27 &file->hhea->header, &hmtx->metrics)) { |
26 return OTS_FAILURE(); | 28 return OTS_FAILURE_MSG("Failed to parse hmtx metrics"); |
27 } | 29 } |
28 | 30 |
29 return true; | 31 return true; |
30 } | 32 } |
31 | 33 |
32 bool ots_hmtx_should_serialise(OpenTypeFile *file) { | 34 bool ots_hmtx_should_serialise(OpenTypeFile *file) { |
33 return file->hmtx != NULL; | 35 return file->hmtx != NULL; |
34 } | 36 } |
35 | 37 |
36 bool ots_hmtx_serialise(OTSStream *out, OpenTypeFile *file) { | 38 bool ots_hmtx_serialise(OTSStream *out, OpenTypeFile *file) { |
37 if (!SerialiseMetricsTable(out, &file->hmtx->metrics)) { | 39 if (!SerialiseMetricsTable(file, out, &file->hmtx->metrics)) { |
38 return OTS_FAILURE(); | 40 return OTS_FAILURE_MSG("Failed to serialise htmx metrics"); |
39 } | 41 } |
40 return true; | 42 return true; |
41 } | 43 } |
42 | 44 |
43 void ots_hmtx_free(OpenTypeFile *file) { | 45 void ots_hmtx_free(OpenTypeFile *file) { |
44 delete file->hmtx; | 46 delete file->hmtx; |
45 } | 47 } |
46 | 48 |
47 } // namespace ots | 49 } // namespace ots |
| 50 |
| 51 #undef TABLE_NAME |
OLD | NEW |