OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 SkPDFStream::~SkPDFStream() {} | 24 SkPDFStream::~SkPDFStream() {} |
25 | 25 |
26 void SkPDFStream::emitObject(SkWStream* stream, | 26 void SkPDFStream::emitObject(SkWStream* stream, |
27 const SkPDFObjNumMap& objNumMap, | 27 const SkPDFObjNumMap& objNumMap, |
28 const SkPDFSubstituteMap& substitutes) { | 28 const SkPDFSubstituteMap& substitutes) { |
29 if (fState == kUnused_State) { | 29 if (fState == kUnused_State) { |
30 fState = kNoCompression_State; | 30 fState = kNoCompression_State; |
31 SkDynamicMemoryWStream compressedData; | 31 SkDynamicMemoryWStream compressedData; |
32 | 32 SkDeflateWStream deflateWStream(&compressedData); |
33 SkAssertResult( | 33 SkAssertResult(SkStreamCopy(&deflateWStream, fDataStream.get())); |
34 SkFlate::Deflate(fDataStream.get(), &compressedData)); | 34 deflateWStream.finalize(); |
35 SkAssertResult(fDataStream->rewind()); | 35 SkAssertResult(fDataStream->rewind()); |
36 if (compressedData.getOffset() < this->dataSize()) { | 36 if (compressedData.getOffset() < this->dataSize()) { |
37 SkAutoTDelete<SkStream> compressed( | 37 SkAutoTDelete<SkStream> compressed( |
38 compressedData.detachAsStream()); | 38 compressedData.detachAsStream()); |
39 this->setData(compressed.get()); | 39 this->setData(compressed.get()); |
40 this->insertName("Filter", "FlateDecode"); | 40 this->insertName("Filter", "FlateDecode"); |
41 } | 41 } |
42 fState = kCompressed_State; | 42 fState = kCompressed_State; |
43 this->insertInt("Length", this->dataSize()); | 43 this->insertInt("Length", this->dataSize()); |
44 } | 44 } |
(...skipping 16 matching lines...) Expand all Loading... |
61 // Code assumes that the stream starts at the beginning and is rewindable. | 61 // Code assumes that the stream starts at the beginning and is rewindable. |
62 // SkStreamRewindableFromSkStream will try stream->duplicate(). | 62 // SkStreamRewindableFromSkStream will try stream->duplicate(). |
63 fDataStream.reset(SkStreamRewindableFromSkStream(stream)); | 63 fDataStream.reset(SkStreamRewindableFromSkStream(stream)); |
64 SkASSERT(fDataStream.get()); | 64 SkASSERT(fDataStream.get()); |
65 } | 65 } |
66 | 66 |
67 size_t SkPDFStream::dataSize() const { | 67 size_t SkPDFStream::dataSize() const { |
68 SkASSERT(fDataStream->hasLength()); | 68 SkASSERT(fDataStream->hasLength()); |
69 return fDataStream->getLength(); | 69 return fDataStream->getLength(); |
70 } | 70 } |
OLD | NEW |