Roll src/third_party/WebKit 06cb9e9:a978ee5 (svn 202558:202559)
[chromium-blink-merge.git] / third_party / ots / src / vmtx.cc
blob0944e598baca6811d118d2c307a4f00b630767d8
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.
5 #include "vmtx.h"
7 #include "gsub.h"
8 #include "maxp.h"
9 #include "vhea.h"
11 // vmtx - Vertical Metrics Table
12 // http://www.microsoft.com/typography/otspec/vmtx.htm
14 #define TABLE_NAME "vmtx"
16 namespace ots {
18 bool ots_vmtx_parse(Font *font, const uint8_t *data, size_t length) {
19 Buffer table(data, length);
20 OpenTypeVMTX *vmtx = new OpenTypeVMTX;
21 font->vmtx = vmtx;
23 if (!font->vhea || !font->maxp) {
24 return OTS_FAILURE_MSG("vhea or maxp table missing as needed by vmtx");
27 if (!ParseMetricsTable(font, &table, font->maxp->num_glyphs,
28 &font->vhea->header, &vmtx->metrics)) {
29 return OTS_FAILURE_MSG("Failed to parse vmtx metrics");
32 return true;
35 bool ots_vmtx_should_serialise(Font *font) {
36 // vmtx should serialise when vhea and GSUB are preserved.
37 // See the comment in ots_vhea_should_serialise().
38 return font->vmtx != NULL && font->vhea != NULL &&
39 ots_gsub_should_serialise(font);
42 bool ots_vmtx_serialise(OTSStream *out, Font *font) {
43 if (!SerialiseMetricsTable(font, out, &font->vmtx->metrics)) {
44 return OTS_FAILURE_MSG("Failed to write vmtx metrics");
46 return true;
49 void ots_vmtx_reuse(Font *font, Font *other) {
50 font->vmtx = other->vmtx;
51 font->vmtx_reused = true;
54 void ots_vmtx_free(Font *font) {
55 delete font->vmtx;
58 } // namespace ots
60 #undef TABLE_NAME