Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: src/pdf/SkPDFStream.cpp

Issue 2104223003: SkPDF: always assume SkStreamAsset behaves as specified (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010 Google Inc. 2 * Copyright 2010 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 8
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkDeflate.h" 10 #include "SkDeflate.h"
(...skipping 14 matching lines...) Expand all
25 this->INHERITED::emitObject(stream, objNumMap, substitutes); 25 this->INHERITED::emitObject(stream, objNumMap, substitutes);
26 // duplicate (a cheap operation) preserves const on fCompressedData. 26 // duplicate (a cheap operation) preserves const on fCompressedData.
27 std::unique_ptr<SkStreamAsset> dup(fCompressedData->duplicate()); 27 std::unique_ptr<SkStreamAsset> dup(fCompressedData->duplicate());
28 SkASSERT(dup); 28 SkASSERT(dup);
29 SkASSERT(dup->hasLength()); 29 SkASSERT(dup->hasLength());
30 stream->writeText(" stream\n"); 30 stream->writeText(" stream\n");
31 stream->writeStream(dup.get(), dup->getLength()); 31 stream->writeStream(dup.get(), dup->getLength());
32 stream->writeText("\nendstream"); 32 stream->writeText("\nendstream");
33 } 33 }
34 34
35
36 void SkPDFStream::setData(SkStreamAsset* stream) { 35 void SkPDFStream::setData(SkStreamAsset* stream) {
37 SkASSERT(!fCompressedData); // Only call this function once. 36 SkASSERT(!fCompressedData); // Only call this function once.
38 SkASSERT(stream); 37 SkASSERT(stream);
39 // Code assumes that the stream starts at the beginning. 38 // Code assumes that the stream starts at the beginning.
40 39
41 #ifdef SK_PDF_LESS_COMPRESSION 40 #ifdef SK_PDF_LESS_COMPRESSION
42 std::unique_ptr<SkStreamAsset> duplicate(stream->duplicate()); 41 fCompressedData.reset(stream->duplicate());
43 SkASSERT(duplicate && duplicate->hasLength()); 42 SkASSERT(fCompressedData && fCompressedData->hasLength());
44 if (duplicate && duplicate->hasLength()) { 43 this->insertInt("Length", fCompressedData->getLength());
45 this->insertInt("Length", duplicate->getLength()); 44 #else
46 fCompressedData.reset(duplicate.release());
47 return;
48 }
49 #endif
50 45
46 SkASSERT(stream->hasLength());
Tom Hudson 2016/06/29 13:37:28 I thought you were getting rid of these?
51 SkDynamicMemoryWStream compressedData; 47 SkDynamicMemoryWStream compressedData;
52 SkDeflateWStream deflateWStream(&compressedData); 48 SkDeflateWStream deflateWStream(&compressedData);
53 SkStreamCopy(&deflateWStream, stream); 49 SkStreamCopy(&deflateWStream, stream);
54 deflateWStream.finalize(); 50 deflateWStream.finalize();
55 size_t length = compressedData.bytesWritten(); 51 size_t compressedLength = compressedData.bytesWritten();
52 size_t originalLength = stream->getLength();
56 53
57 SkASSERT(stream->hasLength()); 54 if (originalLength <= compressedLength + strlen("/Filter_/FlateDecode_")) {
58 if (stream->hasLength()) { 55 fCompressedData.reset(stream->duplicate());
59 std::unique_ptr<SkStreamAsset> dup(stream->duplicate()); 56 this->insertInt("Length", originalLength);
60 SkASSERT(stream->hasLength()); 57 return;
61 SkASSERT(stream->getLength() == dup->getLength());
62 SkASSERT(dup && dup->hasLength());
63 if (dup && dup->hasLength() &&
64 dup->getLength() <= length + strlen("/Filter_/FlateDecode_")) {
65 this->insertInt("Length", dup->getLength());
66 fCompressedData.reset(dup.release());
67 return;
68 }
69 } 58 }
70 fCompressedData.reset(compressedData.detachAsStream()); 59 fCompressedData.reset(compressedData.detachAsStream());
71 this->insertName("Filter", "FlateDecode"); 60 this->insertName("Filter", "FlateDecode");
72 this->insertInt("Length", length); 61 this->insertInt("Length", compressedLength);
62 #endif
73 } 63 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698