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 "fpgm.h" | 5 #include "fpgm.h" |
6 | 6 |
7 // fpgm - Font Program | 7 // fpgm - Font Program |
8 // http://www.microsoft.com/opentype/otspec/fpgm.htm | 8 // http://www.microsoft.com/typography/otspec/fpgm.htm |
| 9 |
| 10 #define TABLE_NAME "fpgm" |
9 | 11 |
10 namespace ots { | 12 namespace ots { |
11 | 13 |
12 bool ots_fpgm_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { | 14 bool ots_fpgm_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
13 Buffer table(data, length); | 15 Buffer table(data, length); |
14 | 16 |
15 OpenTypeFPGM *fpgm = new OpenTypeFPGM; | 17 OpenTypeFPGM *fpgm = new OpenTypeFPGM; |
16 file->fpgm = fpgm; | 18 file->fpgm = fpgm; |
17 | 19 |
18 if (length >= 128 * 1024u) { | 20 if (length >= 128 * 1024u) { |
19 return OTS_FAILURE(); // almost all fpgm tables are less than 5k bytes. | 21 return OTS_FAILURE_MSG("length (%ld) > 120", length); // almost all fpgm ta
bles are less than 5k bytes. |
20 } | 22 } |
21 | 23 |
22 if (!table.Skip(length)) { | 24 if (!table.Skip(length)) { |
23 return OTS_FAILURE(); | 25 return OTS_FAILURE_MSG("Bad fpgm length"); |
24 } | 26 } |
25 | 27 |
26 fpgm->data = data; | 28 fpgm->data = data; |
27 fpgm->length = length; | 29 fpgm->length = length; |
28 return true; | 30 return true; |
29 } | 31 } |
30 | 32 |
31 bool ots_fpgm_should_serialise(OpenTypeFile *file) { | 33 bool ots_fpgm_should_serialise(OpenTypeFile *file) { |
32 if (!file->glyf) return false; // this table is not for CFF fonts. | 34 if (!file->glyf) return false; // this table is not for CFF fonts. |
33 return g_transcode_hints && file->fpgm; | 35 return file->fpgm; |
34 } | 36 } |
35 | 37 |
36 bool ots_fpgm_serialise(OTSStream *out, OpenTypeFile *file) { | 38 bool ots_fpgm_serialise(OTSStream *out, OpenTypeFile *file) { |
37 const OpenTypeFPGM *fpgm = file->fpgm; | 39 const OpenTypeFPGM *fpgm = file->fpgm; |
38 | 40 |
39 if (!out->Write(fpgm->data, fpgm->length)) { | 41 if (!out->Write(fpgm->data, fpgm->length)) { |
40 return OTS_FAILURE(); | 42 return OTS_FAILURE_MSG("Failed to write fpgm"); |
41 } | 43 } |
42 | 44 |
43 return true; | 45 return true; |
44 } | 46 } |
45 | 47 |
46 void ots_fpgm_free(OpenTypeFile *file) { | 48 void ots_fpgm_free(OpenTypeFile *file) { |
47 delete file->fpgm; | 49 delete file->fpgm; |
48 } | 50 } |
49 | 51 |
50 } // namespace ots | 52 } // namespace ots |
| 53 |
| 54 #undef TABLE_NAME |
OLD | NEW |