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" |
11 #include "SkFlate.h" | 11 #include "SkFlate.h" |
12 #include "SkPDFCatalog.h" | 12 #include "SkPDFCatalog.h" |
13 #include "SkPDFStream.h" | 13 #include "SkPDFStream.h" |
14 #include "SkStream.h" | 14 #include "SkStream.h" |
15 #include "SkStreamPriv.h" | 15 #include "SkStreamPriv.h" |
16 | 16 |
17 static bool skip_compression(SkPDFCatalog* catalog) { | |
18 return SkToBool(catalog->getDocumentFlags() & | |
19 SkPDFDocument::kFavorSpeedOverSize_Flags); | |
20 } | |
21 | |
22 SkPDFStream::SkPDFStream(SkStream* stream) : fState(kUnused_State) { | 17 SkPDFStream::SkPDFStream(SkStream* stream) : fState(kUnused_State) { |
23 this->setData(stream); | 18 this->setData(stream); |
24 } | 19 } |
25 | 20 |
26 SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) { | 21 SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) { |
27 this->setData(data); | 22 this->setData(data); |
28 } | 23 } |
29 | 24 |
30 SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream) | 25 SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream) |
31 : SkPDFDict(), | 26 : SkPDFDict(), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 if (fState == kUnused_State) { | 82 if (fState == kUnused_State) { |
88 fState = kNoCompression_State; | 83 fState = kNoCompression_State; |
89 insertInt("Length", this->dataSize()); | 84 insertInt("Length", this->dataSize()); |
90 } | 85 } |
91 return true; | 86 return true; |
92 | 87 |
93 #else // !SK_NO_FLATE | 88 #else // !SK_NO_FLATE |
94 | 89 |
95 if (fState == kUnused_State) { | 90 if (fState == kUnused_State) { |
96 fState = kNoCompression_State; | 91 fState = kNoCompression_State; |
97 if (!skip_compression(catalog)) { | 92 SkDynamicMemoryWStream compressedData; |
98 SkDynamicMemoryWStream compressedData; | |
99 | 93 |
100 SkAssertResult( | 94 SkAssertResult( |
101 SkFlate::Deflate(fDataStream.get(), &compressedData)); | 95 SkFlate::Deflate(fDataStream.get(), &compressedData)); |
102 SkAssertResult(fDataStream->rewind()); | 96 SkAssertResult(fDataStream->rewind()); |
103 if (compressedData.getOffset() < this->dataSize()) { | 97 if (compressedData.getOffset() < this->dataSize()) { |
104 SkAutoTDelete<SkStream> compressed( | 98 SkAutoTDelete<SkStream> compressed( |
105 compressedData.detachAsStream()); | 99 compressedData.detachAsStream()); |
106 this->setData(compressed.get()); | 100 this->setData(compressed.get()); |
107 insertName("Filter", "FlateDecode"); | 101 insertName("Filter", "FlateDecode"); |
108 } | |
109 fState = kCompressed_State; | |
110 } else { | |
111 fState = kNoCompression_State; | |
112 } | 102 } |
| 103 fState = kCompressed_State; |
113 insertInt("Length", this->dataSize()); | 104 insertInt("Length", this->dataSize()); |
114 } | 105 } |
115 else if (fState == kNoCompression_State && !skip_compression(catalog)) { | 106 else if (fState == kNoCompression_State) { |
116 if (!fSubstitute.get()) { | 107 if (!fSubstitute.get()) { |
117 fSubstitute.reset(new SkPDFStream(*this)); | 108 fSubstitute.reset(new SkPDFStream(*this)); |
118 catalog->setSubstitute(this, fSubstitute.get()); | 109 catalog->setSubstitute(this, fSubstitute.get()); |
119 } | 110 } |
120 return false; | 111 return false; |
121 } | 112 } |
122 return true; | 113 return true; |
123 #endif // SK_NO_FLATE | 114 #endif // SK_NO_FLATE |
124 } | 115 } |
OLD | NEW |