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
This commit is contained in:
halcanary 2015-01-12 10:07:50 -08:00 committed by Commit bot
parent 0899696e9f
commit 4fc48af0d7
11 changed files with 40 additions and 83 deletions

View File

@ -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");

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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());

View File

@ -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:

View File

@ -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");

View File

@ -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.

View File

@ -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()));