OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "vmtx.h" | 5 #include "vmtx.h" |
6 | 6 |
7 #include "gsub.h" | 7 #include "gsub.h" |
8 #include "maxp.h" | 8 #include "maxp.h" |
9 #include "vhea.h" | 9 #include "vhea.h" |
10 | 10 |
11 // vmtx - Vertical Metrics Table | 11 // vmtx - Vertical Metrics Table |
12 // http://www.microsoft.com/opentype/otspec/vmtx.htm | 12 // http://www.microsoft.com/typography/otspec/vmtx.htm |
| 13 |
| 14 #define TABLE_NAME "vmtx" |
13 | 15 |
14 namespace ots { | 16 namespace ots { |
15 | 17 |
16 bool ots_vmtx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { | 18 bool ots_vmtx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
17 Buffer table(data, length); | 19 Buffer table(data, length); |
18 OpenTypeVMTX *vmtx = new OpenTypeVMTX; | 20 OpenTypeVMTX *vmtx = new OpenTypeVMTX; |
19 file->vmtx = vmtx; | 21 file->vmtx = vmtx; |
20 | 22 |
21 if (!file->vhea || !file->maxp) { | 23 if (!file->vhea || !file->maxp) { |
22 return OTS_FAILURE(); | 24 return OTS_FAILURE_MSG("vhea or maxp table missing as needed by vmtx"); |
23 } | 25 } |
24 | 26 |
25 if (!ParseMetricsTable(&table, file->maxp->num_glyphs, | 27 if (!ParseMetricsTable(file, &table, file->maxp->num_glyphs, |
26 &file->vhea->header, &vmtx->metrics)) { | 28 &file->vhea->header, &vmtx->metrics)) { |
27 return OTS_FAILURE(); | 29 return OTS_FAILURE_MSG("Failed to parse vmtx metrics"); |
28 } | 30 } |
29 | 31 |
30 return true; | 32 return true; |
31 } | 33 } |
32 | 34 |
33 bool ots_vmtx_should_serialise(OpenTypeFile *file) { | 35 bool ots_vmtx_should_serialise(OpenTypeFile *file) { |
34 // vmtx should serialise when vhea and GSUB are preserved. | 36 // vmtx should serialise when vhea and GSUB are preserved. |
35 // See the comment in ots_vhea_should_serialise(). | 37 // See the comment in ots_vhea_should_serialise(). |
36 return file->vmtx != NULL && file->vhea != NULL && | 38 return file->vmtx != NULL && file->vhea != NULL && |
37 ots_gsub_should_serialise(file); | 39 ots_gsub_should_serialise(file); |
38 } | 40 } |
39 | 41 |
40 bool ots_vmtx_serialise(OTSStream *out, OpenTypeFile *file) { | 42 bool ots_vmtx_serialise(OTSStream *out, OpenTypeFile *file) { |
41 if (!SerialiseMetricsTable(out, &file->vmtx->metrics)) { | 43 if (!SerialiseMetricsTable(file, out, &file->vmtx->metrics)) { |
42 return OTS_FAILURE(); | 44 return OTS_FAILURE_MSG("Failed to write vmtx metrics"); |
43 } | 45 } |
44 return true; | 46 return true; |
45 } | 47 } |
46 | 48 |
47 void ots_vmtx_free(OpenTypeFile *file) { | 49 void ots_vmtx_free(OpenTypeFile *file) { |
48 delete file->vmtx; | 50 delete file->vmtx; |
49 } | 51 } |
50 | 52 |
51 } // namespace ots | 53 } // namespace ots |
52 | 54 |
| 55 #undef TABLE_NAME |
OLD | NEW |