Roll src/third_party/WebKit 06cb9e9:a978ee5 (svn 202558:202559)
[chromium-blink-merge.git] / third_party / ots / src / hmtx.cc
blob667d1fe6f5663b906e4f52a1d8d8d110c3284571
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.
5 #include "hmtx.h"
7 #include "hhea.h"
8 #include "maxp.h"
10 // hmtx - Horizontal Metrics
11 // http://www.microsoft.com/typography/otspec/hmtx.htm
13 #define TABLE_NAME "hmtx"
15 namespace ots {
17 bool ots_hmtx_parse(Font *font, const uint8_t *data, size_t length) {
18 Buffer table(data, length);
19 OpenTypeHMTX *hmtx = new OpenTypeHMTX;
20 font->hmtx = hmtx;
22 if (!font->hhea || !font->maxp) {
23 return OTS_FAILURE_MSG("Missing hhea or maxp tables in font, needed by hmtx");
26 if (!ParseMetricsTable(font, &table, font->maxp->num_glyphs,
27 &font->hhea->header, &hmtx->metrics)) {
28 return OTS_FAILURE_MSG("Failed to parse hmtx metrics");
31 return true;
34 bool ots_hmtx_should_serialise(Font *font) {
35 return font->hmtx != NULL;
38 bool ots_hmtx_serialise(OTSStream *out, Font *font) {
39 if (!SerialiseMetricsTable(font, out, &font->hmtx->metrics)) {
40 return OTS_FAILURE_MSG("Failed to serialise htmx metrics");
42 return true;
45 void ots_hmtx_reuse(Font *font, Font *other) {
46 font->hmtx = other->hmtx;
47 font->hmtx_reused = true;
50 void ots_hmtx_free(Font *font) {
51 delete font->hmtx;
54 } // namespace ots
56 #undef TABLE_NAME