diff options
author | halcanary <halcanary@google.com> | 2016-03-29 10:10:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-29 10:10:24 -0700 |
commit | 6e26205cece95702d34f935669498b569db72626 (patch) | |
tree | 149b8eb852c2d33399c60dc4994ee323d96337a3 /src | |
parent | ffe54004b92f84b65ee4569aaccbc178c51b017f (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/pdf/SkPDFStream.cpp | 10 | ||||
-rw-r--r-- | src/pdf/SkPDFTypes.cpp | 23 |
2 files changed, 33 insertions, 0 deletions
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<SkStreamRewindable> 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<SkStreamAsset> 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 { |