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 "prep.h" michael@0: michael@0: // prep - Control Value Program michael@0: // http://www.microsoft.com/typography/otspec/prep.htm michael@0: michael@0: #define TABLE_NAME "prep" michael@0: michael@0: namespace ots { michael@0: michael@0: bool ots_prep_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { michael@0: Buffer table(data, length); michael@0: michael@0: OpenTypePREP *prep = new OpenTypePREP; michael@0: file->prep = prep; michael@0: michael@0: if (length >= 128 * 1024u) { michael@0: return OTS_FAILURE_MSG("table length %ld > 120K", length); // almost all prep tables are less than 9k bytes. michael@0: } michael@0: michael@0: if (!table.Skip(length)) { michael@0: return OTS_FAILURE_MSG("Failed to read table of length %ld", length); michael@0: } michael@0: michael@0: prep->data = data; michael@0: prep->length = length; michael@0: return true; michael@0: } michael@0: michael@0: bool ots_prep_should_serialise(OpenTypeFile *file) { michael@0: if (!file->glyf) return false; // this table is not for CFF fonts. michael@0: return g_transcode_hints && file->prep; michael@0: } michael@0: michael@0: bool ots_prep_serialise(OTSStream *out, OpenTypeFile *file) { michael@0: const OpenTypePREP *prep = file->prep; michael@0: michael@0: if (!out->Write(prep->data, prep->length)) { michael@0: return OTS_FAILURE_MSG("Failed to write table length"); michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: void ots_prep_free(OpenTypeFile *file) { michael@0: delete file->prep; michael@0: } michael@0: michael@0: } // namespace ots