1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/ots/src/cvt.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +// Copyright (c) 2009 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "cvt.h" 1.9 + 1.10 +// cvt - Control Value Table 1.11 +// http://www.microsoft.com/typography/otspec/cvt.htm 1.12 + 1.13 +#define TABLE_NAME "cvt" 1.14 + 1.15 +namespace ots { 1.16 + 1.17 +bool ots_cvt_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { 1.18 + Buffer table(data, length); 1.19 + 1.20 + OpenTypeCVT *cvt = new OpenTypeCVT; 1.21 + file->cvt = cvt; 1.22 + 1.23 + if (length >= 128 * 1024u) { 1.24 + return OTS_FAILURE_MSG("Length (%d) > 120K"); // almost all cvt tables are less than 4k bytes. 1.25 + } 1.26 + 1.27 + if (length % 2 != 0) { 1.28 + return OTS_FAILURE_MSG("Uneven cvt length (%d)", length); 1.29 + } 1.30 + 1.31 + if (!table.Skip(length)) { 1.32 + return OTS_FAILURE_MSG("Length too high"); 1.33 + } 1.34 + 1.35 + cvt->data = data; 1.36 + cvt->length = length; 1.37 + return true; 1.38 +} 1.39 + 1.40 +bool ots_cvt_should_serialise(OpenTypeFile *file) { 1.41 + if (!file->glyf) { 1.42 + return false; // this table is not for CFF fonts. 1.43 + } 1.44 + return g_transcode_hints && file->cvt; 1.45 +} 1.46 + 1.47 +bool ots_cvt_serialise(OTSStream *out, OpenTypeFile *file) { 1.48 + const OpenTypeCVT *cvt = file->cvt; 1.49 + 1.50 + if (!out->Write(cvt->data, cvt->length)) { 1.51 + return OTS_FAILURE_MSG("Failed to write CVT table"); 1.52 + } 1.53 + 1.54 + return true; 1.55 +} 1.56 + 1.57 +void ots_cvt_free(OpenTypeFile *file) { 1.58 + delete file->cvt; 1.59 +} 1.60 + 1.61 +} // namespace ots