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

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

Issue 2190883003: SkPDF: PDFStream has-a not is-a PDFDict (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-07-29 (Friday) 12:30:20 EDT Created 4 years, 4 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') | src/pdf/SkPDFTypes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2010 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9 #include "SkData.h"
10 #include "SkDeflate.h"
11 #include "SkPDFStream.h"
12 #include "SkStreamPriv.h"
13
14 SkPDFStream::~SkPDFStream() {}
15
16 void SkPDFStream::drop() {
17 fCompressedData.reset(nullptr);
18 this->SkPDFDict::drop();
19 }
20
21 void SkPDFStream::emitObject(SkWStream* stream,
22 const SkPDFObjNumMap& objNumMap,
23 const SkPDFSubstituteMap& substitutes) const {
24 SkASSERT(fCompressedData);
25 this->INHERITED::emitObject(stream, objNumMap, substitutes);
26 // duplicate (a cheap operation) preserves const on fCompressedData.
27 std::unique_ptr<SkStreamAsset> dup(fCompressedData->duplicate());
28 SkASSERT(dup);
29 SkASSERT(dup->hasLength());
30 stream->writeText(" stream\n");
31 stream->writeStream(dup.get(), dup->getLength());
32 stream->writeText("\nendstream");
33 }
34
35 void SkPDFStream::setData(std::unique_ptr<SkStreamAsset> stream) {
36 SkASSERT(!fCompressedData); // Only call this function once.
37 SkASSERT(stream);
38 // Code assumes that the stream starts at the beginning.
39
40 #ifdef SK_PDF_LESS_COMPRESSION
41 fCompressedData = std::move(stream);
42 SkASSERT(fCompressedData && fCompressedData->hasLength());
43 this->insertInt("Length", fCompressedData->getLength());
44 #else
45
46 SkASSERT(stream->hasLength());
47 SkDynamicMemoryWStream compressedData;
48 SkDeflateWStream deflateWStream(&compressedData);
49 SkStreamCopy(&deflateWStream, stream.get());
50 deflateWStream.finalize();
51 size_t compressedLength = compressedData.bytesWritten();
52 size_t originalLength = stream->getLength();
53
54 if (originalLength <= compressedLength + strlen("/Filter_/FlateDecode_")) {
55 SkAssertResult(stream->rewind());
56 fCompressedData = std::move(stream);
57 this->insertInt("Length", originalLength);
58 return;
59 }
60 fCompressedData.reset(compressedData.detachAsStream());
61 this->insertName("Filter", "FlateDecode");
62 this->insertInt("Length", compressedLength);
63 #endif
64 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFStream.h ('k') | src/pdf/SkPDFTypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698