Index: src/pdf/SkPDFTypes.cpp |
diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp |
index 2fe408b1cc879abd910aba5af4e56355a3acb70e..9bb9dee49760840924cee3b022ee90db5d7dcf73 100644 |
--- a/src/pdf/SkPDFTypes.cpp |
+++ b/src/pdf/SkPDFTypes.cpp |
@@ -6,15 +6,10 @@ |
* found in the LICENSE file. |
*/ |
+#include "SkDeflate.h" |
#include "SkPDFTypes.h" |
#include "SkPDFUtils.h" |
-#include "SkStream.h" |
- |
-#ifdef SK_BUILD_FOR_WIN |
- #define SNPRINTF _snprintf |
-#else |
- #define SNPRINTF snprintf |
-#endif |
+#include "SkStreamPriv.h" |
//////////////////////////////////////////////////////////////////////////////// |
@@ -355,6 +350,13 @@ void SkPDFDict::emitObject(SkWStream* stream, |
const SkPDFObjNumMap& objNumMap, |
const SkPDFSubstituteMap& substitutes) const { |
stream->writeText("<<"); |
+ this->emitAll(stream, objNumMap, substitutes); |
+ stream->writeText(">>"); |
+} |
+ |
+void SkPDFDict::emitAll(SkWStream* stream, |
+ const SkPDFObjNumMap& objNumMap, |
+ const SkPDFSubstituteMap& substitutes) const { |
for (int i = 0; i < fRecords.count(); i++) { |
fRecords[i].fKey.emitObject(stream, objNumMap, substitutes); |
stream->writeText(" "); |
@@ -363,7 +365,6 @@ void SkPDFDict::emitObject(SkWStream* stream, |
stream->writeText("\n"); |
} |
} |
- stream->writeText(">>"); |
} |
void SkPDFDict::addResources(SkPDFObjNumMap* catalog, |
@@ -439,6 +440,41 @@ void SkPDFDict::clear() { |
//////////////////////////////////////////////////////////////////////////////// |
+void SkPDFSharedStream::emitObject( |
+ SkWStream* stream, |
+ const SkPDFObjNumMap& objNumMap, |
+ const SkPDFSubstituteMap& substitutes) const { |
+ SkDynamicMemoryWStream buffer; |
+ SkDeflateWStream deflateWStream(&buffer); |
+ // Since emitObject is const, this function doesn't change the dictionary. |
+ SkAutoTDelete<SkStreamAsset> dup(fAsset->duplicate()); // Cheap copy |
+ SkASSERT(dup); |
+ SkStreamCopy(&deflateWStream, dup.get()); |
+ deflateWStream.finalize(); |
+ size_t length = buffer.bytesWritten(); |
+ 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"); |
+ SkPDFUnion::Name("Filter").emitObject(stream, objNumMap, substitutes); |
+ stream->writeText(" "); |
+ SkPDFUnion::Name("FlateDecode").emitObject(stream, objNumMap, substitutes); |
+ stream->writeText(">>"); |
+ stream->writeText(" stream\n"); |
+ buffer.writeToStream(stream); |
+ stream->writeText("\nendstream"); |
+} |
+ |
+void SkPDFSharedStream::addResources( |
+ SkPDFObjNumMap* catalog, const SkPDFSubstituteMap& substitutes) const { |
+ fDict->addResources(catalog, substitutes); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+ |
SkPDFSubstituteMap::~SkPDFSubstituteMap() { |
fSubstituteMap.foreach( |
[](SkPDFObject*, SkPDFObject** v) { (*v)->unref(); }); |