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