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 "cvt.h"
6 :
7 : // cvt - Control Value Table
8 : // http://www.microsoft.com/typography/otspec/cvt.htm
9 :
10 : #define TABLE_NAME "cvt"
11 :
12 : namespace ots {
13 :
14 0 : bool ots_cvt_parse(Font *font, const uint8_t *data, size_t length) {
15 0 : Buffer table(data, length);
16 :
17 0 : OpenTypeCVT *cvt = new OpenTypeCVT;
18 0 : font->cvt = cvt;
19 :
20 0 : if (length >= 128 * 1024u) {
21 0 : return OTS_FAILURE_MSG("Length (%d) > 120K"); // almost all cvt tables are less than 4k bytes.
22 : }
23 :
24 0 : if (length % 2 != 0) {
25 0 : return OTS_FAILURE_MSG("Uneven cvt length (%d)", length);
26 : }
27 :
28 0 : if (!table.Skip(length)) {
29 0 : return OTS_FAILURE_MSG("Length too high");
30 : }
31 :
32 0 : cvt->data = data;
33 0 : cvt->length = length;
34 0 : return true;
35 : }
36 :
37 0 : bool ots_cvt_should_serialise(Font *font) {
38 0 : if (!font->glyf) {
39 0 : return false; // this table is not for CFF fonts.
40 : }
41 0 : return font->cvt != NULL;
42 : }
43 :
44 0 : bool ots_cvt_serialise(OTSStream *out, Font *font) {
45 0 : const OpenTypeCVT *cvt = font->cvt;
46 :
47 0 : if (!out->Write(cvt->data, cvt->length)) {
48 0 : return OTS_FAILURE_MSG("Failed to write CVT table");
49 : }
50 :
51 0 : return true;
52 : }
53 :
54 0 : void ots_cvt_reuse(Font *font, Font *other) {
55 0 : font->cvt = other->cvt;
56 0 : font->cvt_reused = true;
57 0 : }
58 :
59 0 : void ots_cvt_free(Font *font) {
60 0 : delete font->cvt;
61 0 : }
62 :
63 : } // namespace ots
64 :
65 : #undef TABLE_NAME
|