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 "cvt.h"
6 :
7 : // cvt - Control Value Table
8 : // http://www.microsoft.com/opentype/otspec/cvt.htm
9 :
10 : namespace ots {
11 :
12 0 : bool ots_cvt_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
13 0 : Buffer table(data, length);
14 :
15 0 : OpenTypeCVT *cvt = new OpenTypeCVT;
16 0 : file->cvt = cvt;
17 :
18 0 : if (length >= 128 * 1024u) {
19 0 : return OTS_FAILURE(); // almost all cvt tables are less than 4k bytes.
20 : }
21 :
22 0 : if (length % 2 != 0) {
23 0 : return OTS_FAILURE();
24 : }
25 :
26 0 : if (!table.Skip(length)) {
27 0 : return OTS_FAILURE();
28 : }
29 :
30 0 : cvt->data = data;
31 0 : cvt->length = length;
32 0 : return true;
33 : }
34 :
35 0 : bool ots_cvt_should_serialise(OpenTypeFile *file) {
36 0 : if (!file->glyf) {
37 0 : return false; // this table is not for CFF fonts.
38 : }
39 0 : return g_transcode_hints && file->cvt;
40 : }
41 :
42 0 : bool ots_cvt_serialise(OTSStream *out, OpenTypeFile *file) {
43 0 : const OpenTypeCVT *cvt = file->cvt;
44 :
45 0 : if (!out->Write(cvt->data, cvt->length)) {
46 0 : return OTS_FAILURE();
47 : }
48 :
49 0 : return true;
50 : }
51 :
52 0 : void ots_cvt_free(OpenTypeFile *file) {
53 0 : delete file->cvt;
54 0 : }
55 :
56 : } // namespace ots
|