| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // this handles releasing the data we may have gotten from dynamicStream. | 197 // this handles releasing the data we may have gotten from dynamicStream. |
| 198 // if data is null, it is a no-op | 198 // if data is null, it is a no-op |
| 199 SkAutoDataUnref aud(data); | 199 SkAutoDataUnref aud(data); |
| 200 | 200 |
| 201 if (parsePFB(src, srcLen, headerLen, dataLen, trailerLen)) { | 201 if (parsePFB(src, srcLen, headerLen, dataLen, trailerLen)) { |
| 202 static const int kPFBSectionHeaderLength = 6; | 202 static const int kPFBSectionHeaderLength = 6; |
| 203 const size_t length = *headerLen + *dataLen + *trailerLen; | 203 const size_t length = *headerLen + *dataLen + *trailerLen; |
| 204 SkASSERT(length > 0); | 204 SkASSERT(length > 0); |
| 205 SkASSERT(length + (2 * kPFBSectionHeaderLength) <= srcLen); | 205 SkASSERT(length + (2 * kPFBSectionHeaderLength) <= srcLen); |
| 206 | 206 |
| 207 SkAutoTMalloc<uint8_t> buffer(length); | 207 SkData* data = SkData::NewUninitialized(length); |
| 208 | 208 |
| 209 const uint8_t* const srcHeader = src + kPFBSectionHeaderLength; | 209 const uint8_t* const srcHeader = src + kPFBSectionHeaderLength; |
| 210 // There is a six-byte section header before header and data | 210 // There is a six-byte section header before header and data |
| 211 // (but not trailer) that we're not going to copy. | 211 // (but not trailer) that we're not going to copy. |
| 212 const uint8_t* const srcData | 212 const uint8_t* const srcData = srcHeader + *headerLen + kPFBSectionHeade
rLength; |
| 213 = srcHeader + *headerLen + kPFBSectionHeaderLength; | |
| 214 const uint8_t* const srcTrailer = srcData + *headerLen; | 213 const uint8_t* const srcTrailer = srcData + *headerLen; |
| 215 | 214 |
| 216 uint8_t* const resultHeader = buffer.get(); | 215 uint8_t* const resultHeader = (uint8_t*)data->writable_data(); |
| 217 uint8_t* const resultData = resultHeader + *headerLen; | 216 uint8_t* const resultData = resultHeader + *headerLen; |
| 218 uint8_t* const resultTrailer = resultData + *dataLen; | 217 uint8_t* const resultTrailer = resultData + *dataLen; |
| 219 | 218 |
| 220 SkASSERT(resultTrailer + *trailerLen == resultHeader + length); | 219 SkASSERT(resultTrailer + *trailerLen == resultHeader + length); |
| 221 | 220 |
| 222 memcpy(resultHeader, srcHeader, *headerLen); | 221 memcpy(resultHeader, srcHeader, *headerLen); |
| 223 memcpy(resultData, srcData, *dataLen); | 222 memcpy(resultData, srcData, *dataLen); |
| 224 memcpy(resultTrailer, srcTrailer, *trailerLen); | 223 memcpy(resultTrailer, srcTrailer, *trailerLen); |
| 225 | 224 |
| 226 return SkData::NewFromMalloc(buffer.detach(), length); | 225 return data; |
| 227 } | 226 } |
| 228 | 227 |
| 229 // A PFA has to be converted for PDF. | 228 // A PFA has to be converted for PDF. |
| 230 size_t hexDataLen; | 229 size_t hexDataLen; |
| 231 if (parsePFA((const char*)src, srcLen, headerLen, &hexDataLen, dataLen, | 230 if (parsePFA((const char*)src, srcLen, headerLen, &hexDataLen, dataLen, |
| 232 trailerLen)) { | 231 trailerLen)) { |
| 233 const size_t length = *headerLen + *dataLen + *trailerLen; | 232 const size_t length = *headerLen + *dataLen + *trailerLen; |
| 234 SkASSERT(length > 0); | 233 SkASSERT(length > 0); |
| 235 SkAutoTMalloc<uint8_t> buffer(length); | 234 SkAutoTMalloc<uint8_t> buffer(length); |
| 236 | 235 |
| (...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 | 1489 |
| 1491 insert("FontBBox", makeFontBBox(bbox, 1000))->unref(); | 1490 insert("FontBBox", makeFontBBox(bbox, 1000))->unref(); |
| 1492 insertInt("FirstChar", 1); | 1491 insertInt("FirstChar", 1); |
| 1493 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); | 1492 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); |
| 1494 insert("Widths", widthArray.get()); | 1493 insert("Widths", widthArray.get()); |
| 1495 insertName("CIDToGIDMap", "Identity"); | 1494 insertName("CIDToGIDMap", "Identity"); |
| 1496 | 1495 |
| 1497 populateToUnicodeTable(NULL); | 1496 populateToUnicodeTable(NULL); |
| 1498 return true; | 1497 return true; |
| 1499 } | 1498 } |
| OLD | NEW |