michael@0: // Copyright (c) 2009 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "hhea.h" michael@0: michael@0: #include "head.h" michael@0: #include "maxp.h" michael@0: michael@0: // hhea - Horizontal Header michael@0: // http://www.microsoft.com/typography/otspec/hhea.htm michael@0: michael@0: #define TABLE_NAME "hhea" michael@0: michael@0: namespace ots { michael@0: michael@0: bool ots_hhea_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { michael@0: Buffer table(data, length); michael@0: OpenTypeHHEA *hhea = new OpenTypeHHEA; michael@0: file->hhea = hhea; michael@0: michael@0: if (!table.ReadU32(&hhea->header.version)) { michael@0: return OTS_FAILURE_MSG("Failed to read hhea version"); michael@0: } michael@0: if (hhea->header.version >> 16 != 1) { michael@0: return OTS_FAILURE_MSG("Bad hhea version of %d", hhea->header.version); michael@0: } michael@0: michael@0: if (!ParseMetricsHeader(file, &table, &hhea->header)) { michael@0: return OTS_FAILURE_MSG("Failed to parse horizontal metrics"); michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: bool ots_hhea_should_serialise(OpenTypeFile *file) { michael@0: return file->hhea != NULL; michael@0: } michael@0: michael@0: bool ots_hhea_serialise(OTSStream *out, OpenTypeFile *file) { michael@0: if (!SerialiseMetricsHeader(file, out, &file->hhea->header)) { michael@0: return OTS_FAILURE_MSG("Failed to serialise horizontal metrics"); michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: void ots_hhea_free(OpenTypeFile *file) { michael@0: delete file->hhea; michael@0: } michael@0: michael@0: } // namespace ots