aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-01-23 11:45:10 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-23 11:45:10 -0800
commit6a144345d742a53ffb15bbd83f2718022fca8df5 (patch)
tree54e801cddcecca5addcbc9ca89b5f707dde3466a /src/pdf
parent1c4029296f518a84ef90095243ba210163a1e1f9 (diff)
Cleanup SkPDFObject::emit*
Diffstat (limited to 'src/pdf')
-rw-r--r--src/pdf/SkPDFDocument.cpp10
-rw-r--r--src/pdf/SkPDFTypes.cpp43
-rw-r--r--src/pdf/SkPDFTypes.h34
3 files changed, 29 insertions, 58 deletions
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp
index c4a5d448a5..c522b39516 100644
--- a/src/pdf/SkPDFDocument.cpp
+++ b/src/pdf/SkPDFDocument.cpp
@@ -89,9 +89,13 @@ public:
: fCat(cat), fOut(out), fBaseOffset(SkToOffT(out->bytesWritten())) {
}
- void stream(SkPDFObject* obj) {
- fCat->setFileOffset(obj, this->offset());
- obj->emit(fOut, fCat, true);
+ void stream(SkPDFObject* object) {
+ fCat->setFileOffset(object, this->offset());
+ SkPDFObject* realObject = fCat->getSubstituteObject(object);
+ fCat->emitObjectNumber(fOut, realObject);
+ fOut->writeText(" obj\n");
+ realObject->emitObject(fOut, fCat);
+ fOut->writeText("\nendobj\n");
}
off_t offset() {
diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp
index 4a84876b20..b0763a3c59 100644
--- a/src/pdf/SkPDFTypes.cpp
+++ b/src/pdf/SkPDFTypes.cpp
@@ -19,32 +19,9 @@
///////////////////////////////////////////////////////////////////////////////
-void SkPDFObject::emit(SkWStream* stream, SkPDFCatalog* catalog,
- bool indirect) {
- SkPDFObject* realObject = catalog->getSubstituteObject(this);
- if (indirect) {
- realObject->emitIndirectObject(stream, catalog);
- } else {
- realObject->emitObject(stream, catalog);
- }
-}
-
-size_t SkPDFObject::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
- SkDynamicMemoryWStream buffer;
- emit(&buffer, catalog, indirect);
- return buffer.getOffset();
-}
-
void SkPDFObject::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
SkTSet<SkPDFObject*>* newResourceObjects) {}
-void SkPDFObject::emitIndirectObject(SkWStream* stream, SkPDFCatalog* catalog) {
- catalog->emitObjectNumber(stream, this);
- stream->writeText(" obj\n");
- emit(stream, catalog, false);
- stream->writeText("\nendobj\n");
-}
-
void SkPDFObject::AddResourceHelper(SkPDFObject* resource,
SkTDArray<SkPDFObject*>* list) {
list->push(resource);
@@ -70,6 +47,8 @@ void SkPDFObject::GetResourcesHelper(
}
}
+////////////////////////////////////////////////////////////////////////////////
+
SkPDFObjRef::SkPDFObjRef(SkPDFObject* obj) : fObj(obj) {
SkSafeRef(obj);
}
@@ -81,6 +60,8 @@ void SkPDFObjRef::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
stream->writeText(" R");
}
+////////////////////////////////////////////////////////////////////////////////
+
SkPDFInt::SkPDFInt(int32_t value) : fValue(value) {}
SkPDFInt::~SkPDFInt() {}
@@ -88,6 +69,8 @@ void SkPDFInt::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
stream->writeDecAsText(fValue);
}
+////////////////////////////////////////////////////////////////////////////////
+
SkPDFBool::SkPDFBool(bool value) : fValue(value) {}
SkPDFBool::~SkPDFBool() {}
@@ -99,6 +82,8 @@ void SkPDFBool::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
}
}
+////////////////////////////////////////////////////////////////////////////////
+
SkPDFScalar::SkPDFScalar(SkScalar value) : fValue(value) {}
SkPDFScalar::~SkPDFScalar() {}
@@ -155,6 +140,8 @@ void SkPDFScalar::Append(SkScalar value, SkWStream* stream) {
#endif // SK_ALLOW_LARGE_PDF_SCALARS
}
+////////////////////////////////////////////////////////////////////////////////
+
SkPDFString::SkPDFString(const char value[])
: fValue(FormatString(value, strlen(value))) {
}
@@ -238,6 +225,8 @@ SkString SkPDFString::DoFormatString(const void* input, size_t len,
return result;
}
+////////////////////////////////////////////////////////////////////////////////
+
SkPDFName::SkPDFName(const char name[]) : fValue(FormatName(SkString(name))) {}
SkPDFName::SkPDFName(const SkString& name) : fValue(FormatName(name)) {}
SkPDFName::~SkPDFName() {}
@@ -270,6 +259,8 @@ SkString SkPDFName::FormatName(const SkString& input) {
return result;
}
+////////////////////////////////////////////////////////////////////////////////
+
SkPDFArray::SkPDFArray() {}
SkPDFArray::~SkPDFArray() {
fValue.unrefAll();
@@ -278,7 +269,7 @@ SkPDFArray::~SkPDFArray() {
void SkPDFArray::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
stream->writeText("[");
for (int i = 0; i < fValue.count(); i++) {
- fValue[i]->emit(stream, catalog, false);
+ catalog->getSubstituteObject(fValue[i])->emitObject(stream, catalog);
if (i + 1 < fValue.count()) {
stream->writeText(" ");
}
@@ -338,7 +329,6 @@ int SkPDFDict::size() const {
return fValue.count();
}
-
void SkPDFDict::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
SkAutoMutexAcquire lock(fMutex); // If another thread triggers a
// resize while this thread is in
@@ -350,7 +340,8 @@ void SkPDFDict::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
SkASSERT(fValue[i].value);
fValue[i].key->emitObject(stream, catalog);
stream->writeText(" ");
- fValue[i].value->emit(stream, catalog, false);
+ catalog->getSubstituteObject(fValue[i].value)
+ ->emitObject(stream, catalog);
stream->writeText("\n");
}
stream->writeText(">>");
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h
index ce1ca86e6e..b0ce0b97d0 100644
--- a/src/pdf/SkPDFTypes.h
+++ b/src/pdf/SkPDFTypes.h
@@ -30,12 +30,12 @@ class SkPDFObject : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(SkPDFObject)
- /** Return the size (number of bytes) of this object in the final output
- * file. Only used for testing.
+ /** 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.
*/
- size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
+ virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) = 0;
/** For non-primitive objects (i.e. objects defined outside this file),
* this method will add to newResourceObjects any objects that this method
@@ -49,23 +49,6 @@ public:
virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
SkTSet<SkPDFObject*>* newResourceObjects);
- /** Emit this object unless the catalog has a substitute object, in which
- * case emit that.
- * @see emitObject
- */
- void emit(SkWStream* stream, SkPDFCatalog* catalog, bool indirect);
-
- /** Helper function to output an indirect object.
- * @param catalog The object catalog to use.
- * @param stream The writable output stream to send the output to.
- */
- void emitIndirectObject(SkWStream* stream, SkPDFCatalog* catalog);
-
- /** Helper function to find the size of an indirect object.
- * @param catalog The object catalog to use.
- */
- size_t getIndirectOutputSize(SkPDFCatalog* catalog);
-
/** Static helper function to add a resource to a list. The list takes
* a reference.
* @param resource The resource to add.
@@ -88,14 +71,7 @@ public:
const SkTSet<SkPDFObject*>& knownResourceObjects,
SkTSet<SkPDFObject*>* newResourceObjects);
-protected:
- /** Subclasses must implement this method to print the object to the
- * PDF file.
- * @param catalog The object catalog to use.
- * @param stream The writable output stream to send the output to.
- */
- virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) = 0;
-
+private:
typedef SkRefCnt INHERITED;
};