blob: 0342ba5bcb34fd1a2d665d7bb07f89126a28301c [file] [log] [blame]
yusukes@chromium.orgd257d182009-11-04 04:56:32 +00001// 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
13namespace ots {
14
15bool 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.org4dcad602011-03-28 20:51:38 +000020 if (!table.ReadU32(&hhea->header.version)) {
yusukes@chromium.orgd257d182009-11-04 04:56:32 +000021 return OTS_FAILURE();
22 }
bashi@chromium.org4dcad602011-03-28 20:51:38 +000023 if (hhea->header.version >> 16 != 1) {
yusukes@chromium.orgd257d182009-11-04 04:56:32 +000024 return OTS_FAILURE();
25 }
26
bashi@chromium.org4dcad602011-03-28 20:51:38 +000027 if (!ParseMetricsHeader(file, &table, &hhea->header)) {
yusukes@chromium.orgd257d182009-11-04 04:56:32 +000028 return OTS_FAILURE();
29 }
30
31 return true;
32}
33
34bool ots_hhea_should_serialise(OpenTypeFile *file) {
agl@chromium.org2beaf1d2011-01-21 17:19:34 +000035 return file->hhea != NULL;
yusukes@chromium.orgd257d182009-11-04 04:56:32 +000036}
37
38bool ots_hhea_serialise(OTSStream *out, OpenTypeFile *file) {
bashi@chromium.org4dcad602011-03-28 20:51:38 +000039 if (!SerialiseMetricsHeader(out, &file->hhea->header)) {
yusukes@chromium.orgd257d182009-11-04 04:56:32 +000040 return OTS_FAILURE();
41 }
yusukes@chromium.orgd257d182009-11-04 04:56:32 +000042 return true;
43}
44
45void ots_hhea_free(OpenTypeFile *file) {
46 delete file->hhea;
47}
48
49} // namespace ots