diff options
author | halcanary <halcanary@google.com> | 2015-05-05 08:00:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-05 08:00:24 -0700 |
commit | 72266fd1fe9bfe078239a9d9e85f479faee30281 (patch) | |
tree | d12d44b394bc56a1079413065616eac56fe33de9 /src | |
parent | 261694c98a4de4c67fb719e365c0345da0473a17 (diff) |
SkPDF: clean up uses of deprecated calls in SkDocument_PDF
BUG=skia:3585
Review URL: https://codereview.chromium.org/1107913002
Diffstat (limited to 'src')
-rw-r--r-- | src/doc/SkDocument_PDF.cpp | 63 |
1 files changed, 27 insertions, 36 deletions
diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp index 1255b6cbfe..eeb8aa83fd 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())); +} + 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); |