gfx/ots/src/hmtx.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/ots/src/hmtx.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,49 @@
     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 "hmtx.h"
     1.9 +
    1.10 +#include "hhea.h"
    1.11 +#include "maxp.h"
    1.12 +
    1.13 +// hmtx - Horizontal Metrics
    1.14 +// http://www.microsoft.com/typography/otspec/hmtx.htm
    1.15 +
    1.16 +#define TABLE_NAME "hmtx"
    1.17 +
    1.18 +namespace ots {
    1.19 +
    1.20 +bool ots_hmtx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
    1.21 +  Buffer table(data, length);
    1.22 +  OpenTypeHMTX *hmtx = new OpenTypeHMTX;
    1.23 +  file->hmtx = hmtx;
    1.24 +
    1.25 +  if (!file->hhea || !file->maxp) {
    1.26 +    return OTS_FAILURE_MSG("Missing hhea or maxp tables in font, needed by hmtx");
    1.27 +  }
    1.28 +
    1.29 +  if (!ParseMetricsTable(file, &table, file->maxp->num_glyphs,
    1.30 +                         &file->hhea->header, &hmtx->metrics)) {
    1.31 +    return OTS_FAILURE_MSG("Failed to parse hmtx metrics");
    1.32 +  }
    1.33 +
    1.34 +  return true;
    1.35 +}
    1.36 +
    1.37 +bool ots_hmtx_should_serialise(OpenTypeFile *file) {
    1.38 +  return file->hmtx != NULL;
    1.39 +}
    1.40 +
    1.41 +bool ots_hmtx_serialise(OTSStream *out, OpenTypeFile *file) {
    1.42 +  if (!SerialiseMetricsTable(file, out, &file->hmtx->metrics)) {
    1.43 +    return OTS_FAILURE_MSG("Failed to serialise htmx metrics");
    1.44 +  }
    1.45 +  return true;
    1.46 +}
    1.47 +
    1.48 +void ots_hmtx_free(OpenTypeFile *file) {
    1.49 +  delete file->hmtx;
    1.50 +}
    1.51 +
    1.52 +}  // namespace ots

mercurial