*/
SK_API const SkTDArray<SkPDFFont*>& getFontResources() const;
- /** Returns the media box for this device.
+ /** Returns a copy of the media box for this device. The caller is required
+ * to unref() this when it is finished.
*/
- SK_API SkRefPtr<SkPDFArray> getMediaBox() const;
+ SK_API SkPDFArray* copyMediaBox() const;
- /** Get the annotations from this page.
+ /** Get the annotations from this page, or NULL if there are none.
*/
- SK_API SkRefPtr<SkPDFArray> getAnnotations() const;
+ SK_API SkPDFArray* getAnnotations() const { return fAnnotations; }
/** Returns a SkStream with the page contents. The caller is responsible
for a reference to the returned value.
SkMatrix fInitialTransform;
SkClipStack fExistingClipStack;
SkRegion fExistingClipRegion;
- SkRefPtr<SkPDFArray> fAnnotations;
+ SkPDFArray* fAnnotations;
SkRefPtr<SkPDFDict> fResourceDict;
SkTDArray<SkPDFGraphicState*> fGraphicStateResources;
}
void SkPDFDevice::init() {
+ fAnnotations = NULL;
fResourceDict = NULL;
fContentEntries.reset();
fLastContentEntry = NULL;
fXObjectResources.unrefAll();
fFontResources.unrefAll();
fShaderResources.unrefAll();
+ SkSafeUnref(fAnnotations);
+
if (clearFontUsage) {
fFontGlyphUsage->reset();
}
return fFontResources;
}
-SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() const {
- SkRefPtr<SkPDFInt> zero = new SkPDFInt(0);
- zero->unref(); // SkRefPtr and new both took a reference.
+SkPDFArray* SkPDFDevice::copyMediaBox() const {
+ // should this be a singleton?
+ SkAutoTUnref<SkPDFInt> zero(SkNEW_ARGS(SkPDFInt, (0)));
- SkRefPtr<SkPDFArray> mediaBox = new SkPDFArray();
- mediaBox->unref(); // SkRefPtr and new both took a reference.
+ SkPDFArray* mediaBox = SkNEW(SkPDFArray);
mediaBox->reserve(4);
mediaBox->append(zero.get());
mediaBox->append(zero.get());
return mediaBox;
}
-SkRefPtr<SkPDFArray> SkPDFDevice::getAnnotations() const {
- return SkRefPtr<SkPDFArray>(fAnnotations);
-}
-
SkStream* SkPDFDevice::content() const {
SkMemoryStream* result = new SkMemoryStream;
result->setData(this->copyContentToData())->unref();
SkRect translatedRect;
transform.mapRect(&translatedRect, r);
- if (fAnnotations.get() == NULL) {
- fAnnotations = new SkPDFArray;
- fAnnotations->unref(); // Both new and SkRefPtr took a reference.
+ if (NULL == fAnnotations) {
+ fAnnotations = SkNEW(SkPDFArray);
}
SkAutoTUnref<SkPDFDict> annotation(new SkPDFDict("Annot"));
annotation->insertName("Subtype", "Link");
insertName("Type", "XObject");
insertName("Subtype", "Form");
- insert("BBox", device->getMediaBox().get());
+ SkSafeUnref(this->insert("BBox", device->copyMediaBox()));
insert("Resources", device->getResourceDict());
// We invert the initial transform and apply that to the xobject so that
SkTDArray<SkPDFObject*>* resourceObjects) {
if (fContentStream.get() == NULL) {
insert("Resources", fDevice->getResourceDict());
- insert("MediaBox", fDevice->getMediaBox().get());
+ SkSafeUnref(this->insert("MediaBox", fDevice->copyMediaBox()));
if (!SkToBool(catalog->getDocumentFlags() &
SkPDFDocument::kNoLinks_Flags)) {
- SkRefPtr<SkPDFArray> annots = fDevice->getAnnotations();
- if (annots.get() && annots->size() > 0) {
- insert("Annots", annots.get());
+ SkPDFArray* annots = fDevice->getAnnotations();
+ if (annots && annots->size() > 0) {
+ insert("Annots", annots);
}
}