1 // 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
13 namespace ots {
14
ots_hmtx_parse(OpenTypeFile * file,const uint8_t * data,size_t length)15 bool 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
24 if (!ParseMetricsTable(&table, file->maxp->num_glyphs,
25 &file->hhea->header, &hmtx->metrics)) {
26 return OTS_FAILURE();
27 }
28
29 return true;
30 }
31
ots_hmtx_should_serialise(OpenTypeFile * file)32 bool ots_hmtx_should_serialise(OpenTypeFile *file) {
33 return file->hmtx != NULL;
34 }
35
ots_hmtx_serialise(OTSStream * out,OpenTypeFile * file)36 bool ots_hmtx_serialise(OTSStream *out, OpenTypeFile *file) {
37 if (!SerialiseMetricsTable(out, &file->hmtx->metrics)) {
38 return OTS_FAILURE();
39 }
40 return true;
41 }
42
ots_hmtx_free(OpenTypeFile * file)43 void ots_hmtx_free(OpenTypeFile *file) {
44 delete file->hmtx;
45 }
46
47 } // namespace ots
48