gfx/ots/src/hhea.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/ots/src/hhea.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     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 "hhea.h"
     1.9 +
    1.10 +#include "head.h"
    1.11 +#include "maxp.h"
    1.12 +
    1.13 +// hhea - Horizontal Header
    1.14 +// http://www.microsoft.com/typography/otspec/hhea.htm
    1.15 +
    1.16 +#define TABLE_NAME "hhea"
    1.17 +
    1.18 +namespace ots {
    1.19 +
    1.20 +bool ots_hhea_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
    1.21 +  Buffer table(data, length);
    1.22 +  OpenTypeHHEA *hhea = new OpenTypeHHEA;
    1.23 +  file->hhea = hhea;
    1.24 +
    1.25 +  if (!table.ReadU32(&hhea->header.version)) {
    1.26 +    return OTS_FAILURE_MSG("Failed to read hhea version");
    1.27 +  }
    1.28 +  if (hhea->header.version >> 16 != 1) {
    1.29 +    return OTS_FAILURE_MSG("Bad hhea version of %d", hhea->header.version);
    1.30 +  }
    1.31 +
    1.32 +  if (!ParseMetricsHeader(file, &table, &hhea->header)) {
    1.33 +    return OTS_FAILURE_MSG("Failed to parse horizontal metrics");
    1.34 +  }
    1.35 +
    1.36 +  return true;
    1.37 +}
    1.38 +
    1.39 +bool ots_hhea_should_serialise(OpenTypeFile *file) {
    1.40 +  return file->hhea != NULL;
    1.41 +}
    1.42 +
    1.43 +bool ots_hhea_serialise(OTSStream *out, OpenTypeFile *file) {
    1.44 +  if (!SerialiseMetricsHeader(file, out, &file->hhea->header)) {
    1.45 +    return OTS_FAILURE_MSG("Failed to serialise horizontal metrics");
    1.46 +  }
    1.47 +  return true;
    1.48 +}
    1.49 +
    1.50 +void ots_hhea_free(OpenTypeFile *file) {
    1.51 +  delete file->hhea;
    1.52 +}
    1.53 +
    1.54 +}  // namespace ots

mercurial