Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkDocument.h" | 8 #include "SkDocument.h" |
| 9 #include "SkPDFCanon.h" | 9 #include "SkPDFCanon.h" |
| 10 #include "SkPDFDevice.h" | 10 #include "SkPDFDevice.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 | 63 |
| 64 static SkPDFObject* create_pdf_page_content(const SkPDFDevice* pageDevice) { | 64 static SkPDFObject* create_pdf_page_content(const SkPDFDevice* pageDevice) { |
| 65 SkAutoTDelete<SkStreamAsset> content(pageDevice->content()); | 65 SkAutoTDelete<SkStreamAsset> content(pageDevice->content()); |
| 66 return SkNEW_ARGS(SkPDFStream, (content.get())); | 66 return SkNEW_ARGS(SkPDFStream, (content.get())); |
| 67 } | 67 } |
| 68 | 68 |
| 69 static SkPDFDict* create_pdf_page(const SkPDFDevice* pageDevice) { | 69 static SkPDFDict* create_pdf_page(const SkPDFDevice* pageDevice) { |
| 70 SkAutoTUnref<SkPDFDict> page(SkNEW_ARGS(SkPDFDict, ("Page"))); | 70 SkAutoTUnref<SkPDFDict> page(SkNEW_ARGS(SkPDFDict, ("Page"))); |
| 71 page->insertObject("Resources", pageDevice->createResourceDict()); | 71 page->insertObject("Resources", pageDevice->createResourceDict()); |
| 72 page->insertObject("MediaBox", pageDevice->copyMediaBox()); | 72 page->insertObject("MediaBox", pageDevice->copyMediaBox()); |
| 73 if (SkPDFArray* annots = pageDevice->getAnnotations()) { | 73 SkAutoTUnref<SkPDFArray> annotations(SkNEW(SkPDFArray)); |
| 74 SkASSERT(annots->size() > 0); | 74 pageDevice->appendAnnotations(annotations); |
|
hal.canary
2015/09/16 17:30:46
if (annotations->size() > 0) {
page->insertObj
| |
| 75 page->insertObject("Annots", SkRef(annots)); | 75 page->insertObject("Annots", annotations.detach()); |
| 76 } | |
| 77 page->insertObjRef("Contents", create_pdf_page_content(pageDevice)); | 76 page->insertObjRef("Contents", create_pdf_page_content(pageDevice)); |
| 78 return page.detach(); | 77 return page.detach(); |
| 79 } | 78 } |
| 80 | 79 |
| 81 static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages, | 80 static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages, |
| 82 SkTDArray<SkPDFDict*>* pageTree, | 81 SkTDArray<SkPDFDict*>* pageTree, |
| 83 SkPDFDict** rootNode) { | 82 SkPDFDict** rootNode) { |
| 84 // PDF wants a tree describing all the pages in the document. We arbitrary | 83 // PDF wants a tree describing all the pages in the document. We arbitrary |
| 85 // choose 8 (kNodeSize) as the number of allowed children. The internal | 84 // choose 8 (kNodeSize) as the number of allowed children. The internal |
| 86 // nodes have type "Pages" with an array of children, a parent pointer, and | 85 // nodes have type "Pages" with an array of children, a parent pointer, and |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 | 345 |
| 347 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 346 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
| 348 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); | 347 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); |
| 349 if (!stream->isValid()) { | 348 if (!stream->isValid()) { |
| 350 SkDELETE(stream); | 349 SkDELETE(stream); |
| 351 return NULL; | 350 return NULL; |
| 352 } | 351 } |
| 353 auto delete_wstream = [](SkWStream* stream, bool) { SkDELETE(stream); }; | 352 auto delete_wstream = [](SkWStream* stream, bool) { SkDELETE(stream); }; |
| 354 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi)); | 353 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi)); |
| 355 } | 354 } |
| OLD | NEW |