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