| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vhea.h" | 5 #include "vhea.h" |
| 6 | 6 |
| 7 #include "gsub.h" | 7 #include "gsub.h" |
| 8 #include "head.h" | 8 #include "head.h" |
| 9 #include "maxp.h" | 9 #include "maxp.h" |
| 10 | 10 |
| 11 // vhea - Vertical Header Table | 11 // vhea - Vertical Header Table |
| 12 // http://www.microsoft.com/typography/otspec/vhea.htm | 12 // http://www.microsoft.com/typography/otspec/vhea.htm |
| 13 | 13 |
| 14 #define TABLE_NAME "vhea" | 14 #define TABLE_NAME "vhea" |
| 15 | 15 |
| 16 namespace ots { | 16 namespace ots { |
| 17 | 17 |
| 18 bool ots_vhea_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { | 18 bool ots_vhea_parse(Font *font, const uint8_t *data, size_t length) { |
| 19 Buffer table(data, length); | 19 Buffer table(data, length); |
| 20 OpenTypeVHEA *vhea = new OpenTypeVHEA; | 20 OpenTypeVHEA *vhea = new OpenTypeVHEA; |
| 21 file->vhea = vhea; | 21 font->vhea = vhea; |
| 22 | 22 |
| 23 if (!table.ReadU32(&vhea->header.version)) { | 23 if (!table.ReadU32(&vhea->header.version)) { |
| 24 return OTS_FAILURE_MSG("Failed to read version"); | 24 return OTS_FAILURE_MSG("Failed to read version"); |
| 25 } | 25 } |
| 26 if (vhea->header.version != 0x00010000 && | 26 if (vhea->header.version != 0x00010000 && |
| 27 vhea->header.version != 0x00011000) { | 27 vhea->header.version != 0x00011000) { |
| 28 return OTS_FAILURE_MSG("Bad vhea version %x", vhea->header.version); | 28 return OTS_FAILURE_MSG("Bad vhea version %x", vhea->header.version); |
| 29 } | 29 } |
| 30 | 30 |
| 31 if (!ParseMetricsHeader(file, &table, &vhea->header)) { | 31 if (!ParseMetricsHeader(font, &table, &vhea->header)) { |
| 32 return OTS_FAILURE_MSG("Failed to parse metrics in vhea"); | 32 return OTS_FAILURE_MSG("Failed to parse metrics in vhea"); |
| 33 } | 33 } |
| 34 | 34 |
| 35 return true; | 35 return true; |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool ots_vhea_should_serialise(OpenTypeFile *file) { | 38 bool ots_vhea_should_serialise(Font *font) { |
| 39 // vhea should'nt serialise when vmtx doesn't exist. | 39 // vhea should'nt serialise when vmtx doesn't exist. |
| 40 // Firefox developer pointed out that vhea/vmtx should serialise iff GSUB is | 40 // Firefox developer pointed out that vhea/vmtx should serialise iff GSUB is |
| 41 // preserved. See http://crbug.com/77386 | 41 // preserved. See http://crbug.com/77386 |
| 42 return file->vhea != NULL && file->vmtx != NULL && | 42 return font->vhea != NULL && font->vmtx != NULL && |
| 43 ots_gsub_should_serialise(file); | 43 ots_gsub_should_serialise(font); |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool ots_vhea_serialise(OTSStream *out, OpenTypeFile *file) { | 46 bool ots_vhea_serialise(OTSStream *out, Font *font) { |
| 47 if (!SerialiseMetricsHeader(file, out, &file->vhea->header)) { | 47 if (!SerialiseMetricsHeader(font, out, &font->vhea->header)) { |
| 48 return OTS_FAILURE_MSG("Failed to write vhea metrics"); | 48 return OTS_FAILURE_MSG("Failed to write vhea metrics"); |
| 49 } | 49 } |
| 50 return true; | 50 return true; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void ots_vhea_free(OpenTypeFile *file) { | 53 void ots_vhea_reuse(Font *font, Font *other) { |
| 54 delete file->vhea; | 54 font->vhea = other->vhea; |
| 55 font->vhea_reused = true; |
| 56 } |
| 57 |
| 58 void ots_vhea_free(Font *font) { |
| 59 delete font->vhea; |
| 55 } | 60 } |
| 56 | 61 |
| 57 } // namespace ots | 62 } // namespace ots |
| 58 | 63 |
| 59 #undef TABLE_NAME | 64 #undef TABLE_NAME |
| OLD | NEW |