Line data Source code
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 "hhea.h"
6 :
7 : #include "head.h"
8 : #include "maxp.h"
9 :
10 : // hhea - Horizontal Header
11 : // http://www.microsoft.com/typography/otspec/hhea.htm
12 :
13 : #define TABLE_NAME "hhea"
14 :
15 : namespace ots {
16 :
17 0 : bool ots_hhea_parse(Font *font, const uint8_t *data, size_t length) {
18 0 : Buffer table(data, length);
19 0 : OpenTypeHHEA *hhea = new OpenTypeHHEA;
20 0 : font->hhea = hhea;
21 :
22 0 : if (!table.ReadU32(&hhea->header.version)) {
23 0 : return OTS_FAILURE_MSG("Failed to read hhea version");
24 : }
25 0 : if (hhea->header.version >> 16 != 1) {
26 0 : return OTS_FAILURE_MSG("Bad hhea version of %d", hhea->header.version);
27 : }
28 :
29 0 : if (!ParseMetricsHeader(font, &table, &hhea->header)) {
30 0 : return OTS_FAILURE_MSG("Failed to parse horizontal metrics");
31 : }
32 :
33 0 : return true;
34 : }
35 :
36 0 : bool ots_hhea_should_serialise(Font *font) {
37 0 : return font->hhea != NULL;
38 : }
39 :
40 0 : bool ots_hhea_serialise(OTSStream *out, Font *font) {
41 0 : if (!SerialiseMetricsHeader(font, out, &font->hhea->header)) {
42 0 : return OTS_FAILURE_MSG("Failed to serialise horizontal metrics");
43 : }
44 0 : return true;
45 : }
46 :
47 0 : void ots_hhea_reuse(Font *font, Font *other) {
48 0 : font->hhea = other->hhea;
49 0 : font->hhea_reused = true;
50 0 : }
51 :
52 0 : void ots_hhea_free(Font *font) {
53 0 : delete font->hhea;
54 0 : }
55 :
56 : } // namespace ots
57 :
58 : #undef TABLE_NAME
|