Update V8 to version 4.7.44.
[chromium-blink-merge.git] / third_party / ots / src / cvt.cc
blob1402e7c06a66abfcd7065d5860cb334361ccce18
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.
5 #include "cvt.h"
7 // cvt - Control Value Table
8 // http://www.microsoft.com/typography/otspec/cvt.htm
10 #define TABLE_NAME "cvt"
12 namespace ots {
14 bool ots_cvt_parse(Font *font, const uint8_t *data, size_t length) {
15 Buffer table(data, length);
17 OpenTypeCVT *cvt = new OpenTypeCVT;
18 font->cvt = cvt;
20 if (length >= 128 * 1024u) {
21 return OTS_FAILURE_MSG("Length (%d) > 120K"); // almost all cvt tables are less than 4k bytes.
24 if (length % 2 != 0) {
25 return OTS_FAILURE_MSG("Uneven cvt length (%d)", length);
28 if (!table.Skip(length)) {
29 return OTS_FAILURE_MSG("Length too high");
32 cvt->data = data;
33 cvt->length = length;
34 return true;
37 bool ots_cvt_should_serialise(Font *font) {
38 if (!font->glyf) {
39 return false; // this table is not for CFF fonts.
41 return font->cvt != NULL;
44 bool ots_cvt_serialise(OTSStream *out, Font *font) {
45 const OpenTypeCVT *cvt = font->cvt;
47 if (!out->Write(cvt->data, cvt->length)) {
48 return OTS_FAILURE_MSG("Failed to write CVT table");
51 return true;
54 void ots_cvt_reuse(Font *font, Font *other) {
55 font->cvt = other->cvt;
56 font->cvt_reused = true;
59 void ots_cvt_free(Font *font) {
60 delete font->cvt;
63 } // namespace ots
65 #undef TABLE_NAME