gfx/ots/src/fpgm.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/ots/src/fpgm.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 "fpgm.h"
     1.9 +
    1.10 +// fpgm - Font Program
    1.11 +// http://www.microsoft.com/typography/otspec/fpgm.htm
    1.12 +
    1.13 +#define TABLE_NAME "fpgm"
    1.14 +
    1.15 +namespace ots {
    1.16 +
    1.17 +bool ots_fpgm_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
    1.18 +  Buffer table(data, length);
    1.19 +
    1.20 +  OpenTypeFPGM *fpgm = new OpenTypeFPGM;
    1.21 +  file->fpgm = fpgm;
    1.22 +
    1.23 +  if (length >= 128 * 1024u) {
    1.24 +    return OTS_FAILURE_MSG("length (%ld) > 120", length);  // almost all fpgm tables are less than 5k bytes.
    1.25 +  }
    1.26 +
    1.27 +  if (!table.Skip(length)) {
    1.28 +    return OTS_FAILURE_MSG("Bad fpgm length");
    1.29 +  }
    1.30 +
    1.31 +  fpgm->data = data;
    1.32 +  fpgm->length = length;
    1.33 +  return true;
    1.34 +}
    1.35 +
    1.36 +bool ots_fpgm_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->fpgm;
    1.39 +}
    1.40 +
    1.41 +bool ots_fpgm_serialise(OTSStream *out, OpenTypeFile *file) {
    1.42 +  const OpenTypeFPGM *fpgm = file->fpgm;
    1.43 +
    1.44 +  if (!out->Write(fpgm->data, fpgm->length)) {
    1.45 +    return OTS_FAILURE_MSG("Failed to write fpgm");
    1.46 +  }
    1.47 +
    1.48 +  return true;
    1.49 +}
    1.50 +
    1.51 +void ots_fpgm_free(OpenTypeFile *file) {
    1.52 +  delete file->fpgm;
    1.53 +}
    1.54 +
    1.55 +}  // namespace ots

mercurial