gfx/ots/src/prep.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 "prep.h"
     7 // prep - Control Value Program
     8 // http://www.microsoft.com/typography/otspec/prep.htm
    10 #define TABLE_NAME "prep"
    12 namespace ots {
    14 bool ots_prep_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
    15   Buffer table(data, length);
    17   OpenTypePREP *prep = new OpenTypePREP;
    18   file->prep = prep;
    20   if (length >= 128 * 1024u) {
    21     return OTS_FAILURE_MSG("table length %ld > 120K", length);  // almost all prep tables are less than 9k bytes.
    22   }
    24   if (!table.Skip(length)) {
    25     return OTS_FAILURE_MSG("Failed to read table of length %ld", length);
    26   }
    28   prep->data = data;
    29   prep->length = length;
    30   return true;
    31 }
    33 bool ots_prep_should_serialise(OpenTypeFile *file) {
    34   if (!file->glyf) return false;  // this table is not for CFF fonts.
    35   return g_transcode_hints && file->prep;
    36 }
    38 bool ots_prep_serialise(OTSStream *out, OpenTypeFile *file) {
    39   const OpenTypePREP *prep = file->prep;
    41   if (!out->Write(prep->data, prep->length)) {
    42     return OTS_FAILURE_MSG("Failed to write table length");
    43   }
    45   return true;
    46 }
    48 void ots_prep_free(OpenTypeFile *file) {
    49   delete file->prep;
    50 }
    52 }  // namespace ots

mercurial