| OLD | NEW |
| 1 #include "SkNativeParsedPDF.h" | 1 #include "SkNativeParsedPDF.h" |
| 2 #include "SkPdfNativeTokenizer.h" | 2 #include "SkPdfNativeTokenizer.h" |
| 3 #include "SkPdfBasics.h" | 3 #include "SkPdfBasics.h" |
| 4 #include "SkPdfObject.h" | 4 #include "SkPdfObject.h" |
| 5 | 5 |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 | 10 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 current = nextObject(0, current, trailerEnd, &token, fAllocator, NULL); | 299 current = nextObject(0, current, trailerEnd, &token, fAllocator, NULL); |
| 300 if (!token.isDictionary()) { | 300 if (!token.isDictionary()) { |
| 301 return current; | 301 return current; |
| 302 } | 302 } |
| 303 SkPdfFileTrailerDictionary* trailer = (SkPdfFileTrailerDictionary*)&token; | 303 SkPdfFileTrailerDictionary* trailer = (SkPdfFileTrailerDictionary*)&token; |
| 304 if (!trailer->valid()) { | 304 if (!trailer->valid()) { |
| 305 return current; | 305 return current; |
| 306 } | 306 } |
| 307 | 307 |
| 308 if (storeCatalog) { | 308 if (storeCatalog) { |
| 309 const SkPdfObject* ref = trailer->Root(NULL); | 309 SkPdfObject* ref = trailer->Root(NULL); |
| 310 if (ref == NULL || !ref->isReference()) { | 310 if (ref == NULL || !ref->isReference()) { |
| 311 // TODO(edisonn): oops, we have to fix the corrup pdf file | 311 // TODO(edisonn): oops, we have to fix the corrup pdf file |
| 312 return current; | 312 return current; |
| 313 } | 313 } |
| 314 fRootCatalogRef = ref; | 314 fRootCatalogRef = ref; |
| 315 } | 315 } |
| 316 | 316 |
| 317 if (trailer->has_Prev()) { | 317 if (trailer->has_Prev()) { |
| 318 *prev = (long)trailer->Prev(NULL); | 318 *prev = (long)trailer->Prev(NULL); |
| 319 } | 319 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 377 } |
| 378 | 378 |
| 379 current = nextObject(1, current, end, dict, fAllocator, this); | 379 current = nextObject(1, current, end, dict, fAllocator, this); |
| 380 | 380 |
| 381 // TODO(edisonn): report warning/error - verify last token is endobj | 381 // TODO(edisonn): report warning/error - verify last token is endobj |
| 382 | 382 |
| 383 return dict; | 383 return dict; |
| 384 } | 384 } |
| 385 | 385 |
| 386 void SkNativeParsedPDF::fillPages(SkPdfPageTreeNodeDictionary* tree) { | 386 void SkNativeParsedPDF::fillPages(SkPdfPageTreeNodeDictionary* tree) { |
| 387 const SkPdfArray* kids = tree->Kids(this); | 387 SkPdfArray* kids = tree->Kids(this); |
| 388 if (kids == NULL) { | 388 if (kids == NULL) { |
| 389 *fPages.append() = (SkPdfPageObjectDictionary*)tree; | 389 *fPages.append() = (SkPdfPageObjectDictionary*)tree; |
| 390 return; | 390 return; |
| 391 } | 391 } |
| 392 | 392 |
| 393 int cnt = kids->size(); | 393 int cnt = kids->size(); |
| 394 for (int i = 0; i < cnt; i++) { | 394 for (int i = 0; i < cnt; i++) { |
| 395 const SkPdfObject* obj = resolveReference(kids->objAtAIndex(i)); | 395 SkPdfObject* obj = resolveReference(kids->objAtAIndex(i)); |
| 396 if (fMapper->mapPageObjectDictionary(obj) != kPageObjectDictionary_SkPdf
ObjectType) { | 396 if (fMapper->mapPageObjectDictionary(obj) != kPageObjectDictionary_SkPdf
ObjectType) { |
| 397 *fPages.append() = (SkPdfPageObjectDictionary*)obj; | 397 *fPages.append() = (SkPdfPageObjectDictionary*)obj; |
| 398 } else { | 398 } else { |
| 399 // TODO(edisonn): verify that it is a page tree indeed | 399 // TODO(edisonn): verify that it is a page tree indeed |
| 400 fillPages((SkPdfPageTreeNodeDictionary*)obj); | 400 fillPages((SkPdfPageTreeNodeDictionary*)obj); |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 | 404 |
| 405 int SkNativeParsedPDF::pages() const { | 405 int SkNativeParsedPDF::pages() const { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 SkPdfObject::makeString(sz, len, obj); | 499 SkPdfObject::makeString(sz, len, obj); |
| 500 return (SkPdfString*)obj; | 500 return (SkPdfString*)obj; |
| 501 } | 501 } |
| 502 | 502 |
| 503 SkPdfAllocator* SkNativeParsedPDF::allocator() const { | 503 SkPdfAllocator* SkNativeParsedPDF::allocator() const { |
| 504 return fAllocator; | 504 return fAllocator; |
| 505 } | 505 } |
| 506 | 506 |
| 507 // TODO(edisonn): fix infinite loop if ref to itself! | 507 // TODO(edisonn): fix infinite loop if ref to itself! |
| 508 // TODO(edisonn): perf, fix refs at load, and resolve will simply return fResolv
edReference? | 508 // TODO(edisonn): perf, fix refs at load, and resolve will simply return fResolv
edReference? |
| 509 SkPdfObject* SkNativeParsedPDF::resolveReference(const SkPdfObject* ref) { | 509 SkPdfObject* SkNativeParsedPDF::resolveReference(SkPdfObject* ref) { |
| 510 if (ref && ref->isReference()) { | 510 if (ref && ref->isReference()) { |
| 511 int id = ref->referenceId(); | 511 int id = ref->referenceId(); |
| 512 // TODO(edisonn): generation/updates not supported now | 512 // TODO(edisonn): generation/updates not supported now |
| 513 //int gen = ref->referenceGeneration(); | 513 //int gen = ref->referenceGeneration(); |
| 514 | 514 |
| 515 // TODO(edisonn): verify id and gen expected | 515 // TODO(edisonn): verify id and gen expected |
| 516 if (id < 0 || id >= fObjects.count()) { | 516 if (id < 0 || id >= fObjects.count()) { |
| 517 // TODO(edisonn): report error/warning | 517 // TODO(edisonn): report error/warning |
| 518 return NULL; | 518 return NULL; |
| 519 } | 519 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 return (SkPdfObject*)ref; | 551 return (SkPdfObject*)ref; |
| 552 } | 552 } |
| 553 | 553 |
| 554 size_t SkNativeParsedPDF::bytesUsed() const { | 554 size_t SkNativeParsedPDF::bytesUsed() const { |
| 555 return fAllocator->bytesUsed() + | 555 return fAllocator->bytesUsed() + |
| 556 fContentLength + | 556 fContentLength + |
| 557 fObjects.count() * sizeof(PublicObjectEntry) + | 557 fObjects.count() * sizeof(PublicObjectEntry) + |
| 558 fPages.count() * sizeof(SkPdfPageObjectDictionary*) + | 558 fPages.count() * sizeof(SkPdfPageObjectDictionary*) + |
| 559 sizeof(*this); | 559 sizeof(*this); |
| 560 } | 560 } |
| OLD | NEW |