aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-10-26 19:48:49 +0000
committerGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-10-26 19:48:49 +0000
commita518086928494319b8968abc09808eff492c194f (patch)
tree5301b6c2f21c3ff61b39332b62692ea93a77c9d8
parent35fc62b960db6739b19c59576085663796951e47 (diff)
Several cleanups:
Fix the spelling of resource in several places Make getResouce(resourceList) part of SkPDFObject make SkDynamicMemoryWStream::getOffset and SkPDFPage::getMediaBox const Add a temporary NOT_IMPLEMENTED macro instead of using SkASSERT Review URL: http://codereview.appspot.com/2721041 git-svn-id: http://skia.googlecode.com/svn/trunk@619 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkStream.h2
-rw-r--r--include/pdf/SkPDFDevice.h11
-rw-r--r--include/pdf/SkPDFDocument.h2
-rw-r--r--include/pdf/SkPDFPage.h10
-rw-r--r--include/pdf/SkPDFTypes.h9
-rw-r--r--src/pdf/SkPDFDevice.cpp92
-rw-r--r--src/pdf/SkPDFDocument.cpp34
-rw-r--r--src/pdf/SkPDFPage.cpp2
-rw-r--r--src/pdf/SkPDFTypes.cpp2
9 files changed, 92 insertions, 72 deletions
diff --git a/include/core/SkStream.h b/include/core/SkStream.h
index 487c7d68c4..046c4d963f 100644
--- a/include/core/SkStream.h
+++ b/include/core/SkStream.h
@@ -273,7 +273,7 @@ public:
// modifies stream and returns true if offset + size is less than or equal to getOffset()
bool write(const void* buffer, size_t offset, size_t size);
bool read(void* buffer, size_t offset, size_t size);
- size_t getOffset() { return fBytesWritten; }
+ size_t getOffset() const { return fBytesWritten; }
// copy what has been written to the stream into dst
void copyTo(void* dst) const;
diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h
index b972dd4752..7310229bb7 100644
--- a/include/pdf/SkPDFDevice.h
+++ b/include/pdf/SkPDFDevice.h
@@ -20,6 +20,8 @@
#include "SkRefCnt.h"
#include "SkDevice.h"
#include "SkString.h"
+#include "SkPaint.h"
+#include "SkPath.h"
class SkPDFArray;
class SkPDFDevice;
@@ -101,14 +103,14 @@ public:
*/
const SkRefPtr<SkPDFDict>& getResourceDict();
- /** Get the list of resouces (PDF objects) used on this page
- * @param resouceList A list to append the resouces to.
+ /** Get the list of resources (PDF objects) used on this page.
+ * @param resourceList A list to append the resources to.
*/
- void getResouces(SkTDArray<SkPDFObject*>* resouceList);
+ void getResources(SkTDArray<SkPDFObject*>* resourceList) const;
/** Returns the media box for this device.
*/
- SkRefPtr<SkPDFArray> getMediaBox();
+ SkRefPtr<SkPDFArray> getMediaBox() const;
/** Returns a string with the page contents.
* @param flipOrigin Flip the origin between top and bottom.
@@ -144,6 +146,7 @@ private:
void appendRectangle(SkScalar x, SkScalar y, SkScalar w, SkScalar h);
void closePath();
void strokePath();
+ void paintPath(SkPaint::Style style, SkPath::FillType fill);
void internalDrawBitmap(const SkMatrix& matrix, const SkBitmap& bitmap,
const SkPaint& paint);
diff --git a/include/pdf/SkPDFDocument.h b/include/pdf/SkPDFDocument.h
index 91dd379214..54b86c4a29 100644
--- a/include/pdf/SkPDFDocument.h
+++ b/include/pdf/SkPDFDocument.h
@@ -57,7 +57,7 @@ private:
SkTDArray<SkPDFDict*> fPageTree;
SkRefPtr<SkPDFDict> fDocCatalog;
SkTDArray<SkPDFObject*> fPageResources;
- int fSecondPageFirstResouceIndex;
+ int fSecondPageFirstResourceIndex;
SkRefPtr<SkPDFDict> fTrailerDict;
diff --git a/include/pdf/SkPDFPage.h b/include/pdf/SkPDFPage.h
index 7e96212bbf..0831cb504e 100644
--- a/include/pdf/SkPDFPage.h
+++ b/include/pdf/SkPDFPage.h
@@ -45,11 +45,11 @@ public:
* finalizePage has been called. This function adds the page content
* to the passed catalog, so it must be called for each document
* that the page is part of.
- * @param catalog The catalog to add page content objects to.
- * @param firstPage Indicate if this is the first page of a document.
- * @param resouceObjects The resource objects used on the page are added
- * to this array. This gives the caller a chance
- * to deduplicate resources across pages.
+ * @param catalog The catalog to add page content objects to.
+ * @param firstPage Indicate if this is the first page of a document.
+ * @param resourceObjects The resource objects used on the page are added
+ * to this array. This gives the caller a chance
+ * to deduplicate resources across pages.
*/
void finalizePage(SkPDFCatalog* catalog, bool firstPage,
SkTDArray<SkPDFObject*>* resourceObjects);
diff --git a/include/pdf/SkPDFTypes.h b/include/pdf/SkPDFTypes.h
index 2066352167..a281628a23 100644
--- a/include/pdf/SkPDFTypes.h
+++ b/include/pdf/SkPDFTypes.h
@@ -55,6 +55,15 @@ public:
*/
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
+ /** If this object explicitly depends on other objects, add them to the
+ * end of the list. This only applies to higher level object, where
+ * the depenency is explicit and introduced by the class. i.e. an
+ * SkPDFImage added to an SkPDFDevice, but not an SkPDFObjRef added to
+ * an SkPDFArray.
+ * @param resourceList The list to append dependant resources to.
+ */
+ virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
+
/** 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.
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 00c05e4080..7a0b5a8f45 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -18,6 +18,7 @@
#include "SkColor.h"
#include "SkPaint.h"
+#include "SkPath.h"
#include "SkPDFImage.h"
#include "SkPDFGraphicState.h"
#include "SkPDFTypes.h"
@@ -25,6 +26,14 @@
#include "SkRect.h"
#include "SkString.h"
+#define NOT_IMPLEMENTED(condition, assert) \
+ do { \
+ if (condition) { \
+ fprintf(stderr, "NOT_IMPLEMENTED: " #condition "\n"); \
+ SkASSERT(!assert); \
+ } \
+ } while(0)
+
// Utility functions
namespace {
@@ -33,34 +42,18 @@ SkString toPDFColor(SkColor color) {
SkASSERT(SkColorGetA(color) == 0xFF); // We handle alpha elsewhere.
SkScalar colorMax = SkIntToScalar(0xFF);
SkString result;
- result.appendScalar(SkIntToScalar(SkColorGetR(color))/colorMax);
+ result.appendScalar(SkScalarDiv(SkIntToScalar(SkColorGetR(color)),
+ colorMax));
result.append(" ");
- result.appendScalar(SkIntToScalar(SkColorGetG(color))/colorMax);
+ result.appendScalar(SkScalarDiv(SkIntToScalar(SkColorGetG(color)),
+ colorMax));
result.append(" ");
- result.appendScalar(SkIntToScalar(SkColorGetB(color))/colorMax);
+ result.appendScalar(SkScalarDiv(SkIntToScalar(SkColorGetB(color)),
+ colorMax));
result.append(" ");
return result;
}
-SkString StyleAndFillToPaintOperator(SkPaint::Style style,
- SkPath::FillType fillType) {
- SkString result;
- if (style == SkPaint::kFill_Style)
- result.append("f");
- else if (style == SkPaint::kStrokeAndFill_Style)
- result.append("B");
- else if (style == SkPaint::kStroke_Style)
- return SkString("S\n");
-
- // Not supported yet.
- SkASSERT(fillType != SkPath::kInverseEvenOdd_FillType);
- SkASSERT(fillType != SkPath::kInverseWinding_FillType);
- if (fillType == SkPath::kEvenOdd_FillType)
- result.append("*");
- result.append("\n");
- return result;
-}
-
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -172,8 +165,7 @@ void SkPDFDevice::drawRect(const SkDraw& d, const SkRect& r,
// Skia has 0,0 at top left, pdf at bottom left. Do the right thing.
SkScalar bottom = r.fBottom < r.fTop ? r.fBottom : r.fTop;
appendRectangle(r.fLeft, bottom, r.width(), r.height());
- fContent.append(StyleAndFillToPaintOperator(paint.getStyle(),
- SkPath::kWinding_FillType));
+ paintPath(paint.getStyle(), SkPath::kWinding_FillType);
}
void SkPDFDevice::drawPath(const SkDraw&, const SkPath& path,
@@ -208,19 +200,19 @@ void SkPDFDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap,
void SkPDFDevice::drawText(const SkDraw&, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint& paint) {
- SkASSERT(false);
+ NOT_IMPLEMENTED("drawText", true);
}
void SkPDFDevice::drawPosText(const SkDraw&, const void* text, size_t len,
const SkScalar pos[], SkScalar constY,
int scalarsPerPos, const SkPaint& paint) {
- SkASSERT(false);
+ NOT_IMPLEMENTED("drawPosText", false);
}
void SkPDFDevice::drawTextOnPath(const SkDraw&, const void* text, size_t len,
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) {
- SkASSERT(false);
+ NOT_IMPLEMENTED("drawTextOnPath", true);
}
void SkPDFDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode,
@@ -228,7 +220,7 @@ void SkPDFDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode,
const SkPoint texs[], const SkColor colors[],
SkXfermode* xmode, const uint16_t indices[],
int indexCount, const SkPaint& paint) {
- SkASSERT(false);
+ NOT_IMPLEMENTED("drawVerticies", true);
}
void SkPDFDevice::drawDevice(const SkDraw&, SkDevice*, int x, int y,
@@ -276,21 +268,23 @@ const SkRefPtr<SkPDFDict>& SkPDFDevice::getResourceDict() {
return fResourceDict;
}
-void SkPDFDevice::getResouces(SkTDArray<SkPDFObject*>* resouceList) {
- resouceList->setReserve(resouceList->count() +
- fGraphicStateResources.count() +
- fXObjectResources.count());
+void SkPDFDevice::getResources(SkTDArray<SkPDFObject*>* resourceList) const {
+ resourceList->setReserve(resourceList->count() +
+ fGraphicStateResources.count() +
+ fXObjectResources.count());
for (int i = 0; i < fGraphicStateResources.count(); i++) {
- resouceList->push(fGraphicStateResources[i]);
+ resourceList->push(fGraphicStateResources[i]);
fGraphicStateResources[i]->ref();
+ fGraphicStateResources[i]->getResources(resourceList);
}
for (int i = 0; i < fXObjectResources.count(); i++) {
- resouceList->push(fXObjectResources[i]);
+ resourceList->push(fXObjectResources[i]);
fXObjectResources[i]->ref();
+ fXObjectResources[i]->getResources(resourceList);
}
}
-SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() {
+SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() const {
SkRefPtr<SkPDFInt> zero = new SkPDFInt(0);
zero->unref(); // SkRefPtr and new both took a reference.
SkRefPtr<SkPDFInt> width = new SkPDFInt(fWidth);
@@ -321,12 +315,7 @@ SkString SkPDFDevice::content(bool flipOrigin) const {
// Private
// TODO(vandebo) handle these cases.
-#define PAINTCHECK(x,y) do { \
- if(newPaint.x() y) { \
- printf("!!" #x #y "\n"); \
- SkASSERT(false); \
- } \
- } while(0)
+#define PAINTCHECK(x,y) NOT_IMPLEMENTED(newPaint.x() y, false)
void SkPDFDevice::updateGSFromPaint(const SkPaint& newPaint,
SkString* textStateUpdate) {
@@ -430,9 +419,26 @@ void SkPDFDevice::closePath() {
fContent.append("h\n");
}
+void SkPDFDevice::paintPath(SkPaint::Style style, SkPath::FillType fill) {
+ if (style == SkPaint::kFill_Style)
+ fContent.append("f");
+ else if (style == SkPaint::kStrokeAndFill_Style)
+ fContent.append("B");
+ else if (style == SkPaint::kStroke_Style)
+ fContent.append("S");
+
+ if (style != SkPaint::kStroke_Style) {
+ // Not supported yet.
+ NOT_IMPLEMENTED(fill == SkPath::kInverseEvenOdd_FillType, false);
+ NOT_IMPLEMENTED(fill == SkPath::kInverseWinding_FillType, false);
+ if (fill == SkPath::kEvenOdd_FillType)
+ fContent.append("*");
+ }
+ fContent.append("\n");
+}
+
void SkPDFDevice::strokePath() {
- fContent.append(StyleAndFillToPaintOperator(SkPaint::kStroke_Style,
- SkPath::kWinding_FillType));
+ paintPath(SkPaint::kStroke_Style, SkPath::kWinding_FillType);
}
void SkPDFDevice::internalDrawBitmap(const SkMatrix& matrix,
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp
index 8597d7d370..2b1e3f731b 100644
--- a/src/pdf/SkPDFDocument.cpp
+++ b/src/pdf/SkPDFDocument.cpp
@@ -19,22 +19,22 @@
#include "SkPDFPage.h"
#include "SkStream.h"
-// Add the resouces, starting at firstIndex to the catalog, removing any dupes.
+// Add the resources, starting at firstIndex to the catalog, removing any dupes.
// A hash table would be really nice here.
-void addResoucesToCatalog(int firstIndex, bool firstPage,
- SkTDArray<SkPDFObject*>* resouceList,
+void addResourcesToCatalog(int firstIndex, bool firstPage,
+ SkTDArray<SkPDFObject*>* resourceList,
SkPDFCatalog* catalog) {
- for (int i = firstIndex; i < resouceList->count(); i++) {
- int index = resouceList->find((*resouceList)[i]);
+ for (int i = firstIndex; i < resourceList->count(); i++) {
+ int index = resourceList->find((*resourceList)[i]);
if (index != i) {
- // The resouce lists themselves should already be unique, so the
- // first page resouces shouldn't have any dups (assuming the first
- // page resouces are handled first).
+ // The resource lists themselves should already be unique, so the
+ // first page resources shouldn't have any dups (assuming the first
+ // page resources are handled first).
SkASSERT(!firstPage);
- (*resouceList)[i]->unref();
- resouceList->removeShuffle(i);
+ (*resourceList)[i]->unref();
+ resourceList->removeShuffle(i);
} else {
- catalog->addObject((*resouceList)[i], firstPage);
+ catalog->addObject((*resourceList)[i], firstPage);
}
}
}
@@ -72,11 +72,11 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
for (int i = 0; i < fPages.count(); i++) {
int resourceCount = fPageResources.count();
fPages[i]->finalizePage(&fCatalog, first_page, &fPageResources);
- addResoucesToCatalog(resourceCount, first_page, &fPageResources,
+ addResourcesToCatalog(resourceCount, first_page, &fPageResources,
&fCatalog);
if (i == 0) {
first_page = false;
- fSecondPageFirstResouceIndex = fPageResources.count();
+ fSecondPageFirstResourceIndex = fPageResources.count();
}
}
@@ -85,7 +85,7 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
fileOffset += fCatalog.setFileOffset(fDocCatalog.get(), fileOffset);
fileOffset += fCatalog.setFileOffset(fPages[0], fileOffset);
fileOffset += fPages[0]->getPageSize(&fCatalog, fileOffset);
- for (int i = 0; i < fSecondPageFirstResouceIndex; i++)
+ for (int i = 0; i < fSecondPageFirstResourceIndex; i++)
fileOffset += fCatalog.setFileOffset(fPageResources[i], fileOffset);
if (fPages.count() > 1) {
// TODO(vandebo) For linearized format, save the start of the
@@ -98,7 +98,7 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
for (int i = 1; i < fPages.count(); i++)
fileOffset += fPages[i]->getPageSize(&fCatalog, fileOffset);
- for (int i = fSecondPageFirstResouceIndex;
+ for (int i = fSecondPageFirstResourceIndex;
i < fPageResources.count();
i++)
fileOffset += fCatalog.setFileOffset(fPageResources[i], fileOffset);
@@ -110,7 +110,7 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
fDocCatalog->emitObject(stream, &fCatalog, true);
fPages[0]->emitObject(stream, &fCatalog, true);
fPages[0]->emitPage(stream, &fCatalog);
- for (int i = 0; i < fSecondPageFirstResouceIndex; i++)
+ for (int i = 0; i < fSecondPageFirstResourceIndex; i++)
fPageResources[i]->emitObject(stream, &fCatalog, true);
// TODO(vandebo) support linearized format
//if (fPages.size() > 1) {
@@ -124,7 +124,7 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
for (int i = 1; i < fPages.count(); i++)
fPages[i]->emitPage(stream, &fCatalog);
- for (int i = fSecondPageFirstResouceIndex; i < fPageResources.count(); i++)
+ for (int i = fSecondPageFirstResourceIndex; i < fPageResources.count(); i++)
fPageResources[i]->emitObject(stream, &fCatalog, true);
int64_t objCount = fCatalog.emitXrefTable(stream, fPages.count() > 1);
diff --git a/src/pdf/SkPDFPage.cpp b/src/pdf/SkPDFPage.cpp
index c648472692..e96f0a113a 100644
--- a/src/pdf/SkPDFPage.cpp
+++ b/src/pdf/SkPDFPage.cpp
@@ -44,7 +44,7 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage,
insert("Contents", contentRef.get());
}
catalog->addObject(fContentStream.get(), firstPage);
- fDevice->getResouces(resourceObjects);
+ fDevice->getResources(resourceObjects);
}
off_t SkPDFPage::getPageSize(SkPDFCatalog* catalog, off_t fileOffset) {
diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp
index 27668ab287..8bff735da4 100644
--- a/src/pdf/SkPDFTypes.cpp
+++ b/src/pdf/SkPDFTypes.cpp
@@ -27,6 +27,8 @@ size_t SkPDFObject::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
return buffer.getOffset();
}
+void SkPDFObject::getResources(SkTDArray<SkPDFObject*>* resourceList) {}
+
void SkPDFObject::emitIndirectObject(SkWStream* stream, SkPDFCatalog* catalog) {
catalog->emitObjectNumber(stream, this);
stream->writeText(" obj\n");