Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: src/doc/SkDocument_PDF.cpp

Issue 1107913002: SkPDF: clean up uses of deprecated calls in SkDocument_PDF (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/doc/SkDocument_PDF.cpp
diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp
index 1e2148bc885da643602e03486104096afe88b184..274a6581e81f32093ced292cfe247e1cd5a440b4 100644
--- a/src/doc/SkDocument_PDF.cpp
+++ b/src/doc/SkDocument_PDF.cpp
@@ -31,7 +31,7 @@ static void emit_pdf_footer(SkWStream* stream,
// TODO(vandebo): Linearized format will take a Prev entry too.
// TODO(vandebo): PDF/A requires an ID entry.
trailerDict.insertInt("Size", int(objCount));
- trailerDict.insert("Root", new SkPDFObjRef(docCatalog))->unref();
+ trailerDict.insertObjRef("Root", SkRef(docCatalog));
stream->writeText("trailer\n");
trailerDict.emitObject(stream, objNumMap, substitutes);
@@ -61,24 +61,20 @@ static void perform_font_subsetting(
}
}
+static SkPDFObject* create_pdf_page_content(const SkPDFDevice* pageDevice) {
+ SkAutoTDelete<SkStreamAsset> content(pageDevice->content());
+ return SkNEW_ARGS(SkPDFStream, (content.get()));
tomhudson 2015/05/04 18:15:04 Ugh, I really need to internalize your memory mana
hal.canary 2015/05/05 14:37:50 Yes. SkStreamRewindableFromSkStream should be alm
+}
+
static SkPDFDict* create_pdf_page(const SkPDFDevice* pageDevice) {
SkAutoTUnref<SkPDFDict> page(SkNEW_ARGS(SkPDFDict, ("Page")));
- SkAutoTUnref<SkPDFDict> deviceResourceDict(
- pageDevice->createResourceDict());
- page->insert("Resources", deviceResourceDict.get());
-
- SkAutoTUnref<SkPDFArray> mediaBox(pageDevice->copyMediaBox());
- page->insert("MediaBox", mediaBox.get());
-
- SkPDFArray* annots = pageDevice->getAnnotations();
- if (annots && annots->size() > 0) {
- page->insert("Annots", annots);
+ page->insertObject("Resources", pageDevice->createResourceDict());
+ page->insertObject("MediaBox", pageDevice->copyMediaBox());
+ if (SkPDFArray* annots = pageDevice->getAnnotations()) {
+ SkASSERT(annots->size() > 0);
+ page->insertObject("Annots", SkRef(annots));
}
-
- SkAutoTDelete<SkStreamAsset> content(pageDevice->content());
- SkAutoTUnref<SkPDFStream> contentStream(
- SkNEW_ARGS(SkPDFStream, (content.get())));
- page->insert("Contents", new SkPDFObjRef(contentStream.get()))->unref();
+ page->insertObjRef("Contents", create_pdf_page_content(pageDevice));
return page.detach();
}
@@ -114,16 +110,14 @@ static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages,
break;
}
- SkPDFDict* newNode = new SkPDFDict("Pages");
- SkAutoTUnref<SkPDFObjRef> newNodeRef(new SkPDFObjRef(newNode));
-
+ SkAutoTUnref<SkPDFDict> newNode(new SkPDFDict("Pages"));
SkAutoTUnref<SkPDFArray> kids(new SkPDFArray);
kids->reserve(kNodeSize);
int count = 0;
for (; i < curNodes.count() && count < kNodeSize; i++, count++) {
- curNodes[i]->insert("Parent", newNodeRef.get());
- kids->append(new SkPDFObjRef(curNodes[i]))->unref();
+ curNodes[i]->insertObjRef("Parent", SkRef(newNode.get()));
+ kids->appendObjRef(SkRef(curNodes[i]));
// TODO(vandebo): put the objects in strict access order.
// Probably doesn't matter because they are so small.
@@ -145,9 +139,9 @@ static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages,
if (i == curNodes.count()) {
pageCount = ((pages.count() - 1) % treeCapacity) + 1;
}
- newNode->insert("Count", new SkPDFInt(pageCount))->unref();
- newNode->insert("Kids", kids.get());
- nextRoundNodes.push(newNode); // Transfer reference.
+ newNode->insertInt("Count", pageCount);
+ newNode->insertObject("Kids", kids.detach());
+ nextRoundNodes.push(newNode.detach()); // Transfer reference.
}
curNodes = nextRoundNodes;
@@ -184,24 +178,21 @@ static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices,
SkPDFDict* pageTreeRoot;
generate_page_tree(pages, &pageTree, &pageTreeRoot);
+ docCatalog->insertObjRef("Pages", SkRef(pageTreeRoot));
- docCatalog->insert("Pages", new SkPDFObjRef(pageTreeRoot))->unref();
+ if (dests->size() > 0) {
+ docCatalog->insertObjRef("Dests", dests.detach());
+ }
/* TODO(vandebo): output intent
SkAutoTUnref<SkPDFDict> outputIntent = new SkPDFDict("OutputIntent");
- outputIntent->insert("S", new SkPDFName("GTS_PDFA1"))->unref();
- outputIntent->insert("OutputConditionIdentifier",
- new SkPDFString("sRGB"))->unref();
- SkAutoTUnref<SkPDFArray> intentArray = new SkPDFArray;
- intentArray->append(outputIntent.get());
- docCatalog->insert("OutputIntent", intentArray.get());
+ outputIntent->insertName("S", "GTS_PDFA1");
+ outputIntent->insertString("OutputConditionIdentifier", "sRGB");
+ SkAutoTUnref<SkPDFArray> intentArray(new SkPDFArray);
+ intentArray->appendObject(SkRef(outputIntent.get()));
+ docCatalog->insertObject("OutputIntent", intentArray.detach());
*/
- if (dests->size() > 0) {
- docCatalog->insert("Dests", SkNEW_ARGS(SkPDFObjRef, (dests.get())))
- ->unref();
- }
-
// Build font subsetting info before proceeding.
SkPDFSubstituteMap substitutes;
perform_font_subsetting(pageDevices, &substitutes);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698