yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "hhea.h" |
| 6 | |
| 7 | #include "head.h" |
| 8 | #include "maxp.h" |
| 9 | |
| 10 | // hhea - Horizontal Header |
| 11 | // http://www.microsoft.com/opentype/otspec/hhea.htm |
| 12 | |
| 13 | namespace ots { |
| 14 | |
| 15 | bool ots_hhea_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
| 16 | Buffer table(data, length); |
| 17 | OpenTypeHHEA *hhea = new OpenTypeHHEA; |
| 18 | file->hhea = hhea; |
| 19 | |
bashi@chromium.org | 4dcad60 | 2011-03-28 20:51:38 +0000 | [diff] [blame] | 20 | if (!table.ReadU32(&hhea->header.version)) { |
yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 21 | return OTS_FAILURE(); |
| 22 | } |
bashi@chromium.org | 4dcad60 | 2011-03-28 20:51:38 +0000 | [diff] [blame] | 23 | if (hhea->header.version >> 16 != 1) { |
yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 24 | return OTS_FAILURE(); |
| 25 | } |
| 26 | |
bashi@chromium.org | 4dcad60 | 2011-03-28 20:51:38 +0000 | [diff] [blame] | 27 | if (!ParseMetricsHeader(file, &table, &hhea->header)) { |
yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 28 | return OTS_FAILURE(); |
| 29 | } |
| 30 | |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | bool ots_hhea_should_serialise(OpenTypeFile *file) { |
agl@chromium.org | 2beaf1d | 2011-01-21 17:19:34 +0000 | [diff] [blame] | 35 | return file->hhea != NULL; |
yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | bool ots_hhea_serialise(OTSStream *out, OpenTypeFile *file) { |
bashi@chromium.org | 4dcad60 | 2011-03-28 20:51:38 +0000 | [diff] [blame] | 39 | if (!SerialiseMetricsHeader(out, &file->hhea->header)) { |
yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 40 | return OTS_FAILURE(); |
| 41 | } |
yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 42 | return true; |
| 43 | } |
| 44 | |
| 45 | void ots_hhea_free(OpenTypeFile *file) { |
| 46 | delete file->hhea; |
| 47 | } |
| 48 | |
| 49 | } // namespace ots |