Line data Source code
1 : // 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/typography/otspec/prep.htm
9 :
10 : #define TABLE_NAME "prep"
11 :
12 : namespace ots {
13 :
14 0 : bool ots_prep_parse(Font *font, const uint8_t *data, size_t length) {
15 0 : Buffer table(data, length);
16 :
17 0 : OpenTypePREP *prep = new OpenTypePREP;
18 0 : font->prep = prep;
19 :
20 0 : if (length >= 128 * 1024u) {
21 0 : return OTS_FAILURE_MSG("table length %ld > 120K", length); // almost all prep tables are less than 9k bytes.
22 : }
23 :
24 0 : if (!table.Skip(length)) {
25 0 : return OTS_FAILURE_MSG("Failed to read table of length %ld", length);
26 : }
27 :
28 0 : prep->data = data;
29 0 : prep->length = length;
30 0 : return true;
31 : }
32 :
33 0 : bool ots_prep_should_serialise(Font *font) {
34 0 : if (!font->glyf) return false; // this table is not for CFF fonts.
35 0 : return font->prep != NULL;
36 : }
37 :
38 0 : bool ots_prep_serialise(OTSStream *out, Font *font) {
39 0 : const OpenTypePREP *prep = font->prep;
40 :
41 0 : if (!out->Write(prep->data, prep->length)) {
42 0 : return OTS_FAILURE_MSG("Failed to write table length");
43 : }
44 :
45 0 : return true;
46 : }
47 :
48 0 : void ots_prep_reuse(Font *font, Font *other) {
49 0 : font->prep = other->prep;
50 0 : font->prep_reused = true;
51 0 : }
52 :
53 0 : void ots_prep_free(Font *font) {
54 0 : delete font->prep;
55 0 : }
56 :
57 : } // namespace ots
58 :
59 : #undef TABLE_NAME
|