michael@0: // Copyright (c) 2011 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 "vmtx.h" michael@0: michael@0: #include "gsub.h" michael@0: #include "maxp.h" michael@0: #include "vhea.h" michael@0: michael@0: // vmtx - Vertical Metrics Table michael@0: // http://www.microsoft.com/typography/otspec/vmtx.htm michael@0: michael@0: #define TABLE_NAME "vmtx" michael@0: michael@0: namespace ots { michael@0: michael@0: bool ots_vmtx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { michael@0: Buffer table(data, length); michael@0: OpenTypeVMTX *vmtx = new OpenTypeVMTX; michael@0: file->vmtx = vmtx; michael@0: michael@0: if (!file->vhea || !file->maxp) { michael@0: return OTS_FAILURE_MSG("vhea or maxp table missing as needed by vmtx"); michael@0: } michael@0: michael@0: if (!ParseMetricsTable(file, &table, file->maxp->num_glyphs, michael@0: &file->vhea->header, &vmtx->metrics)) { michael@0: return OTS_FAILURE_MSG("Failed to parse vmtx metrics"); michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: bool ots_vmtx_should_serialise(OpenTypeFile *file) { michael@0: // vmtx should serialise when vhea and GSUB are preserved. michael@0: // See the comment in ots_vhea_should_serialise(). michael@0: return file->vmtx != NULL && file->vhea != NULL && michael@0: ots_gsub_should_serialise(file); michael@0: } michael@0: michael@0: bool ots_vmtx_serialise(OTSStream *out, OpenTypeFile *file) { michael@0: if (!SerialiseMetricsTable(file, out, &file->vmtx->metrics)) { michael@0: return OTS_FAILURE_MSG("Failed to write vmtx metrics"); michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: void ots_vmtx_free(OpenTypeFile *file) { michael@0: delete file->vmtx; michael@0: } michael@0: michael@0: } // namespace ots michael@0: