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 "maxp.h" |
michael@0 | 6 | |
michael@0 | 7 | // maxp - Maximum Profile |
michael@0 | 8 | // http://www.microsoft.com/typography/otspec/maxp.htm |
michael@0 | 9 | |
michael@0 | 10 | #define TABLE_NAME "maxp" |
michael@0 | 11 | |
michael@0 | 12 | namespace ots { |
michael@0 | 13 | |
michael@0 | 14 | bool ots_maxp_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { |
michael@0 | 15 | Buffer table(data, length); |
michael@0 | 16 | |
michael@0 | 17 | OpenTypeMAXP *maxp = new OpenTypeMAXP; |
michael@0 | 18 | file->maxp = maxp; |
michael@0 | 19 | |
michael@0 | 20 | uint32_t version = 0; |
michael@0 | 21 | if (!table.ReadU32(&version)) { |
michael@0 | 22 | return OTS_FAILURE_MSG("Failed to read version of maxp table"); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | if (version >> 16 > 1) { |
michael@0 | 26 | return OTS_FAILURE_MSG("Bad maxp version %d", version); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | if (!table.ReadU16(&maxp->num_glyphs)) { |
michael@0 | 30 | return OTS_FAILURE_MSG("Failed to read number of glyphs from maxp table"); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | if (!maxp->num_glyphs) { |
michael@0 | 34 | return OTS_FAILURE_MSG("Bad number of glyphs 0 in maxp table"); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | if (version >> 16 == 1) { |
michael@0 | 38 | maxp->version_1 = true; |
michael@0 | 39 | if (!table.ReadU16(&maxp->max_points) || |
michael@0 | 40 | !table.ReadU16(&maxp->max_contours) || |
michael@0 | 41 | !table.ReadU16(&maxp->max_c_points) || |
michael@0 | 42 | !table.ReadU16(&maxp->max_c_contours) || |
michael@0 | 43 | !table.ReadU16(&maxp->max_zones) || |
michael@0 | 44 | !table.ReadU16(&maxp->max_t_points) || |
michael@0 | 45 | !table.ReadU16(&maxp->max_storage) || |
michael@0 | 46 | !table.ReadU16(&maxp->max_fdefs) || |
michael@0 | 47 | !table.ReadU16(&maxp->max_idefs) || |
michael@0 | 48 | !table.ReadU16(&maxp->max_stack) || |
michael@0 | 49 | !table.ReadU16(&maxp->max_size_glyf_instructions) || |
michael@0 | 50 | !table.ReadU16(&maxp->max_c_components) || |
michael@0 | 51 | !table.ReadU16(&maxp->max_c_depth)) { |
michael@0 | 52 | return OTS_FAILURE_MSG("Failed to read maxp table"); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | if (maxp->max_zones == 0) { |
michael@0 | 56 | // workaround for ipa*.ttf Japanese fonts. |
michael@0 | 57 | OTS_WARNING("bad max_zones: %u", maxp->max_zones); |
michael@0 | 58 | maxp->max_zones = 1; |
michael@0 | 59 | } else if (maxp->max_zones == 3) { |
michael@0 | 60 | // workaround for Ecolier-*.ttf fonts. |
michael@0 | 61 | OTS_WARNING("bad max_zones: %u", maxp->max_zones); |
michael@0 | 62 | maxp->max_zones = 2; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | if ((maxp->max_zones != 1) && (maxp->max_zones != 2)) { |
michael@0 | 66 | return OTS_FAILURE_MSG("Bad max zones %d in maxp", maxp->max_zones); |
michael@0 | 67 | } |
michael@0 | 68 | } else { |
michael@0 | 69 | maxp->version_1 = false; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | return true; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | bool ots_maxp_should_serialise(OpenTypeFile *file) { |
michael@0 | 76 | return file->maxp != NULL; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | bool ots_maxp_serialise(OTSStream *out, OpenTypeFile *file) { |
michael@0 | 80 | const OpenTypeMAXP *maxp = file->maxp; |
michael@0 | 81 | |
michael@0 | 82 | if (!out->WriteU32(maxp->version_1 ? 0x00010000 : 0x00005000) || |
michael@0 | 83 | !out->WriteU16(maxp->num_glyphs)) { |
michael@0 | 84 | return OTS_FAILURE_MSG("Failed to write maxp version or number of glyphs"); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | if (!maxp->version_1) return true; |
michael@0 | 88 | |
michael@0 | 89 | if (!out->WriteU16(maxp->max_points) || |
michael@0 | 90 | !out->WriteU16(maxp->max_contours) || |
michael@0 | 91 | !out->WriteU16(maxp->max_c_points) || |
michael@0 | 92 | !out->WriteU16(maxp->max_c_contours)) { |
michael@0 | 93 | return OTS_FAILURE_MSG("Failed to write maxp"); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | if (g_transcode_hints) { |
michael@0 | 97 | if (!out->WriteU16(maxp->max_zones) || |
michael@0 | 98 | !out->WriteU16(maxp->max_t_points) || |
michael@0 | 99 | !out->WriteU16(maxp->max_storage) || |
michael@0 | 100 | !out->WriteU16(maxp->max_fdefs) || |
michael@0 | 101 | !out->WriteU16(maxp->max_idefs) || |
michael@0 | 102 | !out->WriteU16(maxp->max_stack) || |
michael@0 | 103 | !out->WriteU16(maxp->max_size_glyf_instructions)) { |
michael@0 | 104 | return OTS_FAILURE_MSG("Failed to write more maxp"); |
michael@0 | 105 | } |
michael@0 | 106 | } else { |
michael@0 | 107 | if (!out->WriteU16(1) || // max zones |
michael@0 | 108 | !out->WriteU16(0) || // max twilight points |
michael@0 | 109 | !out->WriteU16(0) || // max storage |
michael@0 | 110 | !out->WriteU16(0) || // max function defs |
michael@0 | 111 | !out->WriteU16(0) || // max instruction defs |
michael@0 | 112 | !out->WriteU16(0) || // max stack elements |
michael@0 | 113 | !out->WriteU16(0)) { // max instruction byte count |
michael@0 | 114 | return OTS_FAILURE_MSG("Failed to write more maxp"); |
michael@0 | 115 | } |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | if (!out->WriteU16(maxp->max_c_components) || |
michael@0 | 119 | !out->WriteU16(maxp->max_c_depth)) { |
michael@0 | 120 | return OTS_FAILURE_MSG("Failed to write yet more maxp"); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | return true; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | void ots_maxp_free(OpenTypeFile *file) { |
michael@0 | 127 | delete file->maxp; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | } // namespace ots |