this->setData(data);
}
-SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream)
- : SkPDFDict(),
- fState(kUnused_State) {
- this->setData(pdfStream.fDataStream.get());
- bool removeLength = true;
- // Don't uncompress an already compressed stream, but we could.
- if (pdfStream.fState == kCompressed_State) {
- fState = kCompressed_State;
- removeLength = false;
- }
- this->mergeFrom(pdfStream);
- if (removeLength) {
- this->remove("Length");
- }
-}
-
SkPDFStream::~SkPDFStream() {}
void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
- if (!this->populate(catalog)) {
- return fSubstitute->emitObject(stream, catalog);
- }
-
+ SkAssertResult(this->populate(catalog));
this->INHERITED::emitObject(stream, catalog);
stream->writeText(" stream\n");
stream->writeStream(fDataStream.get(), fDataStream->getLength());
}
void SkPDFStream::setData(SkStream* stream) {
+ SkASSERT(stream);
// Code assumes that the stream starts at the beginning and is rewindable.
- if (stream) {
- // SkStreamRewindableFromSkStream will try stream->duplicate().
- fDataStream.reset(SkStreamRewindableFromSkStream(stream));
- SkASSERT(fDataStream.get());
- } else {
- // Use an empty memory stream.
- fDataStream.reset(SkNEW(SkMemoryStream));
- }
+ // SkStreamRewindableFromSkStream will try stream->duplicate().
+ fDataStream.reset(SkStreamRewindableFromSkStream(stream));
+ SkASSERT(fDataStream.get());
}
size_t SkPDFStream::dataSize() const {
}
bool SkPDFStream::populate(SkPDFCatalog* catalog) {
-#ifdef SK_NO_FLATE
- if (fState == kUnused_State) {
- fState = kNoCompression_State;
- insertInt("Length", this->dataSize());
- }
- return true;
-
-#else // !SK_NO_FLATE
-
if (fState == kUnused_State) {
fState = kNoCompression_State;
SkDynamicMemoryWStream compressedData;
fState = kCompressed_State;
insertInt("Length", this->dataSize());
}
- else if (fState == kNoCompression_State) {
- if (!fSubstitute.get()) {
- fSubstitute.reset(new SkPDFStream(*this));
- catalog->setSubstitute(this, fSubstitute.get());
- }
- return false;
- }
return true;
-#endif // SK_NO_FLATE
}
kCompressed_State, //!< The stream's already been compressed.
};
- /** Create a PDF stream with the same content and dictionary entries
- * as the passed one.
- */
- explicit SkPDFStream(const SkPDFStream& pdfStream);
-
/* Create a PDF stream with no data. The setData method must be called to
* set the data.
*/
// fSubstitute should be used.
virtual bool populate(SkPDFCatalog* catalog);
- void setSubstitute(SkPDFStream* stream) {
- fSubstitute.reset(stream);
- }
-
- SkPDFStream* getSubstitute() const {
- return fSubstitute.get();
- }
-
void setData(SkData* data);
void setData(SkStream* stream);
fState = state;
}
- State getState() const {
- return fState;
- }
-
private:
// Indicates what form (or if) the stream has been requested.
State fState;
SkAutoTDelete<SkStreamRewindable> fDataStream;
- SkAutoTUnref<SkPDFStream> fSubstitute;
typedef SkPDFDict INHERITED;
};
"<</Length 12\n/Attribute 42\n>> stream\n"
"Test\nFoo\tBar\nendstream");
-#ifndef SK_NO_FLATE
{
char streamBytes2[] = "This is a longer string, so that compression "
"can do something with it. With shorter strings, "
(const char*) expectedResultData2->data(),
expectedResultData2->size(), true);
}
-#endif // SK_NO_FLATE
}
static void TestCatalog(skiatest::Reporter* reporter) {