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

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

Issue 1049753002: SkPDF: Factor SkPDFCatalog into SkPDFObjNumMap and SkPDFSubstituteMap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: full Created 5 years, 8 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
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"
13 #include "SkPDFStream.h" 12 #include "SkPDFStream.h"
14 #include "SkStream.h" 13 #include "SkStream.h"
15 #include "SkStreamPriv.h" 14 #include "SkStreamPriv.h"
16 15
17 SkPDFStream::SkPDFStream(SkStream* stream) : fState(kUnused_State) { 16 SkPDFStream::SkPDFStream(SkStream* stream) : fState(kUnused_State) {
18 this->setData(stream); 17 this->setData(stream);
19 } 18 }
20 19
21 SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) { 20 SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) {
22 this->setData(data); 21 this->setData(data);
23 } 22 }
24 23
25 SkPDFStream::~SkPDFStream() {} 24 SkPDFStream::~SkPDFStream() {}
26 25
27 void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { 26 void SkPDFStream::emitObject(SkWStream* stream,
28 SkAssertResult(this->populate(catalog)); 27 const SkPDFObjNumMap& objNumMap,
29 this->INHERITED::emitObject(stream, catalog); 28 const SkPDFSubstituteMap& substitutes) {
29 if (fState == kUnused_State) {
30 fState = kNoCompression_State;
31 SkDynamicMemoryWStream compressedData;
32
33 SkAssertResult(
34 SkFlate::Deflate(fDataStream.get(), &compressedData));
35 SkAssertResult(fDataStream->rewind());
36 if (compressedData.getOffset() < this->dataSize()) {
37 SkAutoTDelete<SkStream> compressed(
38 compressedData.detachAsStream());
39 this->setData(compressed.get());
40 insertName("Filter", "FlateDecode");
mtklein 2015/03/31 19:29:21 It'd be nice to tack on this-> to these insertFoo
hal.canary 2015/03/31 19:32:48 will do.
41 }
42 fState = kCompressed_State;
43 insertInt("Length", this->dataSize());
44 }
45 this->INHERITED::emitObject(stream, objNumMap, substitutes);
30 stream->writeText(" stream\n"); 46 stream->writeText(" stream\n");
31 stream->writeStream(fDataStream.get(), fDataStream->getLength()); 47 stream->writeStream(fDataStream.get(), fDataStream->getLength());
32 SkAssertResult(fDataStream->rewind()); 48 SkAssertResult(fDataStream->rewind());
33 stream->writeText("\nendstream"); 49 stream->writeText("\nendstream");
34 } 50 }
35 51
36 SkPDFStream::SkPDFStream() : fState(kUnused_State) {} 52 SkPDFStream::SkPDFStream() : fState(kUnused_State) {}
37 53
38 void SkPDFStream::setData(SkData* data) { 54 void SkPDFStream::setData(SkData* data) {
39 // FIXME: Don't swap if the data is the same. 55 // FIXME: Don't swap if the data is the same.
40 fDataStream.reset(SkNEW_ARGS(SkMemoryStream, (data))); 56 fDataStream.reset(SkNEW_ARGS(SkMemoryStream, (data)));
41 } 57 }
42 58
43 void SkPDFStream::setData(SkStream* stream) { 59 void SkPDFStream::setData(SkStream* stream) {
44 SkASSERT(stream); 60 SkASSERT(stream);
45 // 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.
46 // SkStreamRewindableFromSkStream will try stream->duplicate(). 62 // SkStreamRewindableFromSkStream will try stream->duplicate().
47 fDataStream.reset(SkStreamRewindableFromSkStream(stream)); 63 fDataStream.reset(SkStreamRewindableFromSkStream(stream));
48 SkASSERT(fDataStream.get()); 64 SkASSERT(fDataStream.get());
49 } 65 }
50 66
51 size_t SkPDFStream::dataSize() const { 67 size_t SkPDFStream::dataSize() const {
52 SkASSERT(fDataStream->hasLength()); 68 SkASSERT(fDataStream->hasLength());
53 return fDataStream->getLength(); 69 return fDataStream->getLength();
54 } 70 }
55
56 bool SkPDFStream::populate(SkPDFCatalog* catalog) {
57 if (fState == kUnused_State) {
58 fState = kNoCompression_State;
59 SkDynamicMemoryWStream compressedData;
60
61 SkAssertResult(
62 SkFlate::Deflate(fDataStream.get(), &compressedData));
63 SkAssertResult(fDataStream->rewind());
64 if (compressedData.getOffset() < this->dataSize()) {
65 SkAutoTDelete<SkStream> compressed(
66 compressedData.detachAsStream());
67 this->setData(compressed.get());
68 insertName("Filter", "FlateDecode");
69 }
70 fState = kCompressed_State;
71 insertInt("Length", this->dataSize());
72 }
73 return true;
74 }
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