Chromium Code Reviews

Side by Side Diff: src/maxp.cc

Issue 658573004: Updating to new OTS repo from https://github.com/khaledhosny/ots.git (Closed) Base URL: https://chromium.googlesource.com/external/ots@master
Patch Set: Adding Colored Emoji changes from external/git repo Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« .gitmodules ('K') | « src/math.cc ('k') | src/metrics.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "maxp.h" 5 #include "maxp.h"
6 6
7 // maxp - Maximum Profile 7 // maxp - Maximum Profile
8 // http://www.microsoft.com/opentype/otspec/maxp.htm 8 // http://www.microsoft.com/typography/otspec/maxp.htm
9
10 #define TABLE_NAME "maxp"
9 11
10 namespace ots { 12 namespace ots {
11 13
12 bool ots_maxp_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { 14 bool ots_maxp_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
13 Buffer table(data, length); 15 Buffer table(data, length);
14 16
15 OpenTypeMAXP *maxp = new OpenTypeMAXP; 17 OpenTypeMAXP *maxp = new OpenTypeMAXP;
16 file->maxp = maxp; 18 file->maxp = maxp;
17 19
18 uint32_t version = 0; 20 uint32_t version = 0;
19 if (!table.ReadU32(&version)) { 21 if (!table.ReadU32(&version)) {
20 return OTS_FAILURE(); 22 return OTS_FAILURE_MSG("Failed to read version of maxp table");
21 } 23 }
22 24
23 if (version >> 16 > 1) { 25 if (version >> 16 > 1) {
24 return OTS_FAILURE(); 26 return OTS_FAILURE_MSG("Bad maxp version %d", version);
25 } 27 }
26 28
27 if (!table.ReadU16(&maxp->num_glyphs)) { 29 if (!table.ReadU16(&maxp->num_glyphs)) {
28 return OTS_FAILURE(); 30 return OTS_FAILURE_MSG("Failed to read number of glyphs from maxp table");
29 } 31 }
30 32
31 if (!maxp->num_glyphs) { 33 if (!maxp->num_glyphs) {
32 return OTS_FAILURE(); 34 return OTS_FAILURE_MSG("Bad number of glyphs 0 in maxp table");
33 } 35 }
34 36
35 if (version >> 16 == 1) { 37 if (version >> 16 == 1) {
36 maxp->version_1 = true; 38 maxp->version_1 = true;
37 if (!table.ReadU16(&maxp->max_points) || 39 if (!table.ReadU16(&maxp->max_points) ||
38 !table.ReadU16(&maxp->max_contours) || 40 !table.ReadU16(&maxp->max_contours) ||
39 !table.ReadU16(&maxp->max_c_points) || 41 !table.ReadU16(&maxp->max_c_points) ||
40 !table.ReadU16(&maxp->max_c_contours) || 42 !table.ReadU16(&maxp->max_c_contours) ||
41 !table.ReadU16(&maxp->max_zones) || 43 !table.ReadU16(&maxp->max_zones) ||
42 !table.ReadU16(&maxp->max_t_points) || 44 !table.ReadU16(&maxp->max_t_points) ||
43 !table.ReadU16(&maxp->max_storage) || 45 !table.ReadU16(&maxp->max_storage) ||
44 !table.ReadU16(&maxp->max_fdefs) || 46 !table.ReadU16(&maxp->max_fdefs) ||
45 !table.ReadU16(&maxp->max_idefs) || 47 !table.ReadU16(&maxp->max_idefs) ||
46 !table.ReadU16(&maxp->max_stack) || 48 !table.ReadU16(&maxp->max_stack) ||
47 !table.ReadU16(&maxp->max_size_glyf_instructions) || 49 !table.ReadU16(&maxp->max_size_glyf_instructions) ||
48 !table.ReadU16(&maxp->max_c_components) || 50 !table.ReadU16(&maxp->max_c_components) ||
49 !table.ReadU16(&maxp->max_c_depth)) { 51 !table.ReadU16(&maxp->max_c_depth)) {
50 return OTS_FAILURE(); 52 return OTS_FAILURE_MSG("Failed to read maxp table");
51 } 53 }
52 54
53 if (maxp->max_zones == 0) { 55 if (maxp->max_zones == 0) {
54 // workaround for ipa*.ttf Japanese fonts. 56 // workaround for ipa*.ttf Japanese fonts.
55 OTS_WARNING("bad max_zones: %u", maxp->max_zones); 57 OTS_WARNING("bad max_zones: %u", maxp->max_zones);
56 maxp->max_zones = 1; 58 maxp->max_zones = 1;
57 } else if (maxp->max_zones == 3) { 59 } else if (maxp->max_zones == 3) {
58 // workaround for Ecolier-*.ttf fonts. 60 // workaround for Ecolier-*.ttf fonts.
59 OTS_WARNING("bad max_zones: %u", maxp->max_zones); 61 OTS_WARNING("bad max_zones: %u", maxp->max_zones);
60 maxp->max_zones = 2; 62 maxp->max_zones = 2;
61 } 63 }
62 64
63 if ((maxp->max_zones != 1) && (maxp->max_zones != 2)) { 65 if ((maxp->max_zones != 1) && (maxp->max_zones != 2)) {
64 return OTS_FAILURE(); 66 return OTS_FAILURE_MSG("Bad max zones %d in maxp", maxp->max_zones);
65 } 67 }
66 } else { 68 } else {
67 maxp->version_1 = false; 69 maxp->version_1 = false;
68 } 70 }
69 71
70 return true; 72 return true;
71 } 73 }
72 74
73 bool ots_maxp_should_serialise(OpenTypeFile *file) { 75 bool ots_maxp_should_serialise(OpenTypeFile *file) {
74 return file->maxp != NULL; 76 return file->maxp != NULL;
75 } 77 }
76 78
77 bool ots_maxp_serialise(OTSStream *out, OpenTypeFile *file) { 79 bool ots_maxp_serialise(OTSStream *out, OpenTypeFile *file) {
78 const OpenTypeMAXP *maxp = file->maxp; 80 const OpenTypeMAXP *maxp = file->maxp;
79 81
80 if (!out->WriteU32(maxp->version_1 ? 0x00010000 : 0x00005000) || 82 if (!out->WriteU32(maxp->version_1 ? 0x00010000 : 0x00005000) ||
81 !out->WriteU16(maxp->num_glyphs)) { 83 !out->WriteU16(maxp->num_glyphs)) {
82 return OTS_FAILURE(); 84 return OTS_FAILURE_MSG("Failed to write maxp version or number of glyphs");
83 } 85 }
84 86
85 if (!maxp->version_1) return true; 87 if (!maxp->version_1) return true;
86 88
87 if (!out->WriteU16(maxp->max_points) || 89 if (!out->WriteU16(maxp->max_points) ||
88 !out->WriteU16(maxp->max_contours) || 90 !out->WriteU16(maxp->max_contours) ||
89 !out->WriteU16(maxp->max_c_points) || 91 !out->WriteU16(maxp->max_c_points) ||
90 !out->WriteU16(maxp->max_c_contours)) { 92 !out->WriteU16(maxp->max_c_contours)) {
91 return OTS_FAILURE(); 93 return OTS_FAILURE_MSG("Failed to write maxp");
92 } 94 }
93 95
94 if (g_transcode_hints) { 96 if (!out->WriteU16(maxp->max_zones) ||
95 if (!out->WriteU16(maxp->max_zones) || 97 !out->WriteU16(maxp->max_t_points) ||
96 !out->WriteU16(maxp->max_t_points) || 98 !out->WriteU16(maxp->max_storage) ||
97 !out->WriteU16(maxp->max_storage) || 99 !out->WriteU16(maxp->max_fdefs) ||
98 !out->WriteU16(maxp->max_fdefs) || 100 !out->WriteU16(maxp->max_idefs) ||
99 !out->WriteU16(maxp->max_idefs) || 101 !out->WriteU16(maxp->max_stack) ||
100 !out->WriteU16(maxp->max_stack) || 102 !out->WriteU16(maxp->max_size_glyf_instructions)) {
101 !out->WriteU16(maxp->max_size_glyf_instructions)) { 103 return OTS_FAILURE_MSG("Failed to write more maxp");
102 return OTS_FAILURE();
103 }
104 } else {
105 if (!out->WriteU16(1) || // max zones
106 !out->WriteU16(0) || // max twilight points
107 !out->WriteU16(0) || // max storage
108 !out->WriteU16(0) || // max function defs
109 !out->WriteU16(0) || // max instruction defs
110 !out->WriteU16(0) || // max stack elements
111 !out->WriteU16(0)) { // max instruction byte count
112 return OTS_FAILURE();
113 }
114 } 104 }
115 105
116 if (!out->WriteU16(maxp->max_c_components) || 106 if (!out->WriteU16(maxp->max_c_components) ||
117 !out->WriteU16(maxp->max_c_depth)) { 107 !out->WriteU16(maxp->max_c_depth)) {
118 return OTS_FAILURE(); 108 return OTS_FAILURE_MSG("Failed to write yet more maxp");
119 } 109 }
120 110
121 return true; 111 return true;
122 } 112 }
123 113
124 void ots_maxp_free(OpenTypeFile *file) { 114 void ots_maxp_free(OpenTypeFile *file) {
125 delete file->maxp; 115 delete file->maxp;
126 } 116 }
127 117
128 } // namespace ots 118 } // namespace ots
119
120 #undef TABLE_NAME
OLDNEW
« .gitmodules ('K') | « src/math.cc ('k') | src/metrics.h » ('j') | no next file with comments »

Powered by Google App Engine