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 "prep.h" |
michael@0 | 6 | |
michael@0 | 7 | // prep - Control Value Program |
michael@0 | 8 | // http://www.microsoft.com/typography/otspec/prep.htm |
michael@0 | 9 | |
michael@0 | 10 | #define TABLE_NAME "prep" |
michael@0 | 11 | |
michael@0 | 12 | namespace ots { |
michael@0 | 13 | |
michael@0 | 14 | bool ots_prep_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
michael@0 | 15 | Buffer table(data, length); |
michael@0 | 16 | |
michael@0 | 17 | OpenTypePREP *prep = new OpenTypePREP; |
michael@0 | 18 | file->prep = prep; |
michael@0 | 19 | |
michael@0 | 20 | if (length >= 128 * 1024u) { |
michael@0 | 21 | return OTS_FAILURE_MSG("table length %ld > 120K", length); // almost all prep tables are less than 9k bytes. |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | if (!table.Skip(length)) { |
michael@0 | 25 | return OTS_FAILURE_MSG("Failed to read table of length %ld", length); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | prep->data = data; |
michael@0 | 29 | prep->length = length; |
michael@0 | 30 | return true; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | bool ots_prep_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->prep; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | bool ots_prep_serialise(OTSStream *out, OpenTypeFile *file) { |
michael@0 | 39 | const OpenTypePREP *prep = file->prep; |
michael@0 | 40 | |
michael@0 | 41 | if (!out->Write(prep->data, prep->length)) { |
michael@0 | 42 | return OTS_FAILURE_MSG("Failed to write table length"); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | return true; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | void ots_prep_free(OpenTypeFile *file) { |
michael@0 | 49 | delete file->prep; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | } // namespace ots |