Roll src/third_party/WebKit 06cb9e9:a978ee5 (svn 202558:202559)
[chromium-blink-merge.git] / third_party / ots / src / fpgm.cc
blobfaa9a2392ad5c3500954102d99c6c0ec355c297c
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.
5 #include "fpgm.h"
7 // fpgm - Font Program
8 // http://www.microsoft.com/typography/otspec/fpgm.htm
10 #define TABLE_NAME "fpgm"
12 namespace ots {
14 bool ots_fpgm_parse(Font *font, const uint8_t *data, size_t length) {
15 Buffer table(data, length);
17 OpenTypeFPGM *fpgm = new OpenTypeFPGM;
18 font->fpgm = fpgm;
20 if (length >= 128 * 1024u) {
21 return OTS_FAILURE_MSG("length (%ld) > 120", length); // almost all fpgm tables are less than 5k bytes.
24 if (!table.Skip(length)) {
25 return OTS_FAILURE_MSG("Bad fpgm length");
28 fpgm->data = data;
29 fpgm->length = length;
30 return true;
33 bool ots_fpgm_should_serialise(Font *font) {
34 if (!font->glyf) return false; // this table is not for CFF fonts.
35 return font->fpgm != NULL;
38 bool ots_fpgm_serialise(OTSStream *out, Font *font) {
39 const OpenTypeFPGM *fpgm = font->fpgm;
41 if (!out->Write(fpgm->data, fpgm->length)) {
42 return OTS_FAILURE_MSG("Failed to write fpgm");
45 return true;
48 void ots_fpgm_reuse(Font *font, Font *other) {
49 font->fpgm = other->fpgm;
50 font->fpgm_reused = true;
53 void ots_fpgm_free(Font *font) {
54 delete font->fpgm;
57 } // namespace ots
59 #undef TABLE_NAME