OLD | NEW |
1 // Copyright 2013 Google Inc. All Rights Reserved. | 1 // Copyright 2013 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 if (!buffer.Skip(glyph->instructions_size)) { | 115 if (!buffer.Skip(glyph->instructions_size)) { |
116 return FONT_COMPRESSION_FAILURE(); | 116 return FONT_COMPRESSION_FAILURE(); |
117 } | 117 } |
118 | 118 |
119 // Read the run-length coded flags. | 119 // Read the run-length coded flags. |
120 std::vector<std::vector<uint8_t> > flags(num_contours); | 120 std::vector<std::vector<uint8_t> > flags(num_contours); |
121 uint8_t flag = 0; | 121 uint8_t flag = 0; |
122 uint8_t flag_repeat = 0; | 122 uint8_t flag_repeat = 0; |
123 for (int i = 0; i < num_contours; ++i) { | 123 for (int i = 0; i < num_contours; ++i) { |
124 flags[i].resize(glyph->contours[i].size()); | 124 flags[i].resize(glyph->contours[i].size()); |
125 for (int j = 0; j < glyph->contours[i].size(); ++j) { | 125 for (size_t j = 0; j < glyph->contours[i].size(); ++j) { |
126 if (flag_repeat == 0) { | 126 if (flag_repeat == 0) { |
127 if (!buffer.ReadU8(&flag)) { | 127 if (!buffer.ReadU8(&flag)) { |
128 return FONT_COMPRESSION_FAILURE(); | 128 return FONT_COMPRESSION_FAILURE(); |
129 } | 129 } |
130 if (flag & kFLAG_REPEAT) { | 130 if (flag & kFLAG_REPEAT) { |
131 if (!buffer.ReadU8(&flag_repeat)) { | 131 if (!buffer.ReadU8(&flag_repeat)) { |
132 return FONT_COMPRESSION_FAILURE(); | 132 return FONT_COMPRESSION_FAILURE(); |
133 } | 133 } |
134 } | 134 } |
135 } else { | 135 } else { |
136 flag_repeat--; | 136 flag_repeat--; |
137 } | 137 } |
138 flags[i][j] = flag; | 138 flags[i][j] = flag; |
139 glyph->contours[i][j].on_curve = flag & kFLAG_ONCURVE; | 139 glyph->contours[i][j].on_curve = flag & kFLAG_ONCURVE; |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 // Read the x coordinates. | 143 // Read the x coordinates. |
144 int prev_x = 0; | 144 int prev_x = 0; |
145 for (int i = 0; i < num_contours; ++i) { | 145 for (int i = 0; i < num_contours; ++i) { |
146 for (int j = 0; j < glyph->contours[i].size(); ++j) { | 146 for (size_t j = 0; j < glyph->contours[i].size(); ++j) { |
147 uint8_t flag = flags[i][j]; | 147 uint8_t flag = flags[i][j]; |
148 if (flag & kFLAG_XSHORT) { | 148 if (flag & kFLAG_XSHORT) { |
149 // single byte x-delta coord value | 149 // single byte x-delta coord value |
150 uint8_t x_delta; | 150 uint8_t x_delta; |
151 if (!buffer.ReadU8(&x_delta)) { | 151 if (!buffer.ReadU8(&x_delta)) { |
152 return FONT_COMPRESSION_FAILURE(); | 152 return FONT_COMPRESSION_FAILURE(); |
153 } | 153 } |
154 int sign = (flag & kFLAG_XREPEATSIGN) ? 1 : -1; | 154 int sign = (flag & kFLAG_XREPEATSIGN) ? 1 : -1; |
155 glyph->contours[i][j].x = prev_x + sign * x_delta; | 155 glyph->contours[i][j].x = prev_x + sign * x_delta; |
156 } else { | 156 } else { |
157 // double byte x-delta coord value | 157 // double byte x-delta coord value |
158 int16_t x_delta = 0; | 158 int16_t x_delta = 0; |
159 if (!(flag & kFLAG_XREPEATSIGN)) { | 159 if (!(flag & kFLAG_XREPEATSIGN)) { |
160 if (!buffer.ReadS16(&x_delta)) { | 160 if (!buffer.ReadS16(&x_delta)) { |
161 return FONT_COMPRESSION_FAILURE(); | 161 return FONT_COMPRESSION_FAILURE(); |
162 } | 162 } |
163 } | 163 } |
164 glyph->contours[i][j].x = prev_x + x_delta; | 164 glyph->contours[i][j].x = prev_x + x_delta; |
165 } | 165 } |
166 prev_x = glyph->contours[i][j].x; | 166 prev_x = glyph->contours[i][j].x; |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 // Read the y coordinates. | 170 // Read the y coordinates. |
171 int prev_y = 0; | 171 int prev_y = 0; |
172 for (int i = 0; i < num_contours; ++i) { | 172 for (int i = 0; i < num_contours; ++i) { |
173 for (int j = 0; j < glyph->contours[i].size(); ++j) { | 173 for (size_t j = 0; j < glyph->contours[i].size(); ++j) { |
174 uint8_t flag = flags[i][j]; | 174 uint8_t flag = flags[i][j]; |
175 if (flag & kFLAG_YSHORT) { | 175 if (flag & kFLAG_YSHORT) { |
176 // single byte y-delta coord value | 176 // single byte y-delta coord value |
177 uint8_t y_delta; | 177 uint8_t y_delta; |
178 if (!buffer.ReadU8(&y_delta)) { | 178 if (!buffer.ReadU8(&y_delta)) { |
179 return FONT_COMPRESSION_FAILURE(); | 179 return FONT_COMPRESSION_FAILURE(); |
180 } | 180 } |
181 int sign = (flag & kFLAG_YREPEATSIGN) ? 1 : -1; | 181 int sign = (flag & kFLAG_YREPEATSIGN) ? 1 : -1; |
182 glyph->contours[i][j].y = prev_y + sign * y_delta; | 182 glyph->contours[i][j].y = prev_y + sign * y_delta; |
183 } else { | 183 } else { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 StoreInstructions(glyph, &offset, dst); | 371 StoreInstructions(glyph, &offset, dst); |
372 if (!StorePoints(glyph, &offset, dst, *dst_size)) { | 372 if (!StorePoints(glyph, &offset, dst, *dst_size)) { |
373 return FONT_COMPRESSION_FAILURE(); | 373 return FONT_COMPRESSION_FAILURE(); |
374 } | 374 } |
375 } | 375 } |
376 *dst_size = offset; | 376 *dst_size = offset; |
377 return true; | 377 return true; |
378 } | 378 } |
379 | 379 |
380 } // namespace woff2 | 380 } // namespace woff2 |
OLD | NEW |