bashi@chromium.org | 4dcad60 | 2011-03-28 20:51:38 +0000 | [diff] [blame] | 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 "vmtx.h" |
| 6 | |
| 7 | #include "gsub.h" |
| 8 | #include "maxp.h" |
| 9 | #include "vhea.h" |
| 10 | |
| 11 | // vmtx - Vertical Metrics Table |
| 12 | // http://www.microsoft.com/opentype/otspec/vmtx.htm |
| 13 | |
| 14 | namespace ots { |
| 15 | |
| 16 | bool ots_vmtx_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
| 17 | Buffer table(data, length); |
| 18 | OpenTypeVMTX *vmtx = new OpenTypeVMTX; |
| 19 | file->vmtx = vmtx; |
| 20 | |
| 21 | if (!file->vhea || !file->maxp) { |
| 22 | return OTS_FAILURE(); |
| 23 | } |
| 24 | |
| 25 | if (!ParseMetricsTable(&table, file->maxp->num_glyphs, |
| 26 | &file->vhea->header, &vmtx->metrics)) { |
| 27 | return OTS_FAILURE(); |
| 28 | } |
| 29 | |
| 30 | return true; |
| 31 | } |
| 32 | |
| 33 | bool ots_vmtx_should_serialise(OpenTypeFile *file) { |
| 34 | // vmtx should serialise when vhea and GSUB are preserved. |
| 35 | // See the comment in ots_vhea_should_serialise(). |
| 36 | return file->vmtx != NULL && file->vhea != NULL && |
| 37 | ots_gsub_should_serialise(file); |
| 38 | } |
| 39 | |
| 40 | bool ots_vmtx_serialise(OTSStream *out, OpenTypeFile *file) { |
| 41 | if (!SerialiseMetricsTable(out, &file->vmtx->metrics)) { |
| 42 | return OTS_FAILURE(); |
| 43 | } |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | void ots_vmtx_free(OpenTypeFile *file) { |
| 48 | delete file->vmtx; |
| 49 | } |
| 50 | |
| 51 | } // namespace ots |
| 52 | |