From: halcanary Date: Tue, 31 Mar 2015 15:22:01 +0000 (-0700) Subject: SkPDF: remove SK_NO_FLATE & dead code in SkPDFStream X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~2968 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af9c85dee116fdc5f32029ac6a4fa7882c6b9a63;p=platform%2Fupstream%2FlibSkiaSharp.git SkPDF: remove SK_NO_FLATE & dead code in SkPDFStream SkPDFStream copy constructor SkPDFStream Substitute mechanism SkPDFStream::setData(NULL); SkPDFStream SK_NO_FLATE logic BUG=skia:3585 TBR=bsalomon@google.com,reed@google.com Review URL: https://codereview.chromium.org/1041183002 --- diff --git a/include/config/SkUserConfig.h b/include/config/SkUserConfig.h index a6f1293..607b26a 100644 --- a/include/config/SkUserConfig.h +++ b/include/config/SkUserConfig.h @@ -107,11 +107,6 @@ */ //#define SK_DEFAULT_IMAGE_CACHE_LIMIT (1024 * 1024) -/* If zlib is not available or you don't want to support flate compression - in PDF generation, define SK_NO_FLATE. - */ -//#define SK_NO_FLATE - /* Define this to allow PDF scalars above 32k. The PDF/A spec doesn't allow them, but modern PDF interpreters should handle them just fine. */ diff --git a/src/core/SkFlate.cpp b/src/core/SkFlate.cpp index 09975c0..1d764e8 100644 --- a/src/core/SkFlate.cpp +++ b/src/core/SkFlate.cpp @@ -11,8 +11,6 @@ #include "SkFlate.h" #include "SkStream.h" -#ifndef SK_NO_FLATE - namespace { #ifdef ZLIB_INCLUDE @@ -225,7 +223,3 @@ bool SkDeflateWStream::write(const void* void_buffer, size_t len) { size_t SkDeflateWStream::bytesWritten() const { return fImpl->fZStream.total_in + fImpl->fInBufferIndex; } - - -#endif // SK_NO_FLATE - diff --git a/src/core/SkFlate.h b/src/core/SkFlate.h index 35f1849..0104c45 100644 --- a/src/core/SkFlate.h +++ b/src/core/SkFlate.h @@ -12,8 +12,6 @@ #include "SkTypes.h" -#ifndef Sk_NO_FLATE - #include "SkStream.h" class SkData; @@ -74,5 +72,4 @@ private: SkAutoTDelete fImpl; }; -#endif // SK_NO_FLATE #endif // SkFlate_DEFINED diff --git a/src/pdf/SkPDFStream.cpp b/src/pdf/SkPDFStream.cpp index ae3fe4a..939cdd8 100644 --- a/src/pdf/SkPDFStream.cpp +++ b/src/pdf/SkPDFStream.cpp @@ -22,29 +22,10 @@ SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) { 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()); @@ -60,15 +41,11 @@ void SkPDFStream::setData(SkData* data) { } 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 { @@ -77,15 +54,6 @@ 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; @@ -102,13 +70,5 @@ bool SkPDFStream::populate(SkPDFCatalog* catalog) { 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 } diff --git a/src/pdf/SkPDFStream.h b/src/pdf/SkPDFStream.h index bb38ba9..9a43e3c 100644 --- a/src/pdf/SkPDFStream.h +++ b/src/pdf/SkPDFStream.h @@ -50,11 +50,6 @@ protected: 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. */ @@ -64,14 +59,6 @@ protected: // 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); @@ -81,16 +68,11 @@ protected: fState = state; } - State getState() const { - return fState; - } - private: // Indicates what form (or if) the stream has been requested. State fState; SkAutoTDelete fDataStream; - SkAutoTUnref fSubstitute; typedef SkPDFDict INHERITED; }; diff --git a/tests/DeflateWStream.cpp b/tests/DeflateWStream.cpp index 4a602f4..b225746 100644 --- a/tests/DeflateWStream.cpp +++ b/tests/DeflateWStream.cpp @@ -9,8 +9,6 @@ #include "SkRandom.h" #include "Test.h" -#ifndef SK_NO_FLATE - DEF_TEST(SkDeflateWStream, r) { SkRandom random(123456); for (int i = 0; i < 50; ++i) { @@ -72,4 +70,3 @@ DEF_TEST(SkDeflateWStream, r) { } } } -#endif // SK_NO_FLATE diff --git a/tests/FlateTest.cpp b/tests/FlateTest.cpp index 17e8b2d..40efe1a 100644 --- a/tests/FlateTest.cpp +++ b/tests/FlateTest.cpp @@ -10,8 +10,6 @@ #include "SkStream.h" #include "Test.h" -#ifndef SK_NO_FLATE - // A memory stream that reports zero size with the standard call, like // an unseekable file stream would. class SkZeroSizeMemStream : public SkMemoryStream { @@ -114,4 +112,3 @@ DEF_TEST(Flate, reporter) { TestFlate(reporter, &fileStream, 512); TestFlate(reporter, &fileStream, 10240); } -#endif // SK_NO_FLATE diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp index 36c803f..e361554 100644 --- a/tests/PDFPrimitivesTest.cpp +++ b/tests/PDFPrimitivesTest.cpp @@ -114,7 +114,6 @@ static void TestPDFStream(skiatest::Reporter* reporter) { "<> 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, " @@ -138,7 +137,6 @@ static void TestPDFStream(skiatest::Reporter* reporter) { (const char*) expectedResultData2->data(), expectedResultData2->size(), true); } -#endif // SK_NO_FLATE } static void TestCatalog(skiatest::Reporter* reporter) {