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 "vhea.h" michael@0: michael@0: #include "gsub.h" michael@0: #include "head.h" michael@0: #include "maxp.h" michael@0: michael@0: // vhea - Vertical Header Table michael@0: // http://www.microsoft.com/typography/otspec/vhea.htm michael@0: michael@0: #define TABLE_NAME "vhea" michael@0: michael@0: namespace ots { michael@0: michael@0: bool ots_vhea_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { michael@0: Buffer table(data, length); michael@0: OpenTypeVHEA *vhea = new OpenTypeVHEA; michael@0: file->vhea = vhea; michael@0: michael@0: if (!table.ReadU32(&vhea->header.version)) { michael@0: return OTS_FAILURE_MSG("Failed to read version"); michael@0: } michael@0: if (vhea->header.version != 0x00010000 && michael@0: vhea->header.version != 0x00011000) { michael@0: return OTS_FAILURE_MSG("Bad vhea version %x", vhea->header.version); michael@0: } michael@0: michael@0: if (!ParseMetricsHeader(file, &table, &vhea->header)) { michael@0: return OTS_FAILURE_MSG("Failed to parse metrics in vhea"); michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: bool ots_vhea_should_serialise(OpenTypeFile *file) { michael@0: // vhea should'nt serialise when vmtx doesn't exist. michael@0: // Firefox developer pointed out that vhea/vmtx should serialise iff GSUB is michael@0: // preserved. See http://crbug.com/77386 michael@0: return file->vhea != NULL && file->vmtx != NULL && michael@0: ots_gsub_should_serialise(file); michael@0: } michael@0: michael@0: bool ots_vhea_serialise(OTSStream *out, OpenTypeFile *file) { michael@0: if (!SerialiseMetricsHeader(file, out, &file->vhea->header)) { michael@0: return OTS_FAILURE_MSG("Failed to write vhea metrics"); michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: void ots_vhea_free(OpenTypeFile *file) { michael@0: delete file->vhea; michael@0: } michael@0: michael@0: } // namespace ots michael@0: