yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 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/opentype/otspec/hmtx.htm |
| 12 | |
| 13 | namespace ots { |
| 14 | |
| 15 | bool ots_hmtx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
| 16 | Buffer table(data, length); |
| 17 | OpenTypeHMTX *hmtx = new OpenTypeHMTX; |
| 18 | file->hmtx = hmtx; |
| 19 | |
| 20 | if (!file->hhea || !file->maxp) { |
| 21 | return OTS_FAILURE(); |
| 22 | } |
| 23 | |
bashi@chromium.org | 4dcad60 | 2011-03-28 20:51:38 +0000 | [diff] [blame] | 24 | if (!ParseMetricsTable(&table, file->maxp->num_glyphs, |
| 25 | &file->hhea->header, &hmtx->metrics)) { |
yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 26 | return OTS_FAILURE(); |
| 27 | } |
yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 28 | |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | bool ots_hmtx_should_serialise(OpenTypeFile *file) { |
agl@chromium.org | 2beaf1d | 2011-01-21 17:19:34 +0000 | [diff] [blame] | 33 | return file->hmtx != NULL; |
yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | bool ots_hmtx_serialise(OTSStream *out, OpenTypeFile *file) { |
bashi@chromium.org | 4dcad60 | 2011-03-28 20:51:38 +0000 | [diff] [blame] | 37 | if (!SerialiseMetricsTable(out, &file->hmtx->metrics)) { |
| 38 | return OTS_FAILURE(); |
yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 39 | } |
yusukes@chromium.org | d257d18 | 2009-11-04 04:56:32 +0000 | [diff] [blame] | 40 | return true; |
| 41 | } |
| 42 | |
| 43 | void ots_hmtx_free(OpenTypeFile *file) { |
| 44 | delete file->hmtx; |
| 45 | } |
| 46 | |
| 47 | } // namespace ots |