SkPDFDocument::kFavorSpeedOverSize_Flags);
}
-SkPDFStream::SkPDFStream(SkStream* stream)
- : fState(kUnused_State),
- fData(stream) {
- SkSafeRef(stream);
+SkPDFStream::SkPDFStream(SkStream* stream) : fState(kUnused_State) {
+ setData(stream);
}
SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) {
SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream)
: SkPDFDict(),
- fState(kUnused_State),
- fData(pdfStream.fData.get()) {
- fData.get()->ref();
+ fState(kUnused_State) {
+ setData(pdfStream.fData.get());
bool removeLength = true;
// Don't uncompress an already compressed stream, but we could.
if (pdfStream.fState == kCompressed_State) {
this->INHERITED::emitObject(stream, catalog, false);
stream->writeText(" stream\n");
- stream->write(fData->getMemoryBase(), fData->getLength());
+ stream->writeStream(fData.get(), fData->getLength());
+ fData->rewind();
stream->writeText("\nendstream");
}
}
void SkPDFStream::setData(SkStream* stream) {
+ // Code assumes that the stream starts at the beginning and is rewindable.
+ if (stream) {
+ SkASSERT(stream->getPosition() == 0);
+ SkASSERT(stream->rewind());
+ }
fData.reset(stream);
SkSafeRef(stream);
}