aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
4 files changed, 69 insertions, 61 deletions
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");