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 "cvt.h" michael@0: michael@0: // cvt - Control Value Table michael@0: // http://www.microsoft.com/typography/otspec/cvt.htm michael@0: michael@0: #define TABLE_NAME "cvt" michael@0: michael@0: namespace ots { michael@0: michael@0: bool ots_cvt_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { michael@0: Buffer table(data, length); michael@0: michael@0: OpenTypeCVT *cvt = new OpenTypeCVT; michael@0: file->cvt = cvt; michael@0: michael@0: if (length >= 128 * 1024u) { michael@0: return OTS_FAILURE_MSG("Length (%d) > 120K"); // almost all cvt tables are less than 4k bytes. michael@0: } michael@0: michael@0: if (length % 2 != 0) { michael@0: return OTS_FAILURE_MSG("Uneven cvt length (%d)", length); michael@0: } michael@0: michael@0: if (!table.Skip(length)) { michael@0: return OTS_FAILURE_MSG("Length too high"); michael@0: } michael@0: michael@0: cvt->data = data; michael@0: cvt->length = length; michael@0: return true; michael@0: } michael@0: michael@0: bool ots_cvt_should_serialise(OpenTypeFile *file) { michael@0: if (!file->glyf) { michael@0: return false; // this table is not for CFF fonts. michael@0: } michael@0: return g_transcode_hints && file->cvt; michael@0: } michael@0: michael@0: bool ots_cvt_serialise(OTSStream *out, OpenTypeFile *file) { michael@0: const OpenTypeCVT *cvt = file->cvt; michael@0: michael@0: if (!out->Write(cvt->data, cvt->length)) { michael@0: return OTS_FAILURE_MSG("Failed to write CVT table"); michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: void ots_cvt_free(OpenTypeFile *file) { michael@0: delete file->cvt; michael@0: } michael@0: michael@0: } // namespace ots