| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkPdfNativeDoc.h" | 8 #include "SkPdfNativeDoc.h" |
| 9 | 9 |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 if (strcmp((char*)xrefstartKeywordLine, "startxref") != 0) { | 120 if (strcmp((char*)xrefstartKeywordLine, "startxref") != 0) { |
| 121 SkPdfReport(kWarning_SkPdfIssueSeverity, kMissingToken_SkPdfIssue, | 121 SkPdfReport(kWarning_SkPdfIssueSeverity, kMissingToken_SkPdfIssue, |
| 122 "Could not find startxref", NULL, NULL); | 122 "Could not find startxref", NULL, NULL); |
| 123 } | 123 } |
| 124 | 124 |
| 125 long xrefByteOffset = atol((const char*)xrefByteOffsetLine); | 125 long xrefByteOffset = atol((const char*)xrefByteOffsetLine); |
| 126 | 126 |
| 127 bool storeCatalog = true; | 127 bool storeCatalog = true; |
| 128 while (xrefByteOffset >= 0) { | 128 while (xrefByteOffset >= 0) { |
| 129 const unsigned char* trailerStart = readCrossReferenceSection(fFileConte
nt + xrefByteOffset, | 129 const unsigned char* trailerStart = this->readCrossReferenceSection(fFil
eContent + xrefByteOffset, |
| 130 xrefstartK
eywordLine); | 130 xref
startKeywordLine); |
| 131 xrefByteOffset = -1; | 131 xrefByteOffset = -1; |
| 132 if (trailerStart < xrefstartKeywordLine) { | 132 if (trailerStart < xrefstartKeywordLine) { |
| 133 readTrailer(trailerStart, xrefstartKeywordLine, storeCatalog, &xrefB
yteOffset, false); | 133 this->readTrailer(trailerStart, xrefstartKeywordLine, storeCatalog,
&xrefByteOffset, false); |
| 134 storeCatalog = false; | 134 storeCatalog = false; |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 // TODO(edisonn): warn/error expect fObjects[fRefCatalogId].fGeneration == f
RefCatalogGeneration | 138 // TODO(edisonn): warn/error expect fObjects[fRefCatalogId].fGeneration == f
RefCatalogGeneration |
| 139 // TODO(edisonn): security, verify that SkPdfCatalogDictionary is indeed usi
ng mapper | 139 // TODO(edisonn): security, verify that SkPdfCatalogDictionary is indeed usi
ng mapper |
| 140 | 140 |
| 141 if (fRootCatalogRef) { | 141 if (fRootCatalogRef) { |
| 142 fRootCatalog = (SkPdfCatalogDictionary*)resolveReference(fRootCatalogRef
); | 142 fRootCatalog = (SkPdfCatalogDictionary*)resolveReference(fRootCatalogRef
); |
| 143 if (fRootCatalog != NULL && fRootCatalog->isDictionary() && fRootCatalog
->valid()) { | 143 if (fRootCatalog != NULL && fRootCatalog->isDictionary() && fRootCatalog
->valid()) { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 token.reset(); | 296 token.reset(); |
| 297 current = nextObject(current, trailerEnd, &token, NULL, NULL); | 297 current = nextObject(current, trailerEnd, &token, NULL, NULL); |
| 298 if (!token.isKeyword() || token.lenstr() != 1 || | 298 if (!token.isKeyword() || token.lenstr() != 1 || |
| 299 (*token.c_str() != 'f' && *token.c_str() != 'n')) { | 299 (*token.c_str() != 'f' && *token.c_str() != 'n')) { |
| 300 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, | 300 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, |
| 301 "readCrossReferenceSection: f or n exp
ected", | 301 "readCrossReferenceSection: f or n exp
ected", |
| 302 &token, SkPdfNativeObject::kKeyword_Pd
fObjectType, NULL); | 302 &token, SkPdfNativeObject::kKeyword_Pd
fObjectType, NULL); |
| 303 return current; | 303 return current; |
| 304 } | 304 } |
| 305 | 305 |
| 306 addCrossSectionInfo(startId + i, generation, offset, *token.c_str()
== 'f'); | 306 this->addCrossSectionInfo(startId + i, generation, offset, *token.c_
str() == 'f'); |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 SkPdfReport(kInfo_SkPdfIssueSeverity, kNoIssue_SkPdfIssue, | 309 SkPdfReport(kInfo_SkPdfIssueSeverity, kNoIssue_SkPdfIssue, |
| 310 "Unexpected end of readCrossReferenceSection", NULL, NULL); | 310 "Unexpected end of readCrossReferenceSection", NULL, NULL); |
| 311 return current; | 311 return current; |
| 312 } | 312 } |
| 313 | 313 |
| 314 const unsigned char* SkPdfNativeDoc::readTrailer(const unsigned char* trailerSta
rt, | 314 const unsigned char* SkPdfNativeDoc::readTrailer(const unsigned char* trailerSta
rt, |
| 315 const unsigned char* trailerEnd
, | 315 const unsigned char* trailerEnd
, |
| 316 bool storeCatalog, long* prev,
bool skipKeyword) { | 316 bool storeCatalog, long* prev,
bool skipKeyword) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 if (trailer->has_Prev()) { | 356 if (trailer->has_Prev()) { |
| 357 *prev = (long)trailer->Prev(NULL); | 357 *prev = (long)trailer->Prev(NULL); |
| 358 } | 358 } |
| 359 | 359 |
| 360 return current; | 360 return current; |
| 361 } | 361 } |
| 362 | 362 |
| 363 void SkPdfNativeDoc::addCrossSectionInfo(int id, int generation, int offset, boo
l isFreed) { | 363 void SkPdfNativeDoc::addCrossSectionInfo(int id, int generation, int offset, boo
l isFreed) { |
| 364 // TODO(edisonn): security here, verify id | 364 // TODO(edisonn): security here, verify id |
| 365 while (fObjects.count() < id + 1) { | 365 while (fObjects.count() < id + 1) { |
| 366 reset(fObjects.append()); | 366 this->reset(fObjects.append()); |
| 367 } | 367 } |
| 368 | 368 |
| 369 fObjects[id].fOffset = offset; | 369 fObjects[id].fOffset = offset; |
| 370 fObjects[id].fObj = NULL; | 370 fObjects[id].fObj = NULL; |
| 371 fObjects[id].fResolvedReference = NULL; | 371 fObjects[id].fResolvedReference = NULL; |
| 372 fObjects[id].fIsReferenceResolved = false; | 372 fObjects[id].fIsReferenceResolved = false; |
| 373 } | 373 } |
| 374 | 374 |
| 375 SkPdfNativeObject* SkPdfNativeDoc::readObject(int id/*, int expectedGeneration*/
) { | 375 SkPdfNativeObject* SkPdfNativeDoc::readObject(int id/*, int expectedGeneration*/
) { |
| 376 long startOffset = fObjects[id].fOffset; | 376 long startOffset = fObjects[id].fOffset; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 return (SkPdfNativeObject*)ref; | 597 return (SkPdfNativeObject*)ref; |
| 598 } | 598 } |
| 599 | 599 |
| 600 size_t SkPdfNativeDoc::bytesUsed() const { | 600 size_t SkPdfNativeDoc::bytesUsed() const { |
| 601 return fAllocator->bytesUsed() + | 601 return fAllocator->bytesUsed() + |
| 602 fContentLength + | 602 fContentLength + |
| 603 fObjects.count() * sizeof(PublicObjectEntry) + | 603 fObjects.count() * sizeof(PublicObjectEntry) + |
| 604 fPages.count() * sizeof(SkPdfPageObjectDictionary*) + | 604 fPages.count() * sizeof(SkPdfPageObjectDictionary*) + |
| 605 sizeof(*this); | 605 sizeof(*this); |
| 606 } | 606 } |
| OLD | NEW |