OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <ctype.h> | 8 #include <ctype.h> |
9 | 9 |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 // A PFA has to be converted for PDF. | 228 // A PFA has to be converted for PDF. |
229 size_t hexDataLen; | 229 size_t hexDataLen; |
230 if (parsePFA((const char*)src, srcLen, headerLen, &hexDataLen, dataLen, | 230 if (parsePFA((const char*)src, srcLen, headerLen, &hexDataLen, dataLen, |
231 trailerLen)) { | 231 trailerLen)) { |
232 const size_t length = *headerLen + *dataLen + *trailerLen; | 232 const size_t length = *headerLen + *dataLen + *trailerLen; |
233 SkASSERT(length > 0); | 233 SkASSERT(length > 0); |
234 SkAutoTMalloc<uint8_t> buffer(length); | 234 SkAutoTMalloc<uint8_t> buffer(length); |
235 | 235 |
236 memcpy(buffer.get(), src, *headerLen); | 236 memcpy(buffer.get(), src, *headerLen); |
237 uint8_t* const resultData = &(buffer[*headerLen]); | 237 uint8_t* const resultData = &(buffer[SkToInt(*headerLen)]); |
238 | 238 |
239 const uint8_t* hexData = src + *headerLen; | 239 const uint8_t* hexData = src + *headerLen; |
240 const uint8_t* trailer = hexData + hexDataLen; | 240 const uint8_t* trailer = hexData + hexDataLen; |
241 size_t outputOffset = 0; | 241 size_t outputOffset = 0; |
242 uint8_t dataByte = 0; // To hush compiler. | 242 uint8_t dataByte = 0; // To hush compiler. |
243 bool highNibble = true; | 243 bool highNibble = true; |
244 for (; hexData < trailer; hexData++) { | 244 for (; hexData < trailer; hexData++) { |
245 int8_t curNibble = hexToBin(*hexData); | 245 int8_t curNibble = hexToBin(*hexData); |
246 if (curNibble < 0) { | 246 if (curNibble < 0) { |
247 continue; | 247 continue; |
248 } | 248 } |
249 if (highNibble) { | 249 if (highNibble) { |
250 dataByte = curNibble << 4; | 250 dataByte = curNibble << 4; |
251 highNibble = false; | 251 highNibble = false; |
252 } else { | 252 } else { |
253 dataByte |= curNibble; | 253 dataByte |= curNibble; |
254 highNibble = true; | 254 highNibble = true; |
255 resultData[outputOffset++] = dataByte; | 255 resultData[outputOffset++] = dataByte; |
256 } | 256 } |
257 } | 257 } |
258 if (!highNibble) { | 258 if (!highNibble) { |
259 resultData[outputOffset++] = dataByte; | 259 resultData[outputOffset++] = dataByte; |
260 } | 260 } |
261 SkASSERT(outputOffset == *dataLen); | 261 SkASSERT(outputOffset == *dataLen); |
262 | 262 |
263 uint8_t* const resultTrailer = &(buffer[*headerLen + outputOffset]); | 263 uint8_t* const resultTrailer = &(buffer[SkToInt(*headerLen + outputOffse
t)]); |
264 memcpy(resultTrailer, src + *headerLen + hexDataLen, *trailerLen); | 264 memcpy(resultTrailer, src + *headerLen + hexDataLen, *trailerLen); |
265 | 265 |
266 return SkData::NewFromMalloc(buffer.detach(), length); | 266 return SkData::NewFromMalloc(buffer.detach(), length); |
267 } | 267 } |
268 return NULL; | 268 return NULL; |
269 } | 269 } |
270 | 270 |
271 // scale from em-units to base-1000, returning as a SkScalar | 271 // scale from em-units to base-1000, returning as a SkScalar |
272 SkScalar scaleFromFontUnits(int16_t val, uint16_t emSize) { | 272 SkScalar scaleFromFontUnits(int16_t val, uint16_t emSize) { |
273 SkScalar scaled = SkIntToScalar(val); | 273 SkScalar scaled = SkIntToScalar(val); |
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 | 1489 |
1490 insert("FontBBox", makeFontBBox(bbox, 1000))->unref(); | 1490 insert("FontBBox", makeFontBBox(bbox, 1000))->unref(); |
1491 insertInt("FirstChar", 1); | 1491 insertInt("FirstChar", 1); |
1492 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); | 1492 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); |
1493 insert("Widths", widthArray.get()); | 1493 insert("Widths", widthArray.get()); |
1494 insertName("CIDToGIDMap", "Identity"); | 1494 insertName("CIDToGIDMap", "Identity"); |
1495 | 1495 |
1496 populateToUnicodeTable(NULL); | 1496 populateToUnicodeTable(NULL); |
1497 return true; | 1497 return true; |
1498 } | 1498 } |
OLD | NEW |