blob: ea7491d2e38c02fef239ad91941706c30368f4e1 [file] [log] [blame]
yusukes@chromium.orgd257d182009-11-04 04:56:32 +00001// 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.
4
5#include "hmtx.h"
6
7#include "hhea.h"
8#include "maxp.h"
9
10// hmtx - Horizontal Metrics
11// http://www.microsoft.com/opentype/otspec/hmtx.htm
12
13namespace ots {
14
15bool ots_hmtx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
16 Buffer table(data, length);
17 OpenTypeHMTX *hmtx = new OpenTypeHMTX;
18 file->hmtx = hmtx;
19
20 if (!file->hhea || !file->maxp) {
21 return OTS_FAILURE();
22 }
23
bashi@chromium.org4dcad602011-03-28 20:51:38 +000024 if (!ParseMetricsTable(&table, file->maxp->num_glyphs,
25 &file->hhea->header, &hmtx->metrics)) {
yusukes@chromium.orgd257d182009-11-04 04:56:32 +000026 return OTS_FAILURE();
27 }
yusukes@chromium.orgd257d182009-11-04 04:56:32 +000028
29 return true;
30}
31
32bool ots_hmtx_should_serialise(OpenTypeFile *file) {
agl@chromium.org2beaf1d2011-01-21 17:19:34 +000033 return file->hmtx != NULL;
yusukes@chromium.orgd257d182009-11-04 04:56:32 +000034}
35
36bool ots_hmtx_serialise(OTSStream *out, OpenTypeFile *file) {
bashi@chromium.org4dcad602011-03-28 20:51:38 +000037 if (!SerialiseMetricsTable(out, &file->hmtx->metrics)) {
38 return OTS_FAILURE();
yusukes@chromium.orgd257d182009-11-04 04:56:32 +000039 }
yusukes@chromium.orgd257d182009-11-04 04:56:32 +000040 return true;
41}
42
43void ots_hmtx_free(OpenTypeFile *file) {
44 delete file->hmtx;
45}
46
47} // namespace ots