diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/doc/SkDocument_PDF.cpp | 2 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 62 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.h | 8 | ||||
-rw-r--r-- | src/pdf/SkPDFDocument.cpp | 2 | ||||
-rw-r--r-- | src/pdf/SkPDFDocument.h | 2 | ||||
-rw-r--r-- | src/pdf/SkPDFFormXObject.cpp | 4 | ||||
-rw-r--r-- | src/pdf/SkPDFPage.cpp | 6 | ||||
-rw-r--r-- | src/pdf/SkPDFPage.h | 4 | ||||
-rw-r--r-- | src/pdf/SkPDFShader.cpp | 4 |
9 files changed, 45 insertions, 49 deletions
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<SkPDFDevice*> fPageDevices; + SkTDArray<const SkPDFDevice*> fPageDevices; SkAutoTUnref<SkCanvas> 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]); - } +SkPDFResourceDict* SkPDFDevice::createResourceDict() const { + SkAutoTUnref<SkPDFResourceDict> resourceDict(SkNEW(SkPDFResourceDict)); + if (fGraphicStateResources.count()) { + for (int i = 0; i < fGraphicStateResources.count(); i++) { + resourceDict->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 (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++) { - fResourceDict->insertResourceAsReference( - SkPDFResourceDict::kFont_ResourceType, - i, fFontResources[i]); - } + if (fFontResources.count()) { + for (int i = 0; i < fFontResources.count(); i++) { + resourceDict->insertResourceAsReference( + SkPDFResourceDict::kFont_ResourceType, + i, fFontResources[i]); } + } - if (fShaderResources.count()) { - SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict()); - for (int i = 0; i < fShaderResources.count(); i++) { - fResourceDict->insertResourceAsReference( - SkPDFResourceDict::kPattern_ResourceType, - i, fShaderResources[i]); - } + if (fShaderResources.count()) { + SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict()); + for (int i = 0; i < fShaderResources.count(); i++) { + resourceDict->insertResourceAsReference( + SkPDFResourceDict::kPattern_ResourceType, + i, fShaderResources[i]); } } - return fResourceDict; + return resourceDict.detach(); } const SkTDArray<SkPDFFont*>& 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 <typename T> 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<NamedDestination*> fNamedDestinations; SkTDArray<SkPDFGraphicState*> 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<SkPDFDevice*>& pageDevices, +bool SkPDFDocument::EmitPDF(const SkTDArray<const SkPDFDevice*>& 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<SkPDFDevice*>& pageDevices, SkWStream*); +bool EmitPDF(const SkTDArray<const SkPDFDevice*>& 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<SkPDFResourceDict> resourceDict(device->createResourceDict()); SkAutoTDelete<SkStreamAsset> content(device->content()); this->setData(content.get()); SkAutoTUnref<SkPDFArray> 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<SkPDFObject*>& knownResourceObjects, SkTSet<SkPDFObject*>* newResourceObjects) { if (fContentStream.get() == NULL) { - this->insert("Resources", fDevice->getResourceDict()); + SkAutoTUnref<SkPDFResourceDict> 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<SkPDFDevice> fDevice; + SkAutoTUnref<const SkPDFDevice> fDevice; // Once the content is finalized, put it into a stream for output. SkAutoTUnref<SkPDFStream> 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<SkPDFResourceDict> resourceDict( + patternDevice->createResourceDict()); populate_tiling_pattern_dict(imageShader, patternBBox, - patternDevice->getResourceDict(), finalMatrix); + resourceDict.get(), finalMatrix); imageShader->fShaderState->fImage.unlockPixels(); |