diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp index 8387cccbd5..599238e1db 100644 --- a/src/doc/SkDocument_PDF.cpp +++ b/src/doc/SkDocument_PDF.cpp @@ -62,7 +62,7 @@ protected: private: SkPDFCanon fCanon; - SkTDArray fPageDevices; + SkTDArray fPageDevices; SkAutoTUnref fCanvas; SkScalar fRasterDpi; }; diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 72e9135876..87555a8111 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -705,7 +705,6 @@ SkPDFDevice::SkPDFDevice(SkISize pageSize, , fContentSize(pageSize) , fExistingClipRegion(SkIRect::MakeSize(pageSize)) , fAnnotations(NULL) - , fResourceDict(NULL) , fLastContentEntry(NULL) , fLastMarginContentEntry(NULL) , fDrawingArea(kContent_DrawingArea) @@ -735,7 +734,6 @@ SkPDFDevice::~SkPDFDevice() { void SkPDFDevice::init() { fAnnotations = NULL; - fResourceDict = NULL; fContentEntries.free(); fLastContentEntry = NULL; fMarginContentEntries.free(); @@ -752,7 +750,6 @@ void SkPDFDevice::cleanUp(bool clearFontUsage) { fFontResources.unrefAll(); fShaderResources.unrefAll(); SkSafeUnref(fAnnotations); - SkSafeUnref(fResourceDict); fNamedDestinations.deleteAll(); if (clearFontUsage) { @@ -1249,44 +1246,41 @@ void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) { fDrawingArea = drawingArea; } -SkPDFResourceDict* SkPDFDevice::getResourceDict() { - if (NULL == fResourceDict) { - fResourceDict = SkNEW(SkPDFResourceDict); - - if (fGraphicStateResources.count()) { - for (int i = 0; i < fGraphicStateResources.count(); i++) { - fResourceDict->insertResourceAsReference( - SkPDFResourceDict::kExtGState_ResourceType, - i, fGraphicStateResources[i]); - } - } - - if (fXObjectResources.count()) { - for (int i = 0; i < fXObjectResources.count(); i++) { - fResourceDict->insertResourceAsReference( - SkPDFResourceDict::kXObject_ResourceType, - i, fXObjectResources[i]); - } - } - - if (fFontResources.count()) { - for (int i = 0; i < fFontResources.count(); i++) { - fResourceDict->insertResourceAsReference( - SkPDFResourceDict::kFont_ResourceType, - i, fFontResources[i]); - } - } - - if (fShaderResources.count()) { - SkAutoTUnref patterns(new SkPDFDict()); - for (int i = 0; i < fShaderResources.count(); i++) { - fResourceDict->insertResourceAsReference( - SkPDFResourceDict::kPattern_ResourceType, - i, fShaderResources[i]); - } +SkPDFResourceDict* SkPDFDevice::createResourceDict() const { + SkAutoTUnref resourceDict(SkNEW(SkPDFResourceDict)); + if (fGraphicStateResources.count()) { + for (int i = 0; i < fGraphicStateResources.count(); i++) { + resourceDict->insertResourceAsReference( + SkPDFResourceDict::kExtGState_ResourceType, + i, fGraphicStateResources[i]); } } - return fResourceDict; + + if (fXObjectResources.count()) { + for (int i = 0; i < fXObjectResources.count(); i++) { + resourceDict->insertResourceAsReference( + SkPDFResourceDict::kXObject_ResourceType, + i, fXObjectResources[i]); + } + } + + if (fFontResources.count()) { + for (int i = 0; i < fFontResources.count(); i++) { + resourceDict->insertResourceAsReference( + SkPDFResourceDict::kFont_ResourceType, + i, fFontResources[i]); + } + } + + if (fShaderResources.count()) { + SkAutoTUnref patterns(new SkPDFDict()); + for (int i = 0; i < fShaderResources.count(); i++) { + resourceDict->insertResourceAsReference( + SkPDFResourceDict::kPattern_ResourceType, + i, fShaderResources[i]); + } + } + return resourceDict.detach(); } const SkTDArray& SkPDFDevice::getFontResources() const { @@ -1539,7 +1533,7 @@ void SkPDFDevice::defineNamedDestination(SkData* nameData, const SkPoint& point, SkNEW_ARGS(NamedDestination, (nameData, translatedPoint))); } -void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) { +void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const { int nDest = fNamedDestinations.count(); for (int i = 0; i < nDest; i++) { NamedDestination* dest = fNamedDestinations[i]; diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h index 047841df84..ef2cbf78bb 100644 --- a/src/pdf/SkPDFDevice.h +++ b/src/pdf/SkPDFDevice.h @@ -35,7 +35,6 @@ class SkPDFResourceDict; class SkPDFShader; class SkPDFStream; class SkRRect; -template class SkTSet; // Private classes. struct ContentEntry; @@ -138,9 +137,9 @@ public: // PDF specific methods. - /** Returns the resource dictionary for this device. + /** Create the resource dictionary for this device. */ - SkPDFResourceDict* getResourceDict(); + SkPDFResourceDict* createResourceDict() const; /** Get the fonts used on this device. */ @@ -150,7 +149,7 @@ public: * @param dict Dictionary to add destinations to. * @param page The PDF object representing the page for this device. */ - void appendDestinations(SkPDFDict* dict, SkPDFObject* page); + void appendDestinations(SkPDFDict* dict, SkPDFObject* page) const; /** Returns a copy of the media box for this device. The caller is required * to unref() this when it is finished. @@ -202,7 +201,6 @@ private: SkClipStack fExistingClipStack; SkRegion fExistingClipRegion; SkPDFArray* fAnnotations; - SkPDFResourceDict* fResourceDict; SkTDArray fNamedDestinations; SkTDArray fGraphicStateResources; diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp index 6d49e68584..42744a847f 100644 --- a/src/pdf/SkPDFDocument.cpp +++ b/src/pdf/SkPDFDocument.cpp @@ -65,7 +65,7 @@ static void emit_pdf_footer(SkWStream* stream, stream->writeText("\n%%EOF"); } -bool SkPDFDocument::EmitPDF(const SkTDArray& pageDevices, +bool SkPDFDocument::EmitPDF(const SkTDArray& pageDevices, SkWStream* stream) { if (pageDevices.isEmpty()) { return false; diff --git a/src/pdf/SkPDFDocument.h b/src/pdf/SkPDFDocument.h index b63edc12d2..0e1728999a 100644 --- a/src/pdf/SkPDFDocument.h +++ b/src/pdf/SkPDFDocument.h @@ -28,7 +28,7 @@ namespace SkPDFDocument { * should be created using the same SkPDFCanon. * @param SkWStream The writable output stream to send the PDF to. */ -bool EmitPDF(const SkTDArray& pageDevices, SkWStream*); +bool EmitPDF(const SkTDArray& pageDevices, SkWStream*); /** Get the count of unique font types used in the given pages. */ diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp index 19570f3d6d..59e81f4146 100644 --- a/src/pdf/SkPDFFormXObject.cpp +++ b/src/pdf/SkPDFFormXObject.cpp @@ -21,13 +21,13 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { // We don't want to keep around device because we'd have two copies // of content, so reference or copy everything we need (content and // resources). - SkPDFResourceDict* resourceDict = device->getResourceDict(); + SkAutoTUnref resourceDict(device->createResourceDict()); SkAutoTDelete content(device->content()); this->setData(content.get()); SkAutoTUnref bboxArray(device->copyMediaBox()); - init(NULL, resourceDict, bboxArray); + this->init(NULL, resourceDict.get(), bboxArray); // We invert the initial transform and apply that to the xobject so that // it doesn't get applied twice. We can't just undo it because it's diff --git a/src/pdf/SkPDFPage.cpp b/src/pdf/SkPDFPage.cpp index da0179a283..f86b252105 100644 --- a/src/pdf/SkPDFPage.cpp +++ b/src/pdf/SkPDFPage.cpp @@ -13,7 +13,7 @@ #include "SkPDFPage.h" #include "SkPDFResourceDict.h" -SkPDFPage::SkPDFPage(SkPDFDevice* content) +SkPDFPage::SkPDFPage(const SkPDFDevice* content) : SkPDFDict("Page"), fDevice(content) { SkSafeRef(content); @@ -25,7 +25,9 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage, const SkTSet& knownResourceObjects, SkTSet* newResourceObjects) { if (fContentStream.get() == NULL) { - this->insert("Resources", fDevice->getResourceDict()); + SkAutoTUnref deviceResourceDict( + fDevice->createResourceDict()); + this->insert("Resources", deviceResourceDict.get()); SkSafeUnref(this->insert("MediaBox", fDevice->copyMediaBox())); SkPDFArray* annots = fDevice->getAnnotations(); if (annots && annots->size() > 0) { diff --git a/src/pdf/SkPDFPage.h b/src/pdf/SkPDFPage.h index 38cc5c45e5..99a913441b 100644 --- a/src/pdf/SkPDFPage.h +++ b/src/pdf/SkPDFPage.h @@ -31,7 +31,7 @@ public: * have content on it yet. * @param content The page content. */ - explicit SkPDFPage(SkPDFDevice* content); + explicit SkPDFPage(const SkPDFDevice* content); ~SkPDFPage(); /** Before a page and its contents can be sized and emitted, it must @@ -86,7 +86,7 @@ public: private: // Multiple pages may reference the content. - SkAutoTUnref fDevice; + SkAutoTUnref fDevice; // Once the content is finalized, put it into a stream for output. SkAutoTUnref fContentStream; diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp index 97bca73f63..da55340d4c 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -1101,8 +1101,10 @@ SkPDFImageShader* SkPDFImageShader::Create( SkNEW_ARGS(SkPDFImageShader, (autoState->detach())); imageShader->setData(content.get()); + SkAutoTUnref resourceDict( + patternDevice->createResourceDict()); populate_tiling_pattern_dict(imageShader, patternBBox, - patternDevice->getResourceDict(), finalMatrix); + resourceDict.get(), finalMatrix); imageShader->fShaderState->fImage.unlockPixels();