| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 "cvt.h" | 5 #include "cvt.h" |
| 6 | 6 |
| 7 // cvt - Control Value Table | 7 // cvt - Control Value Table |
| 8 // http://www.microsoft.com/typography/otspec/cvt.htm | 8 // http://www.microsoft.com/typography/otspec/cvt.htm |
| 9 | 9 |
| 10 #define TABLE_NAME "cvt" | 10 #define TABLE_NAME "cvt" |
| 11 | 11 |
| 12 namespace ots { | 12 namespace ots { |
| 13 | 13 |
| 14 bool ots_cvt_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { | 14 bool ots_cvt_parse(Font *font, const uint8_t *data, size_t length) { |
| 15 Buffer table(data, length); | 15 Buffer table(data, length); |
| 16 | 16 |
| 17 OpenTypeCVT *cvt = new OpenTypeCVT; | 17 OpenTypeCVT *cvt = new OpenTypeCVT; |
| 18 file->cvt = cvt; | 18 font->cvt = cvt; |
| 19 | 19 |
| 20 if (length >= 128 * 1024u) { | 20 if (length >= 128 * 1024u) { |
| 21 return OTS_FAILURE_MSG("Length (%d) > 120K"); // almost all cvt tables are
less than 4k bytes. | 21 return OTS_FAILURE_MSG("Length (%d) > 120K"); // almost all cvt tables are
less than 4k bytes. |
| 22 } | 22 } |
| 23 | 23 |
| 24 if (length % 2 != 0) { | 24 if (length % 2 != 0) { |
| 25 return OTS_FAILURE_MSG("Uneven cvt length (%d)", length); | 25 return OTS_FAILURE_MSG("Uneven cvt length (%d)", length); |
| 26 } | 26 } |
| 27 | 27 |
| 28 if (!table.Skip(length)) { | 28 if (!table.Skip(length)) { |
| 29 return OTS_FAILURE_MSG("Length too high"); | 29 return OTS_FAILURE_MSG("Length too high"); |
| 30 } | 30 } |
| 31 | 31 |
| 32 cvt->data = data; | 32 cvt->data = data; |
| 33 cvt->length = length; | 33 cvt->length = length; |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool ots_cvt_should_serialise(OpenTypeFile *file) { | 37 bool ots_cvt_should_serialise(Font *font) { |
| 38 if (!file->glyf) { | 38 if (!font->glyf) { |
| 39 return false; // this table is not for CFF fonts. | 39 return false; // this table is not for CFF fonts. |
| 40 } | 40 } |
| 41 return file->cvt != NULL; | 41 return font->cvt != NULL; |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool ots_cvt_serialise(OTSStream *out, OpenTypeFile *file) { | 44 bool ots_cvt_serialise(OTSStream *out, Font *font) { |
| 45 const OpenTypeCVT *cvt = file->cvt; | 45 const OpenTypeCVT *cvt = font->cvt; |
| 46 | 46 |
| 47 if (!out->Write(cvt->data, cvt->length)) { | 47 if (!out->Write(cvt->data, cvt->length)) { |
| 48 return OTS_FAILURE_MSG("Failed to write CVT table"); | 48 return OTS_FAILURE_MSG("Failed to write CVT table"); |
| 49 } | 49 } |
| 50 | 50 |
| 51 return true; | 51 return true; |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ots_cvt_free(OpenTypeFile *file) { | 54 void ots_cvt_reuse(Font *font, Font *other) { |
| 55 delete file->cvt; | 55 font->cvt = other->cvt; |
| 56 font->cvt_reused = true; |
| 57 } |
| 58 |
| 59 void ots_cvt_free(Font *font) { |
| 60 delete font->cvt; |
| 56 } | 61 } |
| 57 | 62 |
| 58 } // namespace ots | 63 } // namespace ots |
| 59 | 64 |
| 60 #undef TABLE_NAME | 65 #undef TABLE_NAME |
| OLD | NEW |