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

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

Issue 2098393002: SkPDF: SkPDFStream takes only SkStreamAsset (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 | « src/pdf/SkPDFStream.h ('k') | 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"
11 #include "SkPDFStream.h" 11 #include "SkPDFStream.h"
12 #include "SkStream.h" 12 #include "SkStream.h"
13 #include "SkStreamPriv.h" 13 #include "SkStreamPriv.h"
14 14
15 SkPDFStream::~SkPDFStream() {} 15 SkPDFStream::~SkPDFStream() {}
16 16
17 void SkPDFStream::drop() { 17 void SkPDFStream::drop() {
18 fCompressedData.reset(nullptr); 18 fCompressedData.reset(nullptr);
19 this->SkPDFDict::drop(); 19 this->SkPDFDict::drop();
20 } 20 }
21 21
22 void SkPDFStream::emitObject(SkWStream* stream, 22 void SkPDFStream::emitObject(SkWStream* stream,
23 const SkPDFObjNumMap& objNumMap, 23 const SkPDFObjNumMap& objNumMap,
24 const SkPDFSubstituteMap& substitutes) const { 24 const SkPDFSubstituteMap& substitutes) const {
25 SkASSERT(fCompressedData); 25 SkASSERT(fCompressedData);
26 this->INHERITED::emitObject(stream, objNumMap, substitutes); 26 this->INHERITED::emitObject(stream, objNumMap, substitutes);
27 // duplicate (a cheap operation) preserves const on fCompressedData. 27 // duplicate (a cheap operation) preserves const on fCompressedData.
28 std::unique_ptr<SkStreamRewindable> dup(fCompressedData->duplicate()); 28 std::unique_ptr<SkStreamAsset> dup(fCompressedData->duplicate());
29 SkASSERT(dup); 29 SkASSERT(dup);
30 SkASSERT(dup->hasLength()); 30 SkASSERT(dup->hasLength());
31 stream->writeText(" stream\n"); 31 stream->writeText(" stream\n");
32 stream->writeStream(dup.get(), dup->getLength()); 32 stream->writeStream(dup.get(), dup->getLength());
33 stream->writeText("\nendstream"); 33 stream->writeText("\nendstream");
34 } 34 }
35 35
36 36
37 void SkPDFStream::setData(SkStream* stream) { 37 void SkPDFStream::setData(SkStreamAsset* stream) {
38 SkASSERT(!fCompressedData); // Only call this function once. 38 SkASSERT(!fCompressedData); // Only call this function once.
39 SkASSERT(stream); 39 SkASSERT(stream);
40 // Code assumes that the stream starts at the beginning. 40 // Code assumes that the stream starts at the beginning.
41 41
42 #ifdef SK_PDF_LESS_COMPRESSION 42 #ifdef SK_PDF_LESS_COMPRESSION
43 std::unique_ptr<SkStreamRewindable> duplicate(stream->duplicate()); 43 std::unique_ptr<SkStreamAsset> duplicate(stream->duplicate());
44 SkASSERT(duplicate && duplicate->hasLength());
44 if (duplicate && duplicate->hasLength()) { 45 if (duplicate && duplicate->hasLength()) {
45 this->insertInt("Length", duplicate->getLength()); 46 this->insertInt("Length", duplicate->getLength());
46 fCompressedData.reset(duplicate.release()); 47 fCompressedData.reset(duplicate.release());
47 return; 48 return;
48 } 49 }
49 #endif 50 #endif
50 51
51 SkDynamicMemoryWStream compressedData; 52 SkDynamicMemoryWStream compressedData;
52 SkDeflateWStream deflateWStream(&compressedData); 53 SkDeflateWStream deflateWStream(&compressedData);
53 SkStreamCopy(&deflateWStream, stream); 54 SkStreamCopy(&deflateWStream, stream);
54 deflateWStream.finalize(); 55 deflateWStream.finalize();
55 size_t length = compressedData.bytesWritten(); 56 size_t length = compressedData.bytesWritten();
56 57
58 SkASSERT(stream->hasLength());
57 if (stream->hasLength()) { 59 if (stream->hasLength()) {
58 std::unique_ptr<SkStreamRewindable> dup(stream->duplicate()); 60 std::unique_ptr<SkStreamAsset> dup(stream->duplicate());
61 SkASSERT(stream->hasLength());
62 SkASSERT(stream->getLength() == dup->getLength());
63 SkASSERT(dup && dup->hasLength());
59 if (dup && dup->hasLength() && 64 if (dup && dup->hasLength() &&
60 dup->getLength() <= length + strlen("/Filter_/FlateDecode_")) { 65 dup->getLength() <= length + strlen("/Filter_/FlateDecode_")) {
61 this->insertInt("Length", dup->getLength()); 66 this->insertInt("Length", dup->getLength());
62 fCompressedData.reset(dup.release()); 67 fCompressedData.reset(dup.release());
63 return; 68 return;
64 } 69 }
65 } 70 }
66 fCompressedData.reset(compressedData.detachAsStream()); 71 fCompressedData.reset(compressedData.detachAsStream());
67 this->insertName("Filter", "FlateDecode"); 72 this->insertName("Filter", "FlateDecode");
68 this->insertInt("Length", length); 73 this->insertInt("Length", length);
69 } 74 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFStream.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698