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 "hmtx.h" michael@0: michael@0: #include "hhea.h" michael@0: #include "maxp.h" michael@0: michael@0: // hmtx - Horizontal Metrics michael@0: // http://www.microsoft.com/typography/otspec/hmtx.htm michael@0: michael@0: #define TABLE_NAME "hmtx" michael@0: michael@0: namespace ots { michael@0: michael@0: bool ots_hmtx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { michael@0: Buffer table(data, length); michael@0: OpenTypeHMTX *hmtx = new OpenTypeHMTX; michael@0: file->hmtx = hmtx; michael@0: michael@0: if (!file->hhea || !file->maxp) { michael@0: return OTS_FAILURE_MSG("Missing hhea or maxp tables in font, needed by hmtx"); michael@0: } michael@0: michael@0: if (!ParseMetricsTable(file, &table, file->maxp->num_glyphs, michael@0: &file->hhea->header, &hmtx->metrics)) { michael@0: return OTS_FAILURE_MSG("Failed to parse hmtx metrics"); michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: bool ots_hmtx_should_serialise(OpenTypeFile *file) { michael@0: return file->hmtx != NULL; michael@0: } michael@0: michael@0: bool ots_hmtx_serialise(OTSStream *out, OpenTypeFile *file) { michael@0: if (!SerialiseMetricsTable(file, out, &file->hmtx->metrics)) { michael@0: return OTS_FAILURE_MSG("Failed to serialise htmx metrics"); michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: void ots_hmtx_free(OpenTypeFile *file) { michael@0: delete file->hmtx; michael@0: } michael@0: michael@0: } // namespace ots