From: halcanary Date: Wed, 29 Jun 2016 14:23:47 +0000 (-0700) Subject: SkPDF: always assume SkStreamAsset behaves as specified X-Git-Tag: submit/tizen/20180928.044319~129^2~23 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2633e62f7798a17f095ba1f27ec1f72e5472c439;p=platform%2Fupstream%2FlibSkiaSharp.git SkPDF: always assume SkStreamAsset behaves as specified GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2104223003 Review-Url: https://codereview.chromium.org/2104223003 --- diff --git a/src/pdf/SkPDFStream.cpp b/src/pdf/SkPDFStream.cpp index 50735efa6c..a9b5864c08 100644 --- a/src/pdf/SkPDFStream.cpp +++ b/src/pdf/SkPDFStream.cpp @@ -32,42 +32,32 @@ void SkPDFStream::emitObject(SkWStream* stream, stream->writeText("\nendstream"); } - void SkPDFStream::setData(SkStreamAsset* stream) { SkASSERT(!fCompressedData); // Only call this function once. SkASSERT(stream); // Code assumes that the stream starts at the beginning. #ifdef SK_PDF_LESS_COMPRESSION - std::unique_ptr duplicate(stream->duplicate()); - SkASSERT(duplicate && duplicate->hasLength()); - if (duplicate && duplicate->hasLength()) { - this->insertInt("Length", duplicate->getLength()); - fCompressedData.reset(duplicate.release()); - return; - } - #endif + fCompressedData.reset(stream->duplicate()); + SkASSERT(fCompressedData && fCompressedData->hasLength()); + this->insertInt("Length", fCompressedData->getLength()); + #else + SkASSERT(stream->hasLength()); SkDynamicMemoryWStream compressedData; SkDeflateWStream deflateWStream(&compressedData); SkStreamCopy(&deflateWStream, stream); deflateWStream.finalize(); - size_t length = compressedData.bytesWritten(); + size_t compressedLength = compressedData.bytesWritten(); + size_t originalLength = stream->getLength(); - SkASSERT(stream->hasLength()); - if (stream->hasLength()) { - std::unique_ptr dup(stream->duplicate()); - SkASSERT(stream->hasLength()); - SkASSERT(stream->getLength() == dup->getLength()); - SkASSERT(dup && dup->hasLength()); - if (dup && dup->hasLength() && - dup->getLength() <= length + strlen("/Filter_/FlateDecode_")) { - this->insertInt("Length", dup->getLength()); - fCompressedData.reset(dup.release()); - return; - } + if (originalLength <= compressedLength + strlen("/Filter_/FlateDecode_")) { + fCompressedData.reset(stream->duplicate()); + this->insertInt("Length", originalLength); + return; } fCompressedData.reset(compressedData.detachAsStream()); this->insertName("Filter", "FlateDecode"); - this->insertInt("Length", length); + this->insertInt("Length", compressedLength); + #endif }