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
This commit is contained in:
vandebo@chromium.org 2010-10-26 19:48:49 +00:00
Родитель 35fc62b960
Коммит a518086928
9 изменённых файлов: 92 добавлений и 72 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -57,7 +57,7 @@ private:
SkTDArray<SkPDFDict*> fPageTree;
SkRefPtr<SkPDFDict> fDocCatalog;
SkTDArray<SkPDFObject*> fPageResources;
int fSecondPageFirstResouceIndex;
int fSecondPageFirstResourceIndex;
SkRefPtr<SkPDFDict> fTrailerDict;

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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