gfx/ots/src/prep.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/ots/src/prep.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     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 "prep.h"
     1.9 +
    1.10 +// prep - Control Value Program
    1.11 +// http://www.microsoft.com/typography/otspec/prep.htm
    1.12 +
    1.13 +#define TABLE_NAME "prep"
    1.14 +
    1.15 +namespace ots {
    1.16 +
    1.17 +bool ots_prep_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
    1.18 +  Buffer table(data, length);
    1.19 +
    1.20 +  OpenTypePREP *prep = new OpenTypePREP;
    1.21 +  file->prep = prep;
    1.22 +
    1.23 +  if (length >= 128 * 1024u) {
    1.24 +    return OTS_FAILURE_MSG("table length %ld > 120K", length);  // almost all prep tables are less than 9k bytes.
    1.25 +  }
    1.26 +
    1.27 +  if (!table.Skip(length)) {
    1.28 +    return OTS_FAILURE_MSG("Failed to read table of length %ld", length);
    1.29 +  }
    1.30 +
    1.31 +  prep->data = data;
    1.32 +  prep->length = length;
    1.33 +  return true;
    1.34 +}
    1.35 +
    1.36 +bool ots_prep_should_serialise(OpenTypeFile *file) {
    1.37 +  if (!file->glyf) return false;  // this table is not for CFF fonts.
    1.38 +  return g_transcode_hints && file->prep;
    1.39 +}
    1.40 +
    1.41 +bool ots_prep_serialise(OTSStream *out, OpenTypeFile *file) {
    1.42 +  const OpenTypePREP *prep = file->prep;
    1.43 +
    1.44 +  if (!out->Write(prep->data, prep->length)) {
    1.45 +    return OTS_FAILURE_MSG("Failed to write table length");
    1.46 +  }
    1.47 +
    1.48 +  return true;
    1.49 +}
    1.50 +
    1.51 +void ots_prep_free(OpenTypeFile *file) {
    1.52 +  delete file->prep;
    1.53 +}
    1.54 +
    1.55 +}  // namespace ots

mercurial