aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-01-12 10:07:50 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-12 10:07:50 -0800
commit4fc48af0d7bec93a911d32330f251386a8adec98 (patch)
tree5f7335bed00f121fade421297dd117c8bebc2037
parent0899696e9fec7d376b63655bedaed76871cb15c2 (diff)
Change function signature of SkPDFObject::emitObject.
Replace virutal SkPDFObject::emitObject(s, c, true) with non-virtual SkPDFObject::emitIndirectObject(s, c), since none of the subclasses do (or should do) anything different. Replace object->emitObject(s, c, false) with object->emitObject(s, c) This is one step in simplifying the SkPDFObject interface to allow for the next step in refactoring. Review URL: https://codereview.chromium.org/827733004
-rw-r--r--src/pdf/SkPDFDocument.cpp8
-rw-r--r--src/pdf/SkPDFFont.cpp5
-rw-r--r--src/pdf/SkPDFFontImpl.h3
-rw-r--r--src/pdf/SkPDFGraphicState.cpp5
-rw-r--r--src/pdf/SkPDFGraphicState.h3
-rw-r--r--src/pdf/SkPDFPage.cpp2
-rw-r--r--src/pdf/SkPDFStream.cpp10
-rw-r--r--src/pdf/SkPDFStream.h3
-rw-r--r--src/pdf/SkPDFTypes.cpp52
-rw-r--r--src/pdf/SkPDFTypes.h30
-rw-r--r--tests/PDFPrimitivesTest.cpp2
11 files changed, 40 insertions, 83 deletions
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp
index 9b1458f832..632cbcfe3e 100644
--- a/src/pdf/SkPDFDocument.cpp
+++ b/src/pdf/SkPDFDocument.cpp
@@ -191,8 +191,8 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
}
emitHeader(stream);
- fDocCatalog->emitObject(stream, fCatalog.get(), true);
- fPages[0]->emitObject(stream, fCatalog.get(), true);
+ fDocCatalog->emitIndirectObject(stream, fCatalog.get());
+ fPages[0]->emitIndirectObject(stream, fCatalog.get());
fPages[0]->emitPage(stream, fCatalog.get());
for (int i = 0; i < fFirstPageResources->count(); i++) {
(*fFirstPageResources)[i]->emit(stream, fCatalog.get(), true);
@@ -205,7 +205,7 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
// }
for (int i = 0; i < fPageTree.count(); i++) {
- fPageTree[i]->emitObject(stream, fCatalog.get(), true);
+ fPageTree[i]->emitIndirectObject(stream, fCatalog.get());
}
for (int i = 1; i < fPages.count(); i++) {
@@ -340,7 +340,7 @@ void SkPDFDocument::emitFooter(SkWStream* stream, int64_t objCount) {
}
stream->writeText("trailer\n");
- fTrailerDict->emitObject(stream, fCatalog.get(), false);
+ fTrailerDict->emitObject(stream, fCatalog.get());
stream->writeText("\nstartxref\n");
stream->writeBigDecAsText(fXRefFileOffset);
stream->writeText("\n%%EOF");
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 3c5739cb71..08c1289ce3 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -1099,10 +1099,9 @@ SkPDFFont* SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) {
}
#ifdef SK_DEBUG
-void SkPDFType0Font::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
+void SkPDFType0Font::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
SkASSERT(fPopulated);
- return INHERITED::emitObject(stream, catalog, indirect);
+ return INHERITED::emitObject(stream, catalog);
}
#endif
diff --git a/src/pdf/SkPDFFontImpl.h b/src/pdf/SkPDFFontImpl.h
index 842e1c9547..eaec8f9002 100644
--- a/src/pdf/SkPDFFontImpl.h
+++ b/src/pdf/SkPDFFontImpl.h
@@ -18,8 +18,7 @@ public:
virtual bool multiByteGlyphs() const { return true; }
SK_API virtual SkPDFFont* getFontSubset(const SkPDFGlyphSet* usage);
#ifdef SK_DEBUG
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog);
#endif
private:
diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp
index 7664ed699b..b330fb4abf 100644
--- a/src/pdf/SkPDFGraphicState.cpp
+++ b/src/pdf/SkPDFGraphicState.cpp
@@ -69,10 +69,9 @@ void SkPDFGraphicState::getResources(
GetResourcesHelper(&fResources, knownResourceObjects, newResourceObjects);
}
-void SkPDFGraphicState::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
+void SkPDFGraphicState::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
populateDict();
- SkPDFDict::emitObject(stream, catalog, indirect);
+ SkPDFDict::emitObject(stream, catalog);
}
// static
diff --git a/src/pdf/SkPDFGraphicState.h b/src/pdf/SkPDFGraphicState.h
index 9182efeffb..28686e37be 100644
--- a/src/pdf/SkPDFGraphicState.h
+++ b/src/pdf/SkPDFGraphicState.h
@@ -41,8 +41,7 @@ public:
// Override emitObject and getOutputSize so that we can populate
// the dictionary on demand.
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog);
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
/** Get the graphic state for the passed SkPaint. The reference count of
diff --git a/src/pdf/SkPDFPage.cpp b/src/pdf/SkPDFPage.cpp
index cd05c9f59c..35fc4609c8 100644
--- a/src/pdf/SkPDFPage.cpp
+++ b/src/pdf/SkPDFPage.cpp
@@ -54,7 +54,7 @@ off_t SkPDFPage::getPageSize(SkPDFCatalog* catalog, off_t fileOffset) {
void SkPDFPage::emitPage(SkWStream* stream, SkPDFCatalog* catalog) {
SkASSERT(fContentStream.get() != NULL);
- fContentStream->emitObject(stream, catalog, true);
+ fContentStream->emitIndirectObject(stream, catalog);
}
// static
diff --git a/src/pdf/SkPDFStream.cpp b/src/pdf/SkPDFStream.cpp
index c310998a57..4b55226f12 100644
--- a/src/pdf/SkPDFStream.cpp
+++ b/src/pdf/SkPDFStream.cpp
@@ -45,17 +45,13 @@ SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream)
SkPDFStream::~SkPDFStream() {}
-void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
- if (indirect) {
- return emitIndirectObject(stream, catalog);
- }
+void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
SkAutoMutexAcquire lock(fMutex); // multiple threads could be calling emit
if (!this->populate(catalog)) {
- return fSubstitute->emitObject(stream, catalog, indirect);
+ return fSubstitute->emitObject(stream, catalog);
}
- this->INHERITED::emitObject(stream, catalog, false);
+ this->INHERITED::emitObject(stream, catalog);
stream->writeText(" stream\n");
stream->writeStream(fDataStream.get(), fDataStream->getLength());
SkAssertResult(fDataStream->rewind());
diff --git a/src/pdf/SkPDFStream.h b/src/pdf/SkPDFStream.h
index f908fbf2f3..7f33c162aa 100644
--- a/src/pdf/SkPDFStream.h
+++ b/src/pdf/SkPDFStream.h
@@ -41,8 +41,7 @@ public:
// The SkPDFObject interface. These two methods use a mutex to
// allow multiple threads to call at the same time.
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRIDE;
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
protected:
diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp
index 7b79e411b6..7562528c04 100644
--- a/src/pdf/SkPDFTypes.cpp
+++ b/src/pdf/SkPDFTypes.cpp
@@ -22,7 +22,11 @@
void SkPDFObject::emit(SkWStream* stream, SkPDFCatalog* catalog,
bool indirect) {
SkPDFObject* realObject = catalog->getSubstituteObject(this);
- return realObject->emitObject(stream, catalog, indirect);
+ if (indirect) {
+ realObject->emitIndirectObject(stream, catalog);
+ } else {
+ realObject->emitObject(stream, catalog);
+ }
}
size_t SkPDFObject::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
@@ -77,9 +81,7 @@ SkPDFObjRef::SkPDFObjRef(SkPDFObject* obj) : fObj(obj) {
SkPDFObjRef::~SkPDFObjRef() {}
-void SkPDFObjRef::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
- SkASSERT(!indirect);
+void SkPDFObjRef::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
catalog->emitObjectNumber(stream, fObj.get());
stream->writeText(" R");
}
@@ -92,20 +94,14 @@ size_t SkPDFObjRef::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
SkPDFInt::SkPDFInt(int32_t value) : fValue(value) {}
SkPDFInt::~SkPDFInt() {}
-void SkPDFInt::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
- if (indirect) {
- return emitIndirectObject(stream, catalog);
- }
+void SkPDFInt::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
stream->writeDecAsText(fValue);
}
SkPDFBool::SkPDFBool(bool value) : fValue(value) {}
SkPDFBool::~SkPDFBool() {}
-void SkPDFBool::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
- SkASSERT(!indirect);
+void SkPDFBool::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
if (fValue) {
stream->writeText("true");
} else {
@@ -124,12 +120,7 @@ size_t SkPDFBool::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
SkPDFScalar::SkPDFScalar(SkScalar value) : fValue(value) {}
SkPDFScalar::~SkPDFScalar() {}
-void SkPDFScalar::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
- if (indirect) {
- return emitIndirectObject(stream, catalog);
- }
-
+void SkPDFScalar::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
Append(fValue, stream);
}
@@ -196,10 +187,7 @@ SkPDFString::SkPDFString(const uint16_t* value, size_t len, bool wideChars)
SkPDFString::~SkPDFString() {}
-void SkPDFString::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
- if (indirect)
- return emitIndirectObject(stream, catalog);
+void SkPDFString::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
stream->write(fValue.c_str(), fValue.size());
}
@@ -282,9 +270,7 @@ bool SkPDFName::operator==(const SkPDFName& b) const {
return fValue == b.fValue;
}
-void SkPDFName::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
- SkASSERT(!indirect);
+void SkPDFName::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
stream->write(fValue.c_str(), fValue.size());
}
@@ -318,12 +304,7 @@ SkPDFArray::~SkPDFArray() {
fValue.unrefAll();
}
-void SkPDFArray::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
- if (indirect) {
- return emitIndirectObject(stream, catalog);
- }
-
+void SkPDFArray::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
stream->writeText("[");
for (int i = 0; i < fValue.count(); i++) {
fValue[i]->emit(stream, catalog, false);
@@ -402,12 +383,7 @@ int SkPDFDict::size() const {
}
-void SkPDFDict::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
- if (indirect) {
- return emitIndirectObject(stream, catalog);
- }
-
+void SkPDFDict::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
SkAutoMutexAcquire lock(fMutex); // If another thread triggers a
// resize while this thread is in
// the for-loop, we can be left
@@ -416,7 +392,7 @@ void SkPDFDict::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
for (int i = 0; i < fValue.count(); i++) {
SkASSERT(fValue[i].key);
SkASSERT(fValue[i].value);
- fValue[i].key->emitObject(stream, catalog, false);
+ fValue[i].key->emitObject(stream, catalog);
stream->writeText(" ");
fValue[i].value->emit(stream, catalog, false);
stream->writeText("\n");
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h
index 004c767843..75989c09ed 100644
--- a/src/pdf/SkPDFTypes.h
+++ b/src/pdf/SkPDFTypes.h
@@ -93,13 +93,11 @@ protected:
/** Subclasses must implement this method to print the object to the
* PDF file.
* @param catalog The object catalog to use.
- * @param indirect If true, output an object identifier with the object.
* @param stream The writable output stream to send the output to.
*/
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) = 0;
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) = 0;
- typedef SkRefCnt INHERITED;
+ typedef SkRefCnt INHERITED;
};
/** \class SkPDFObjRef
@@ -117,8 +115,7 @@ public:
virtual ~SkPDFObjRef();
// The SkPDFObject interface.
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRIDE;
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
private:
@@ -142,8 +139,7 @@ public:
virtual ~SkPDFInt();
// The SkPDFObject interface.
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRIDE;
private:
int32_t fValue;
@@ -166,8 +162,7 @@ public:
virtual ~SkPDFBool();
// The SkPDFObject interface.
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRIDE;
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
private:
@@ -193,8 +188,7 @@ public:
static void Append(SkScalar value, SkWStream* stream);
// The SkPDFObject interface.
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRIDE;
private:
SkScalar fValue;
@@ -226,8 +220,7 @@ public:
virtual ~SkPDFString();
// The SkPDFObject interface.
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRIDE;
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
static SkString FormatString(const char* input, size_t len);
@@ -262,8 +255,7 @@ public:
bool operator==(const SkPDFName& b) const;
// The SkPDFObject interface.
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRIDE;
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
private:
@@ -290,8 +282,7 @@ public:
virtual ~SkPDFArray();
// The SkPDFObject interface.
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRIDE;
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
/** The size of the array.
@@ -363,8 +354,7 @@ public:
virtual ~SkPDFDict();
// The SkPDFObject interface.
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRIDE;
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
/** The size of the dictionary.
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index 2ff98607fb..9421fc9597 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -205,7 +205,7 @@ static void TestObjectRef(skiatest::Reporter* reporter) {
char expectedResult[] = "2 0 R";
SkDynamicMemoryWStream buffer;
- int2ref->emitObject(&buffer, &catalog, false);
+ int2ref->emitObject(&buffer, &catalog);
REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult));
REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult,
buffer.getOffset()));