[PDF] Fix printing crashes caused by font streams that don't support getMemoryBase().
authorvandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 26 Aug 2013 22:52:09 +0000 (22:52 +0000)
committervandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 26 Aug 2013 22:52:09 +0000 (22:52 +0000)
An apparently recently change started putting web fonts into SkStream objects that don't support getMemoryBase().  This change uses writeStream to avoid needing to call getMemoryBase().

BUG=chromium:274440
R=bungeman@google.com

Review URL: https://codereview.chromium.org/23437004

git-svn-id: http://skia.googlecode.com/svn/trunk@10928 2bbb7eff-a529-9590-31e7-b0007b416f81

src/pdf/SkPDFStream.cpp
src/pdf/SkPDFStream.h

index 4ae1f39d26f18dc9783c5bcf1decb75c7a828b05..e570976403382cac79dfcb327030391fa9a08253 100644 (file)
@@ -18,10 +18,8 @@ static bool skip_compression(SkPDFCatalog* catalog) {
                     SkPDFDocument::kFavorSpeedOverSize_Flags);
 }
 
-SkPDFStream::SkPDFStream(SkStream* stream)
-    : fState(kUnused_State),
-      fData(stream) {
-    SkSafeRef(stream);
+SkPDFStream::SkPDFStream(SkStream* stream) : fState(kUnused_State) {
+    setData(stream);
 }
 
 SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) {
@@ -30,9 +28,8 @@ SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) {
 
 SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream)
         : SkPDFDict(),
-          fState(kUnused_State),
-          fData(pdfStream.fData.get()) {
-    fData.get()->ref();
+          fState(kUnused_State) {
+    setData(pdfStream.fData.get());
     bool removeLength = true;
     // Don't uncompress an already compressed stream, but we could.
     if (pdfStream.fState == kCompressed_State) {
@@ -64,7 +61,8 @@ void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
 
     this->INHERITED::emitObject(stream, catalog, false);
     stream->writeText(" stream\n");
-    stream->write(fData->getMemoryBase(), fData->getLength());
+    stream->writeStream(fData.get(), fData->getLength());
+    fData->rewind();
     stream->writeText("\nendstream");
 }
 
@@ -89,6 +87,11 @@ void SkPDFStream::setData(SkData* data) {
 }
 
 void SkPDFStream::setData(SkStream* stream) {
+    // Code assumes that the stream starts at the beginning and is rewindable.
+    if (stream) {
+        SkASSERT(stream->getPosition() == 0);
+        SkASSERT(stream->rewind());
+    }
     fData.reset(stream);
     SkSafeRef(stream);
 }
index ed18510c9f53f7fbf9a628ba21e0a796befcfb14..d7ff115ba9170fbd88af8571cdd70b4ec9f6673e 100644 (file)
@@ -21,6 +21,8 @@ class SkPDFCatalog;
 
     A stream object in a PDF.  Note, all streams must be indirect objects (via
     SkObjRef).
+    TODO(vandebo): SkStream should be replaced by SkStreamRewindable when that
+    is feasible.
 */
 class SkPDFStream : public SkPDFDict {
 public: