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 "SkDeflate.h" | 8 #include "SkDeflate.h" |
9 #include "SkPDFTypes.h" | 9 #include "SkPDFTypes.h" |
10 #include "SkPDFUtils.h" | 10 #include "SkPDFUtils.h" |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 } | 458 } |
459 | 459 |
460 SkPDFSharedStream::~SkPDFSharedStream() { this->drop(); } | 460 SkPDFSharedStream::~SkPDFSharedStream() { this->drop(); } |
461 | 461 |
462 void SkPDFSharedStream::drop() { | 462 void SkPDFSharedStream::drop() { |
463 fAsset.reset(); | 463 fAsset.reset(); |
464 fDict.reset(nullptr); | 464 fDict.reset(nullptr); |
465 SkDEBUGCODE(fDumped = true;) | 465 SkDEBUGCODE(fDumped = true;) |
466 } | 466 } |
467 | 467 |
| 468 #ifdef SK_PDF_LESS_COMPRESSION |
468 void SkPDFSharedStream::emitObject( | 469 void SkPDFSharedStream::emitObject( |
469 SkWStream* stream, | 470 SkWStream* stream, |
470 const SkPDFObjNumMap& objNumMap, | 471 const SkPDFObjNumMap& objNumMap, |
| 472 const SkPDFSubstituteMap& substitutes) const { |
| 473 SkASSERT(!fDumped); |
| 474 std::unique_ptr<SkStreamAsset> dup(fAsset->duplicate()); |
| 475 SkASSERT(dup && dup->hasLength()); |
| 476 size_t length = dup->getLength(); |
| 477 stream->writeText("<<"); |
| 478 fDict->emitAll(stream, objNumMap, substitutes); |
| 479 stream->writeText("\n"); |
| 480 SkPDFUnion::Name("Length").emitObject( |
| 481 stream, objNumMap, substitutes); |
| 482 stream->writeText(" "); |
| 483 SkPDFUnion::Int(length).emitObject( |
| 484 stream, objNumMap, substitutes); |
| 485 stream->writeText("\n>>stream\n"); |
| 486 SkStreamCopy(stream, dup.get()); |
| 487 stream->writeText("\nendstream"); |
| 488 } |
| 489 #else |
| 490 void SkPDFSharedStream::emitObject( |
| 491 SkWStream* stream, |
| 492 const SkPDFObjNumMap& objNumMap, |
471 const SkPDFSubstituteMap& substitutes) const { | 493 const SkPDFSubstituteMap& substitutes) const { |
472 SkASSERT(!fDumped); | 494 SkASSERT(!fDumped); |
473 SkDynamicMemoryWStream buffer; | 495 SkDynamicMemoryWStream buffer; |
474 SkDeflateWStream deflateWStream(&buffer); | 496 SkDeflateWStream deflateWStream(&buffer); |
475 // Since emitObject is const, this function doesn't change the dictionary. | 497 // Since emitObject is const, this function doesn't change the dictionary. |
476 std::unique_ptr<SkStreamAsset> dup(fAsset->duplicate()); // Cheap copy | 498 std::unique_ptr<SkStreamAsset> dup(fAsset->duplicate()); // Cheap copy |
477 SkASSERT(dup); | 499 SkASSERT(dup); |
478 SkStreamCopy(&deflateWStream, dup.get()); | 500 SkStreamCopy(&deflateWStream, dup.get()); |
479 deflateWStream.finalize(); | 501 deflateWStream.finalize(); |
480 size_t length = buffer.bytesWritten(); | 502 size_t length = buffer.bytesWritten(); |
481 stream->writeText("<<"); | 503 stream->writeText("<<"); |
482 fDict->emitAll(stream, objNumMap, substitutes); | 504 fDict->emitAll(stream, objNumMap, substitutes); |
483 stream->writeText("\n"); | 505 stream->writeText("\n"); |
484 SkPDFUnion::Name("Length").emitObject(stream, objNumMap, substitutes); | 506 SkPDFUnion::Name("Length").emitObject(stream, objNumMap, substitutes); |
485 stream->writeText(" "); | 507 stream->writeText(" "); |
486 SkPDFUnion::Int(length).emitObject(stream, objNumMap, substitutes); | 508 SkPDFUnion::Int(length).emitObject(stream, objNumMap, substitutes); |
487 stream->writeText("\n"); | 509 stream->writeText("\n"); |
488 SkPDFUnion::Name("Filter").emitObject(stream, objNumMap, substitutes); | 510 SkPDFUnion::Name("Filter").emitObject(stream, objNumMap, substitutes); |
489 stream->writeText(" "); | 511 stream->writeText(" "); |
490 SkPDFUnion::Name("FlateDecode").emitObject(stream, objNumMap, substitutes); | 512 SkPDFUnion::Name("FlateDecode").emitObject(stream, objNumMap, substitutes); |
491 stream->writeText(">>"); | 513 stream->writeText(">>"); |
492 stream->writeText(" stream\n"); | 514 stream->writeText(" stream\n"); |
493 buffer.writeToStream(stream); | 515 buffer.writeToStream(stream); |
494 stream->writeText("\nendstream"); | 516 stream->writeText("\nendstream"); |
495 } | 517 } |
| 518 #endif |
496 | 519 |
497 void SkPDFSharedStream::addResources( | 520 void SkPDFSharedStream::addResources( |
498 SkPDFObjNumMap* catalog, const SkPDFSubstituteMap& substitutes) const { | 521 SkPDFObjNumMap* catalog, const SkPDFSubstituteMap& substitutes) const { |
499 SkASSERT(!fDumped); | 522 SkASSERT(!fDumped); |
500 fDict->addResources(catalog, substitutes); | 523 fDict->addResources(catalog, substitutes); |
501 } | 524 } |
502 | 525 |
503 //////////////////////////////////////////////////////////////////////////////// | 526 //////////////////////////////////////////////////////////////////////////////// |
504 | 527 |
505 SkPDFSubstituteMap::~SkPDFSubstituteMap() { | 528 SkPDFSubstituteMap::~SkPDFSubstituteMap() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 573 |
551 void SkPDFImageDumpStats() { | 574 void SkPDFImageDumpStats() { |
552 SkDebugf("\ntotal PDF drawImage/drawBitmap calls: %d\n" | 575 SkDebugf("\ntotal PDF drawImage/drawBitmap calls: %d\n" |
553 "total PDF jpeg images: %d\n" | 576 "total PDF jpeg images: %d\n" |
554 "total PDF regular images: %d\n", | 577 "total PDF regular images: %d\n", |
555 gDrawImageCalls.load(), | 578 gDrawImageCalls.load(), |
556 gJpegImageObjects.load(), | 579 gJpegImageObjects.load(), |
557 gRegularImageObjects.load()); | 580 gRegularImageObjects.load()); |
558 } | 581 } |
559 #endif // SK_PDF_IMAGE_STATS | 582 #endif // SK_PDF_IMAGE_STATS |
OLD | NEW |