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.
7 // maxp - Maximum Profile
8 // http://www.microsoft.com/typography/otspec/maxp.htm
10 #define TABLE_NAME "maxp"
14 bool ots_maxp_parse(Font
*font
, const uint8_t *data
, size_t length
) {
15 Buffer
table(data
, length
);
17 OpenTypeMAXP
*maxp
= new OpenTypeMAXP
;
21 if (!table
.ReadU32(&version
)) {
22 return OTS_FAILURE_MSG("Failed to read version of maxp table");
25 if (version
>> 16 > 1) {
26 return OTS_FAILURE_MSG("Bad maxp version %d", version
);
29 if (!table
.ReadU16(&maxp
->num_glyphs
)) {
30 return OTS_FAILURE_MSG("Failed to read number of glyphs from maxp table");
33 if (!maxp
->num_glyphs
) {
34 return OTS_FAILURE_MSG("Bad number of glyphs 0 in maxp table");
37 if (version
>> 16 == 1) {
38 maxp
->version_1
= true;
39 if (!table
.ReadU16(&maxp
->max_points
) ||
40 !table
.ReadU16(&maxp
->max_contours
) ||
41 !table
.ReadU16(&maxp
->max_c_points
) ||
42 !table
.ReadU16(&maxp
->max_c_contours
) ||
43 !table
.ReadU16(&maxp
->max_zones
) ||
44 !table
.ReadU16(&maxp
->max_t_points
) ||
45 !table
.ReadU16(&maxp
->max_storage
) ||
46 !table
.ReadU16(&maxp
->max_fdefs
) ||
47 !table
.ReadU16(&maxp
->max_idefs
) ||
48 !table
.ReadU16(&maxp
->max_stack
) ||
49 !table
.ReadU16(&maxp
->max_size_glyf_instructions
) ||
50 !table
.ReadU16(&maxp
->max_c_components
) ||
51 !table
.ReadU16(&maxp
->max_c_depth
)) {
52 return OTS_FAILURE_MSG("Failed to read maxp table");
55 if (maxp
->max_zones
== 0) {
56 // workaround for ipa*.ttf Japanese fonts.
57 OTS_WARNING("bad max_zones: %u", maxp
->max_zones
);
59 } else if (maxp
->max_zones
== 3) {
60 // workaround for Ecolier-*.ttf fonts.
61 OTS_WARNING("bad max_zones: %u", maxp
->max_zones
);
65 if ((maxp
->max_zones
!= 1) && (maxp
->max_zones
!= 2)) {
66 return OTS_FAILURE_MSG("Bad max zones %d in maxp", maxp
->max_zones
);
69 maxp
->version_1
= false;
75 bool ots_maxp_should_serialise(Font
*font
) {
76 return font
->maxp
!= NULL
;
79 bool ots_maxp_serialise(OTSStream
*out
, Font
*font
) {
80 const OpenTypeMAXP
*maxp
= font
->maxp
;
82 if (!out
->WriteU32(maxp
->version_1
? 0x00010000 : 0x00005000) ||
83 !out
->WriteU16(maxp
->num_glyphs
)) {
84 return OTS_FAILURE_MSG("Failed to write maxp version or number of glyphs");
87 if (!maxp
->version_1
) return true;
89 if (!out
->WriteU16(maxp
->max_points
) ||
90 !out
->WriteU16(maxp
->max_contours
) ||
91 !out
->WriteU16(maxp
->max_c_points
) ||
92 !out
->WriteU16(maxp
->max_c_contours
)) {
93 return OTS_FAILURE_MSG("Failed to write maxp");
96 if (!out
->WriteU16(maxp
->max_zones
) ||
97 !out
->WriteU16(maxp
->max_t_points
) ||
98 !out
->WriteU16(maxp
->max_storage
) ||
99 !out
->WriteU16(maxp
->max_fdefs
) ||
100 !out
->WriteU16(maxp
->max_idefs
) ||
101 !out
->WriteU16(maxp
->max_stack
) ||
102 !out
->WriteU16(maxp
->max_size_glyf_instructions
)) {
103 return OTS_FAILURE_MSG("Failed to write more maxp");
106 if (!out
->WriteU16(maxp
->max_c_components
) ||
107 !out
->WriteU16(maxp
->max_c_depth
)) {
108 return OTS_FAILURE_MSG("Failed to write yet more maxp");
114 void ots_maxp_reuse(Font
*font
, Font
*other
) {
115 font
->maxp
= other
->maxp
;
116 font
->maxp_reused
= true;
119 void ots_maxp_free(Font
*font
) {