blob: 6567a6f82ca07f23d887c6301f0d13df774653cf [file] [log] [blame]
yusukes@chromium.orgd257d182009-11-04 04:56:32 +00001// Copyright (c) 2009 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "prep.h"
6
7// prep - Control Value Program
8// http://www.microsoft.com/opentype/otspec/prep.htm
9
10namespace ots {
11
12bool ots_prep_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
13 Buffer table(data, length);
14
15 OpenTypePREP *prep = new OpenTypePREP;
16 file->prep = prep;
17
18 if (length >= 128 * 1024u) {
19 return OTS_FAILURE(); // almost all prep tables are less than 9k bytes.
20 }
21
22 if (!table.Skip(length)) {
23 return OTS_FAILURE();
24 }
25
26 prep->data = data;
27 prep->length = length;
28 return true;
29}
30
31bool ots_prep_should_serialise(OpenTypeFile *file) {
32 if (!file->glyf) return false; // this table is not for CFF fonts.
33 return g_transcode_hints && file->prep;
34}
35
36bool ots_prep_serialise(OTSStream *out, OpenTypeFile *file) {
37 const OpenTypePREP *prep = file->prep;
38
39 if (!out->Write(prep->data, prep->length)) {
40 return OTS_FAILURE();
41 }
42
43 return true;
44}
45
46void ots_prep_free(OpenTypeFile *file) {
47 delete file->prep;
48}
49
50} // namespace ots