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 19 matching lines...) Expand all Loading... |
30 fState = kNoCompression_State; | 30 fState = kNoCompression_State; |
31 SkDynamicMemoryWStream compressedData; | 31 SkDynamicMemoryWStream compressedData; |
32 | 32 |
33 SkAssertResult( | 33 SkAssertResult( |
34 SkFlate::Deflate(fDataStream.get(), &compressedData)); | 34 SkFlate::Deflate(fDataStream.get(), &compressedData)); |
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 insertName("Filter", "FlateDecode"); | 40 this->insertName("Filter", "FlateDecode"); |
41 } | 41 } |
42 fState = kCompressed_State; | 42 fState = kCompressed_State; |
43 insertInt("Length", this->dataSize()); | 43 this->insertInt("Length", this->dataSize()); |
44 } | 44 } |
45 this->INHERITED::emitObject(stream, objNumMap, substitutes); | 45 this->INHERITED::emitObject(stream, objNumMap, substitutes); |
46 stream->writeText(" stream\n"); | 46 stream->writeText(" stream\n"); |
47 stream->writeStream(fDataStream.get(), fDataStream->getLength()); | 47 stream->writeStream(fDataStream.get(), fDataStream->getLength()); |
48 SkAssertResult(fDataStream->rewind()); | 48 SkAssertResult(fDataStream->rewind()); |
49 stream->writeText("\nendstream"); | 49 stream->writeText("\nendstream"); |
50 } | 50 } |
51 | 51 |
52 SkPDFStream::SkPDFStream() : fState(kUnused_State) {} | 52 SkPDFStream::SkPDFStream() : fState(kUnused_State) {} |
53 | 53 |
54 void SkPDFStream::setData(SkData* data) { | 54 void SkPDFStream::setData(SkData* data) { |
55 // FIXME: Don't swap if the data is the same. | 55 // FIXME: Don't swap if the data is the same. |
56 fDataStream.reset(SkNEW_ARGS(SkMemoryStream, (data))); | 56 fDataStream.reset(SkNEW_ARGS(SkMemoryStream, (data))); |
57 } | 57 } |
58 | 58 |
59 void SkPDFStream::setData(SkStream* stream) { | 59 void SkPDFStream::setData(SkStream* stream) { |
60 SkASSERT(stream); | 60 SkASSERT(stream); |
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 |