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 "hmtx.h"
6 :
7 : #include "hhea.h"
8 : #include "maxp.h"
9 :
10 : // hmtx - Horizontal Metrics
11 : // http://www.microsoft.com/typography/otspec/hmtx.htm
12 :
13 : #define TABLE_NAME "hmtx"
14 :
15 : namespace ots {
16 :
17 0 : bool ots_hmtx_parse(Font *font, const uint8_t *data, size_t length) {
18 0 : Buffer table(data, length);
19 0 : OpenTypeHMTX *hmtx = new OpenTypeHMTX;
20 0 : font->hmtx = hmtx;
21 :
22 0 : if (!font->hhea || !font->maxp) {
23 0 : return OTS_FAILURE_MSG("Missing hhea or maxp tables in font, needed by hmtx");
24 : }
25 :
26 0 : if (!ParseMetricsTable(font, &table, font->maxp->num_glyphs,
27 0 : &font->hhea->header, &hmtx->metrics)) {
28 0 : return OTS_FAILURE_MSG("Failed to parse hmtx metrics");
29 : }
30 :
31 0 : return true;
32 : }
33 :
34 0 : bool ots_hmtx_should_serialise(Font *font) {
35 0 : return font->hmtx != NULL;
36 : }
37 :
38 0 : bool ots_hmtx_serialise(OTSStream *out, Font *font) {
39 0 : if (!SerialiseMetricsTable(font, out, &font->hmtx->metrics)) {
40 0 : return OTS_FAILURE_MSG("Failed to serialise htmx metrics");
41 : }
42 0 : return true;
43 : }
44 :
45 0 : void ots_hmtx_reuse(Font *font, Font *other) {
46 0 : font->hmtx = other->hmtx;
47 0 : font->hmtx_reused = true;
48 0 : }
49 :
50 0 : void ots_hmtx_free(Font *font) {
51 0 : delete font->hmtx;
52 0 : }
53 :
54 : } // namespace ots
55 :
56 : #undef TABLE_NAME
|