Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "fpgm.h" |
michael@0 | 6 | |
michael@0 | 7 | // fpgm - Font Program |
michael@0 | 8 | // http://www.microsoft.com/typography/otspec/fpgm.htm |
michael@0 | 9 | |
michael@0 | 10 | #define TABLE_NAME "fpgm" |
michael@0 | 11 | |
michael@0 | 12 | namespace ots { |
michael@0 | 13 | |
michael@0 | 14 | bool ots_fpgm_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
michael@0 | 15 | Buffer table(data, length); |
michael@0 | 16 | |
michael@0 | 17 | OpenTypeFPGM *fpgm = new OpenTypeFPGM; |
michael@0 | 18 | file->fpgm = fpgm; |
michael@0 | 19 | |
michael@0 | 20 | if (length >= 128 * 1024u) { |
michael@0 | 21 | return OTS_FAILURE_MSG("length (%ld) > 120", length); // almost all fpgm tables are less than 5k bytes. |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | if (!table.Skip(length)) { |
michael@0 | 25 | return OTS_FAILURE_MSG("Bad fpgm length"); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | fpgm->data = data; |
michael@0 | 29 | fpgm->length = length; |
michael@0 | 30 | return true; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | bool ots_fpgm_should_serialise(OpenTypeFile *file) { |
michael@0 | 34 | if (!file->glyf) return false; // this table is not for CFF fonts. |
michael@0 | 35 | return g_transcode_hints && file->fpgm; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | bool ots_fpgm_serialise(OTSStream *out, OpenTypeFile *file) { |
michael@0 | 39 | const OpenTypeFPGM *fpgm = file->fpgm; |
michael@0 | 40 | |
michael@0 | 41 | if (!out->Write(fpgm->data, fpgm->length)) { |
michael@0 | 42 | return OTS_FAILURE_MSG("Failed to write fpgm"); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | return true; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | void ots_fpgm_free(OpenTypeFile *file) { |
michael@0 | 49 | delete file->fpgm; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | } // namespace ots |