From 6e26205cece95702d34f935669498b569db72626 Mon Sep 17 00:00:00 2001 From: halcanary Date: Tue, 29 Mar 2016 10:10:24 -0700 Subject: SkPDF: skia_pdf_less_compression - for debugging only Motivation: as we implement more features in PDF, it would be nice to more easily see what is happening in the output. This change serializes page content as plain text rather than compressed text, but it has to be explicitly enabled with a GYP_DEFINE change: export GYP_DEFINES='skia_pdf_less_compression=1' bin/sync-and-gyp ninja -C out/Debug dm out/Debug/dm --config pdf --src gm -w /tmp GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1840103002 Review URL: https://codereview.chromium.org/1840103002 --- src/pdf/SkPDFStream.cpp | 10 ++++++++++ src/pdf/SkPDFTypes.cpp | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) (limited to 'src') diff --git a/src/pdf/SkPDFStream.cpp b/src/pdf/SkPDFStream.cpp index 10fc77b587..bfe33a8465 100644 --- a/src/pdf/SkPDFStream.cpp +++ b/src/pdf/SkPDFStream.cpp @@ -33,11 +33,21 @@ void SkPDFStream::emitObject(SkWStream* stream, stream->writeText("\nendstream"); } + void SkPDFStream::setData(SkStream* 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()); + if (duplicate && duplicate->hasLength()) { + this->insertInt("Length", duplicate->getLength()); + fCompressedData.reset(duplicate.release()); + return; + } + #endif + SkDynamicMemoryWStream compressedData; SkDeflateWStream deflateWStream(&compressedData); SkStreamCopy(&deflateWStream, stream); diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp index 5eb5c39c0e..285da38513 100644 --- a/src/pdf/SkPDFTypes.cpp +++ b/src/pdf/SkPDFTypes.cpp @@ -465,6 +465,28 @@ void SkPDFSharedStream::drop() { SkDEBUGCODE(fDumped = true;) } +#ifdef SK_PDF_LESS_COMPRESSION +void SkPDFSharedStream::emitObject( + SkWStream* stream, + const SkPDFObjNumMap& objNumMap, + const SkPDFSubstituteMap& substitutes) const { + SkASSERT(!fDumped); + std::unique_ptr dup(fAsset->duplicate()); + SkASSERT(dup && dup->hasLength()); + size_t length = dup->getLength(); + stream->writeText("<<"); + fDict->emitAll(stream, objNumMap, substitutes); + stream->writeText("\n"); + SkPDFUnion::Name("Length").emitObject( + stream, objNumMap, substitutes); + stream->writeText(" "); + SkPDFUnion::Int(length).emitObject( + stream, objNumMap, substitutes); + stream->writeText("\n>>stream\n"); + SkStreamCopy(stream, dup.get()); + stream->writeText("\nendstream"); +} +#else void SkPDFSharedStream::emitObject( SkWStream* stream, const SkPDFObjNumMap& objNumMap, @@ -493,6 +515,7 @@ void SkPDFSharedStream::emitObject( buffer.writeToStream(stream); stream->writeText("\nendstream"); } +#endif void SkPDFSharedStream::addResources( SkPDFObjNumMap* catalog, const SkPDFSubstituteMap& substitutes) const { -- cgit v1.2.3