1 // Copyright (c) 2011 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 "vhea.h"
6
7 #include "gsub.h"
8 #include "head.h"
9 #include "maxp.h"
10
11 // vhea - Vertical Header Table
12 // http://www.microsoft.com/opentype/otspec/vhea.htm
13
14 namespace ots {
15
ots_vhea_parse(OpenTypeFile * file,const uint8_t * data,size_t length)16 bool ots_vhea_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
17 Buffer table(data, length);
18 OpenTypeVHEA *vhea = new OpenTypeVHEA;
19 file->vhea = vhea;
20
21 if (!table.ReadU32(&vhea->header.version)) {
22 return OTS_FAILURE();
23 }
24 if (vhea->header.version != 0x00010000 &&
25 vhea->header.version != 0x00011000) {
26 return OTS_FAILURE();
27 }
28
29 if (!ParseMetricsHeader(file, &table, &vhea->header)) {
30 return OTS_FAILURE();
31 }
32
33 return true;
34 }
35
ots_vhea_should_serialise(OpenTypeFile * file)36 bool ots_vhea_should_serialise(OpenTypeFile *file) {
37 // vhea should'nt serialise when vmtx doesn't exist.
38 // Firefox developer pointed out that vhea/vmtx should serialise iff GSUB is
39 // preserved. See http://crbug.com/77386
40 return file->vhea != NULL && file->vmtx != NULL &&
41 ots_gsub_should_serialise(file);
42 }
43
ots_vhea_serialise(OTSStream * out,OpenTypeFile * file)44 bool ots_vhea_serialise(OTSStream *out, OpenTypeFile *file) {
45 if (!SerialiseMetricsHeader(out, &file->vhea->header)) {
46 return OTS_FAILURE();
47 }
48 return true;
49 }
50
ots_vhea_free(OpenTypeFile * file)51 void ots_vhea_free(OpenTypeFile *file) {
52 delete file->vhea;
53 }
54
55 } // namespace ots
56
57